-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,171 additions
and
62 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
common/src/main/java/gripe/_90/megacells/block/MEGAPatternProviderBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package gripe._90.megacells.block; | ||
|
||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.TooltipFlag; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.StateDefinition; | ||
import net.minecraft.world.level.block.state.properties.BooleanProperty; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
|
||
import appeng.api.util.IOrientable; | ||
import appeng.block.AEBaseBlockItem; | ||
import appeng.block.AEBaseEntityBlock; | ||
import appeng.core.localization.Tooltips; | ||
import appeng.menu.locator.MenuLocators; | ||
import appeng.util.InteractionUtil; | ||
|
||
import gripe._90.megacells.block.entity.MEGAPatternProviderBlockEntity; | ||
|
||
public class MEGAPatternProviderBlock extends AEBaseEntityBlock<MEGAPatternProviderBlockEntity> { | ||
public static final BooleanProperty OMNIDIRECTIONAL = BooleanProperty.create("omnidirectional"); | ||
|
||
public MEGAPatternProviderBlock(Properties props) { | ||
super(props); | ||
registerDefaultState(defaultBlockState().setValue(OMNIDIRECTIONAL, true)); | ||
} | ||
|
||
@Override | ||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { | ||
super.createBlockStateDefinition(builder); | ||
builder.add(OMNIDIRECTIONAL); | ||
} | ||
|
||
@Override | ||
protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, MEGAPatternProviderBlockEntity be) { | ||
return currentState.setValue(OMNIDIRECTIONAL, be.isOmniDirectional()); | ||
} | ||
|
||
@Override | ||
public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, | ||
boolean isMoving) { | ||
var be = this.getBlockEntity(level, pos); | ||
if (be != null) { | ||
be.getLogic().updateRedstoneState(); | ||
} | ||
} | ||
|
||
@Override | ||
public InteractionResult onActivated(Level level, BlockPos pos, Player p, | ||
InteractionHand hand, | ||
@Nullable ItemStack heldItem, BlockHitResult hit) { | ||
if (InteractionUtil.isInAlternateUseMode(p)) { | ||
return InteractionResult.PASS; | ||
} | ||
|
||
var be = this.getBlockEntity(level, pos); | ||
|
||
if (be != null) { | ||
if (!level.isClientSide()) { | ||
be.openMenu(p, MenuLocators.forBlockEntity(be)); | ||
} | ||
|
||
return InteractionResult.sidedSuccess(level.isClientSide()); | ||
} | ||
|
||
return InteractionResult.PASS; | ||
} | ||
|
||
@Override | ||
protected boolean hasCustomRotation() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void customRotateBlock(IOrientable rotatable, Direction axis) { | ||
if (rotatable instanceof MEGAPatternProviderBlockEntity patternProvider) { | ||
patternProvider.setSide(axis); | ||
} | ||
} | ||
|
||
public static class Item extends AEBaseBlockItem { | ||
public Item(Block id, Properties props) { | ||
super(id, props); | ||
} | ||
|
||
@Override | ||
public void addCheckedInformation(ItemStack stack, Level level, List<Component> tooltip, TooltipFlag flag) { | ||
tooltip.add(Tooltips.of("Supports processing patterns only.")); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
common/src/main/java/gripe/_90/megacells/block/entity/MEGAPatternProviderBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package gripe._90.megacells.block.entity; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
import appeng.api.stacks.AEItemKey; | ||
import appeng.blockentity.crafting.PatternProviderBlockEntity; | ||
import appeng.helpers.iface.PatternProviderLogic; | ||
import appeng.menu.ISubMenu; | ||
import appeng.menu.MenuOpener; | ||
import appeng.menu.locator.MenuLocator; | ||
|
||
import gripe._90.megacells.definition.MEGABlocks; | ||
import gripe._90.megacells.menu.MEGAPatternProviderMenu; | ||
|
||
public class MEGAPatternProviderBlockEntity extends PatternProviderBlockEntity { | ||
|
||
public MEGAPatternProviderBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState blockState) { | ||
super(blockEntityType, pos, blockState); | ||
} | ||
|
||
@Override | ||
public PatternProviderLogic createLogic() { | ||
return new PatternProviderLogic(this.getMainNode(), this, 18); | ||
} | ||
|
||
@Override | ||
public void openMenu(Player player, MenuLocator locator) { | ||
MenuOpener.open(MEGAPatternProviderMenu.TYPE, player, locator); | ||
} | ||
|
||
@Override | ||
public void returnToMainMenu(Player player, ISubMenu subMenu) { | ||
MenuOpener.returnTo(MEGAPatternProviderMenu.TYPE, player, subMenu.getLocator()); | ||
} | ||
|
||
@Override | ||
public AEItemKey getTerminalIcon() { | ||
return AEItemKey.of(MEGABlocks.MEGA_PATTERN_PROVIDER.stack()); | ||
} | ||
|
||
@Override | ||
public ItemStack getMainMenuIcon() { | ||
return MEGABlocks.MEGA_PATTERN_PROVIDER.stack(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
common/src/main/java/gripe/_90/megacells/definition/MEGAParts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package gripe._90.megacells.definition; | ||
|
||
import java.util.function.Function; | ||
|
||
import net.minecraft.world.item.Item; | ||
|
||
import appeng.api.parts.IPart; | ||
import appeng.api.parts.IPartItem; | ||
import appeng.api.parts.PartModels; | ||
import appeng.core.definitions.ItemDefinition; | ||
import appeng.items.parts.PartItem; | ||
import appeng.items.parts.PartModelsHelper; | ||
|
||
import gripe._90.megacells.part.MEGAPatternProviderPart; | ||
|
||
public final class MEGAParts { | ||
|
||
public static void init() { | ||
// controls static load order | ||
} | ||
|
||
// spotless:off | ||
public static final ItemDefinition<PartItem<MEGAPatternProviderPart>> MEGA_PATTERN_PROVIDER = customPart("MEGA Pattern Provider", "cable_mega_pattern_provider", MEGAPatternProviderPart.class, MEGAPatternProviderPart.Item::new); | ||
// spotless:on | ||
|
||
private static <T extends IPart> ItemDefinition<PartItem<T>> part(String englishName, String id, Class<T> partClass, | ||
Function<IPartItem<T>, T> factory) { | ||
return customPart(englishName, id, partClass, props -> new PartItem<>(props, partClass, factory)); | ||
} | ||
|
||
private static <T extends IPart> ItemDefinition<PartItem<T>> customPart(String englishName, String id, | ||
Class<T> partClass, Function<Item.Properties, PartItem<T>> itemFactory) { | ||
PartModels.registerModels(PartModelsHelper.createModels(partClass)); | ||
return MEGAItems.item(englishName, id, itemFactory); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
common/src/main/java/gripe/_90/megacells/definition/MEGATags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package gripe._90.megacells.definition; | ||
|
||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.world.item.Item; | ||
|
||
public final class MEGATags { | ||
public static final TagKey<Item> MEGA_PATTERN_PROVIDER = itemTag("megacells:mega_pattern_provider"); | ||
|
||
private static TagKey<Item> itemTag(String name) { | ||
return TagKey.create(Registry.ITEM_REGISTRY, new ResourceLocation(name)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
common/src/main/java/gripe/_90/megacells/menu/MEGAPatternProviderMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package gripe._90.megacells.menu; | ||
|
||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.inventory.MenuType; | ||
|
||
import appeng.api.config.SecurityPermissions; | ||
import appeng.core.definitions.AEItems; | ||
import appeng.helpers.iface.PatternProviderLogicHost; | ||
import appeng.menu.implementations.MenuTypeBuilder; | ||
import appeng.menu.implementations.PatternProviderMenu; | ||
import appeng.util.inv.AppEngInternalInventory; | ||
import appeng.util.inv.filter.AEItemDefinitionFilter; | ||
|
||
public class MEGAPatternProviderMenu extends PatternProviderMenu { | ||
public static final MenuType<MEGAPatternProviderMenu> TYPE = MenuTypeBuilder | ||
.create(MEGAPatternProviderMenu::new, PatternProviderLogicHost.class) | ||
.requirePermission(SecurityPermissions.BUILD) | ||
.build("mega_pattern_provider"); | ||
|
||
public MEGAPatternProviderMenu(int id, Inventory playerInventory, PatternProviderLogicHost host) { | ||
super(TYPE, id, playerInventory, host); | ||
((AppEngInternalInventory) logic.getPatternInv()) | ||
.setFilter(new AEItemDefinitionFilter(AEItems.PROCESSING_PATTERN)); | ||
} | ||
} |
Oops, something went wrong.