diff --git a/src/main/java/gripe/_90/arseng/ArsEnergistique.java b/src/main/java/gripe/_90/arseng/ArsEnergistique.java index 82a1a95..5f31191 100644 --- a/src/main/java/gripe/_90/arseng/ArsEnergistique.java +++ b/src/main/java/gripe/_90/arseng/ArsEnergistique.java @@ -4,6 +4,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; @@ -46,16 +47,17 @@ public static ResourceLocation makeId(String id) { return new ResourceLocation(MODID, id); } + private static final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + @SuppressWarnings("UnstableApiUsage") public ArsEnergistique() { ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ArsEngConfig.SPEC); - var bus = FMLJavaModLoadingContext.get().getModEventBus(); - bus.addListener(ArsEngItems::register); - bus.addListener(ArsEngBlocks::register); - bus.addListener(ArsEngCreativeTab::register); + modEventBus.addListener(ArsEngItems::register); + modEventBus.addListener(ArsEngBlocks::register); + modEventBus.addListener(ArsEngCreativeTab::register); - bus.addListener(SourceKeyType::register); + modEventBus.addListener(SourceKeyType::register); StorageCells.addCellHandler(SourceCellHandler.INSTANCE); StorageCells.addCellHandler(CreativeSourceCellHandler.INSTANCE); @@ -66,7 +68,7 @@ public ArsEnergistique() { Upgrades.add(AEItems.VOID_CARD, cell, 1, GuiText.PortableCells.getTranslationKey()); }); - bus.addListener(ArsEngCapabilities::register); + modEventBus.addListener(ArsEngCapabilities::register); MinecraftForge.EVENT_BUS.addGenericListener(BlockEntity.class, ArsEngCapabilities::attach); StackWorldBehaviors.registerImportStrategy(SourceKeyType.TYPE, SourceStorageImportStrategy::new); @@ -76,7 +78,7 @@ public ArsEnergistique() { ContainerItemStrategy.register(SourceKeyType.TYPE, SourceKey.class, SourceContainerItemStrategy.INSTANCE); GenericSlotCapacities.register(SourceKeyType.TYPE, (long) SourceContainerItemStrategy.MAX_SOURCE); - bus.addListener(ArsEngItems::initP2PAttunement); + modEventBus.addListener(ArsEngItems::initP2PAttunement); MinecraftForge.EVENT_BUS.addListener(SpellP2PTunnelPart::onSpellHit); if (FMLEnvironment.dist == Dist.CLIENT) { @@ -86,9 +88,8 @@ public ArsEnergistique() { private static class Client { private static void init() { - var bus = FMLJavaModLoadingContext.get().getModEventBus(); - bus.addListener(SourceCellItem::initColours); - bus.addListener(PortableSourceCellItem::initColours); + modEventBus.addListener(SourceCellItem::initColours); + modEventBus.addListener(PortableSourceCellItem::initColours); AEKeyRendering.register(SourceKeyType.TYPE, SourceKey.class, SourceRenderer.INSTANCE); diff --git a/src/main/java/gripe/_90/arseng/block/entity/PlayerAwareScribesTile.java b/src/main/java/gripe/_90/arseng/block/entity/PlayerAwareScribesTile.java deleted file mode 100644 index cd41bd1..0000000 --- a/src/main/java/gripe/_90/arseng/block/entity/PlayerAwareScribesTile.java +++ /dev/null @@ -1,7 +0,0 @@ -package gripe._90.arseng.block.entity; - -import net.minecraft.world.entity.player.Player; - -public interface PlayerAwareScribesTile { - void arseng$setPlayer(Player player); -} diff --git a/src/main/java/gripe/_90/arseng/block/entity/SourceAcceptorBlockEntity.java b/src/main/java/gripe/_90/arseng/block/entity/SourceAcceptorBlockEntity.java index e5ab46e..a5b566b 100644 --- a/src/main/java/gripe/_90/arseng/block/entity/SourceAcceptorBlockEntity.java +++ b/src/main/java/gripe/_90/arseng/block/entity/SourceAcceptorBlockEntity.java @@ -19,7 +19,7 @@ import gripe._90.arseng.definition.ArsEngBlocks; import gripe._90.arseng.definition.ArsEngCapabilities; -import gripe._90.arseng.me.energy.SourceEnergyAdapter; +import gripe._90.arseng.me.energy.SourceEnergyAdaptor; public class SourceAcceptorBlockEntity extends AENetworkBlockEntity implements IExternalPowerSink { private LazyOptional sourceTileOptional; @@ -32,7 +32,7 @@ public SourceAcceptorBlockEntity(BlockPos pos, BlockState state) { @Override public void onLoad() { super.onLoad(); - sourceTileOptional = LazyOptional.of(() -> new SourceEnergyAdapter(this, this)); + sourceTileOptional = LazyOptional.of(() -> new SourceEnergyAdaptor(this, this)); } @NotNull diff --git a/src/main/java/gripe/_90/arseng/block/entity/SourceTileWrapper.java b/src/main/java/gripe/_90/arseng/block/entity/SourceTileWrapper.java index 306d41d..481faf2 100644 --- a/src/main/java/gripe/_90/arseng/block/entity/SourceTileWrapper.java +++ b/src/main/java/gripe/_90/arseng/block/entity/SourceTileWrapper.java @@ -2,17 +2,7 @@ import com.hollingsworth.arsnouveau.api.source.ISourceTile; -public class SourceTileWrapper implements IAdvancedSourceTile { - private final ISourceTile tile; - private final boolean relayTake; - private final boolean sourcelinkGive; - - public SourceTileWrapper(ISourceTile tile, boolean relayCanTake, boolean sourcelinkCanGive) { - this.tile = tile; - relayTake = relayCanTake; - sourcelinkGive = sourcelinkCanGive; - } - +public record SourceTileWrapper(ISourceTile tile, boolean takeFrom, boolean giveTo) implements IAdvancedSourceTile { @Override public int getTransferRate() { return tile.getTransferRate(); @@ -55,11 +45,11 @@ public int removeSource(int source) { @Override public boolean relayCanTakePower() { - return relayTake; + return takeFrom; } @Override public boolean sourcelinksCanProvidePower() { - return sourcelinkGive; + return giveTo; } } diff --git a/src/main/java/gripe/_90/arseng/item/PortableSourceCellItem.java b/src/main/java/gripe/_90/arseng/item/PortableSourceCellItem.java index f4dc3aa..cc33f8d 100644 --- a/src/main/java/gripe/_90/arseng/item/PortableSourceCellItem.java +++ b/src/main/java/gripe/_90/arseng/item/PortableSourceCellItem.java @@ -26,6 +26,7 @@ import gripe._90.arseng.ArsEnergistique; import gripe._90.arseng.definition.ArsEngItems; import gripe._90.arseng.me.cell.ISourceCellItem; +import gripe._90.arseng.me.cell.SourceCellHandler; public class PortableSourceCellItem extends AbstractPortableCell implements ISourceCellItem { private final StorageTier tier; @@ -57,13 +58,13 @@ public ResourceLocation getRecipeId() { @Override public void appendHoverText(ItemStack stack, Level level, List lines, TooltipFlag advancedTooltips) { super.appendHoverText(stack, level, lines, advancedTooltips); - addCellInformationToTooltip(stack, lines); + SourceCellHandler.INSTANCE.addCellInformationToTooltip(stack, lines); } @NotNull @Override public Optional getTooltipImage(@NotNull ItemStack stack) { - return getCellTooltipImage(stack); + return SourceCellHandler.INSTANCE.getTooltipImage(stack); } @Override diff --git a/src/main/java/gripe/_90/arseng/item/SourceCellItem.java b/src/main/java/gripe/_90/arseng/item/SourceCellItem.java index 25a50ad..4f7226e 100644 --- a/src/main/java/gripe/_90/arseng/item/SourceCellItem.java +++ b/src/main/java/gripe/_90/arseng/item/SourceCellItem.java @@ -27,6 +27,7 @@ import gripe._90.arseng.definition.ArsEngItems; import gripe._90.arseng.me.cell.ISourceCellItem; +import gripe._90.arseng.me.cell.SourceCellHandler; public class SourceCellItem extends AEBaseItem implements ISourceCellItem { private final StorageTier tier; @@ -103,13 +104,13 @@ private boolean disassemble(ItemStack stack, Level level, Player player) { @Override public void appendHoverText( @NotNull ItemStack stack, Level level, @NotNull List lines, @NotNull TooltipFlag advTooltips) { - addCellInformationToTooltip(stack, lines); + SourceCellHandler.INSTANCE.addCellInformationToTooltip(stack, lines); } @NotNull @Override public Optional getTooltipImage(@NotNull ItemStack stack) { - return getCellTooltipImage(stack); + return SourceCellHandler.INSTANCE.getTooltipImage(stack); } public static void initColours(RegisterColorHandlersEvent.Item event) { diff --git a/src/main/java/gripe/_90/arseng/me/cell/CreativeSourceCellInventory.java b/src/main/java/gripe/_90/arseng/me/cell/CreativeSourceCellInventory.java index 1a5a8e7..079ea92 100644 --- a/src/main/java/gripe/_90/arseng/me/cell/CreativeSourceCellInventory.java +++ b/src/main/java/gripe/_90/arseng/me/cell/CreativeSourceCellInventory.java @@ -12,13 +12,7 @@ import gripe._90.arseng.me.key.SourceKey; -public class CreativeSourceCellInventory implements StorageCell { - private final ItemStack i; - - public CreativeSourceCellInventory(ItemStack o) { - this.i = o; - } - +public record CreativeSourceCellInventory(ItemStack i) implements StorageCell { @Override public long extract(AEKey what, long amount, Actionable mode, IActionSource source) { return what instanceof SourceKey ? amount : 0; diff --git a/src/main/java/gripe/_90/arseng/me/cell/ISourceCellItem.java b/src/main/java/gripe/_90/arseng/me/cell/ISourceCellItem.java index 0cfc736..c3e16e8 100644 --- a/src/main/java/gripe/_90/arseng/me/cell/ISourceCellItem.java +++ b/src/main/java/gripe/_90/arseng/me/cell/ISourceCellItem.java @@ -1,12 +1,5 @@ package gripe._90.arseng.me.cell; -import java.util.List; -import java.util.Optional; - -import com.google.common.base.Preconditions; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.ItemStack; import appeng.api.config.FuzzyMode; @@ -29,14 +22,4 @@ default FuzzyMode getFuzzyMode(ItemStack is) { @Override default void setFuzzyMode(ItemStack is, FuzzyMode fzMode) {} - - default void addCellInformationToTooltip(ItemStack is, List lines) { - Preconditions.checkArgument(is.getItem() == this); - SourceCellHandler.INSTANCE.addCellInformationToTooltip(is, lines); - } - - default Optional getCellTooltipImage(ItemStack is) { - Preconditions.checkArgument(is.getItem() == this); - return SourceCellHandler.INSTANCE.getTooltipImage(is); - } } diff --git a/src/main/java/gripe/_90/arseng/me/cell/SourceCellHandler.java b/src/main/java/gripe/_90/arseng/me/cell/SourceCellHandler.java index 874de9c..14e7cb2 100644 --- a/src/main/java/gripe/_90/arseng/me/cell/SourceCellHandler.java +++ b/src/main/java/gripe/_90/arseng/me/cell/SourceCellHandler.java @@ -33,7 +33,7 @@ public SourceCellInventory getCellInventory(ItemStack is, @Nullable ISaveProvide return isCell(is) ? new SourceCellInventory((ISourceCellItem) is.getItem(), is, container) : null; } - void addCellInformationToTooltip(ItemStack is, List lines) { + public void addCellInformationToTooltip(ItemStack is, List lines) { var handler = getCellInventory(is, null); if (handler != null) { @@ -41,7 +41,7 @@ void addCellInformationToTooltip(ItemStack is, List lines) { } } - Optional getTooltipImage(ItemStack is) { + public Optional getTooltipImage(ItemStack is) { var handler = getCellInventory(is, null); if (handler == null) return Optional.empty(); diff --git a/src/main/java/gripe/_90/arseng/me/energy/SourceEnergyAdapter.java b/src/main/java/gripe/_90/arseng/me/energy/SourceEnergyAdaptor.java similarity index 84% rename from src/main/java/gripe/_90/arseng/me/energy/SourceEnergyAdapter.java rename to src/main/java/gripe/_90/arseng/me/energy/SourceEnergyAdaptor.java index d6c765c..624e759 100644 --- a/src/main/java/gripe/_90/arseng/me/energy/SourceEnergyAdapter.java +++ b/src/main/java/gripe/_90/arseng/me/energy/SourceEnergyAdaptor.java @@ -8,22 +8,9 @@ import gripe._90.arseng.block.entity.IAdvancedSourceTile; import gripe._90.arseng.definition.ArsEngConfig; -public class SourceEnergyAdapter implements IAdvancedSourceTile { +public record SourceEnergyAdaptor(IExternalPowerSink sink, IActionHost host) implements IAdvancedSourceTile { private static final double AE_PER_SOURCE = ArsEngConfig.AE_PER_SOURCE.get(); - private final IExternalPowerSink sink; - private final IActionHost host; - - public SourceEnergyAdapter(IExternalPowerSink sink, IActionHost host) { - this.sink = sink; - this.host = host; - } - - @Override - public String toString() { - return super.toString(); - } - @Override public int getTransferRate() { return getMaxSource(); diff --git a/src/main/java/gripe/_90/arseng/me/key/SourceKeyType.java b/src/main/java/gripe/_90/arseng/me/key/SourceKeyType.java index ef0c416..ff960f7 100644 --- a/src/main/java/gripe/_90/arseng/me/key/SourceKeyType.java +++ b/src/main/java/gripe/_90/arseng/me/key/SourceKeyType.java @@ -18,7 +18,7 @@ public class SourceKeyType extends AEKeyType { public static final Component SOURCE = Component.translatable("ars_nouveau.category.source"); public static final AEKeyType TYPE = new SourceKeyType(); - public SourceKeyType() { + private SourceKeyType() { super(ArsEnergistique.makeId("source"), SourceKey.class, SOURCE); } diff --git a/src/main/java/gripe/_90/arseng/me/storage/GenericStackSourceStorage.java b/src/main/java/gripe/_90/arseng/me/storage/GenericStackSourceStorage.java index 0a3cf0c..19b754c 100644 --- a/src/main/java/gripe/_90/arseng/me/storage/GenericStackSourceStorage.java +++ b/src/main/java/gripe/_90/arseng/me/storage/GenericStackSourceStorage.java @@ -9,13 +9,7 @@ import gripe._90.arseng.me.key.SourceKey; @SuppressWarnings("UnstableApiUsage") -public class GenericStackSourceStorage implements IAdvancedSourceTile { - private final GenericInternalInventory inv; - - public GenericStackSourceStorage(GenericInternalInventory inv) { - this.inv = inv; - } - +public record GenericStackSourceStorage(GenericInternalInventory inv) implements IAdvancedSourceTile { @Override public int getTransferRate() { return Integer.MAX_VALUE; diff --git a/src/main/java/gripe/_90/arseng/me/strategy/SourceExternalStorageStrategy.java b/src/main/java/gripe/_90/arseng/me/strategy/SourceExternalStorageStrategy.java index cd827de..da0b25d 100644 --- a/src/main/java/gripe/_90/arseng/me/strategy/SourceExternalStorageStrategy.java +++ b/src/main/java/gripe/_90/arseng/me/strategy/SourceExternalStorageStrategy.java @@ -29,7 +29,7 @@ public class SourceExternalStorageStrategy implements ExternalStorageStrategy { private final Direction fromSide; public SourceExternalStorageStrategy(ServerLevel level, BlockPos fromPos, Direction fromSide) { - this.apiCache = BlockApiCache.create(ArsEngCapabilities.SOURCE_TILE, level, fromPos); + apiCache = BlockApiCache.create(ArsEngCapabilities.SOURCE_TILE, level, fromPos); this.fromSide = fromSide; } diff --git a/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageExportStrategy.java b/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageExportStrategy.java index f538a4f..e50f6a7 100644 --- a/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageExportStrategy.java +++ b/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageExportStrategy.java @@ -21,7 +21,7 @@ public class SourceStorageExportStrategy implements StackExportStrategy { private final Direction fromSide; public SourceStorageExportStrategy(ServerLevel level, BlockPos fromPos, Direction fromSide) { - this.apiCache = BlockApiCache.create(ArsEngCapabilities.SOURCE_TILE, level, fromPos); + apiCache = BlockApiCache.create(ArsEngCapabilities.SOURCE_TILE, level, fromPos); this.fromSide = fromSide; } diff --git a/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageImportStrategy.java b/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageImportStrategy.java index a9d16f1..73d9d04 100644 --- a/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageImportStrategy.java +++ b/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageImportStrategy.java @@ -25,7 +25,7 @@ public class SourceStorageImportStrategy implements StackImportStrategy { private final Direction fromSide; public SourceStorageImportStrategy(ServerLevel level, BlockPos fromPos, Direction fromSide) { - this.apiCache = BlockApiCache.create(ArsEngCapabilities.SOURCE_TILE, level, fromPos); + apiCache = BlockApiCache.create(ArsEngCapabilities.SOURCE_TILE, level, fromPos); this.fromSide = fromSide; } diff --git a/src/main/java/gripe/_90/arseng/mixin/ScribesTileMixin.java b/src/main/java/gripe/_90/arseng/mixin/ScribesTileMixin.java index 884e8ad..16b7737 100644 --- a/src/main/java/gripe/_90/arseng/mixin/ScribesTileMixin.java +++ b/src/main/java/gripe/_90/arseng/mixin/ScribesTileMixin.java @@ -26,10 +26,8 @@ import appeng.api.storage.MEStorage; import appeng.capabilities.Capabilities; -import gripe._90.arseng.block.entity.PlayerAwareScribesTile; - @Mixin(value = ScribesTile.class, remap = false) -public abstract class ScribesTileMixin extends ModdedTile implements PlayerAwareScribesTile { +public abstract class ScribesTileMixin extends ModdedTile { @Shadow public List consumedStacks; diff --git a/src/main/java/gripe/_90/arseng/part/SourceAcceptorPart.java b/src/main/java/gripe/_90/arseng/part/SourceAcceptorPart.java index e1872d9..6d52699 100644 --- a/src/main/java/gripe/_90/arseng/part/SourceAcceptorPart.java +++ b/src/main/java/gripe/_90/arseng/part/SourceAcceptorPart.java @@ -18,13 +18,13 @@ import gripe._90.arseng.ArsEnergistique; import gripe._90.arseng.definition.ArsEngCapabilities; -import gripe._90.arseng.me.energy.SourceEnergyAdapter; +import gripe._90.arseng.me.energy.SourceEnergyAdaptor; public class SourceAcceptorPart extends AEBasePart implements IExternalPowerSink { @PartModels private static final IPartModel MODEL = new PartModel(ArsEnergistique.makeId("part/source_acceptor")); - private final SourceEnergyAdapter adapter = new SourceEnergyAdapter(this, this); + private final SourceEnergyAdaptor adapter = new SourceEnergyAdaptor(this, this); public SourceAcceptorPart(IPartItem partItem) { super(partItem); diff --git a/src/main/java/gripe/_90/arseng/part/SpellP2PTunnelPart.java b/src/main/java/gripe/_90/arseng/part/SpellP2PTunnelPart.java index 9202e82..ef58c95 100644 --- a/src/main/java/gripe/_90/arseng/part/SpellP2PTunnelPart.java +++ b/src/main/java/gripe/_90/arseng/part/SpellP2PTunnelPart.java @@ -15,9 +15,9 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.phys.BlockHitResult; +import appeng.api.parts.IPartHost; import appeng.api.parts.IPartItem; import appeng.api.parts.IPartModel; -import appeng.blockentity.networking.CableBusBlockEntity; import appeng.items.parts.PartModels; import appeng.parts.p2p.P2PModels; import appeng.parts.p2p.P2PTunnelPart; @@ -52,8 +52,8 @@ public static void onSpellHit(SpellProjectileHitEvent event) { if (event.getHitResult() instanceof BlockHitResult blockHit) { var be = event.getProjectile().level().getBlockEntity(blockHit.getBlockPos()); - if (be instanceof CableBusBlockEntity cableBus) { - var part = cableBus.getPart(blockHit.getDirection()); + if (be instanceof IPartHost partHost) { + var part = partHost.getPart(blockHit.getDirection()); if (part instanceof SpellP2PTunnelPart spellP2P && spellP2P.equals(spellP2P.getInput())) { var outputs = new ArrayList<>(spellP2P.getOutputs());