Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Nov 28, 2023
1 parent 1004b04 commit 4777eaa
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 95 deletions.
21 changes: 11 additions & 10 deletions src/main/java/gripe/_90/arseng/ArsEnergistique.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<IAdvancedSourceTile> sourceTileOptional;
Expand All @@ -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
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/gripe/_90/arseng/block/entity/SourceTileWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,13 +58,13 @@ public ResourceLocation getRecipeId() {
@Override
public void appendHoverText(ItemStack stack, Level level, List<Component> lines, TooltipFlag advancedTooltips) {
super.appendHoverText(stack, level, lines, advancedTooltips);
addCellInformationToTooltip(stack, lines);
SourceCellHandler.INSTANCE.addCellInformationToTooltip(stack, lines);
}

@NotNull
@Override
public Optional<TooltipComponent> getTooltipImage(@NotNull ItemStack stack) {
return getCellTooltipImage(stack);
return SourceCellHandler.INSTANCE.getTooltipImage(stack);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/gripe/_90/arseng/item/SourceCellItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,13 +104,13 @@ private boolean disassemble(ItemStack stack, Level level, Player player) {
@Override
public void appendHoverText(
@NotNull ItemStack stack, Level level, @NotNull List<Component> lines, @NotNull TooltipFlag advTooltips) {
addCellInformationToTooltip(stack, lines);
SourceCellHandler.INSTANCE.addCellInformationToTooltip(stack, lines);
}

@NotNull
@Override
public Optional<TooltipComponent> getTooltipImage(@NotNull ItemStack stack) {
return getCellTooltipImage(stack);
return SourceCellHandler.INSTANCE.getTooltipImage(stack);
}

public static void initColours(RegisterColorHandlersEvent.Item event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/gripe/_90/arseng/me/cell/ISourceCellItem.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -29,14 +22,4 @@ default FuzzyMode getFuzzyMode(ItemStack is) {

@Override
default void setFuzzyMode(ItemStack is, FuzzyMode fzMode) {}

default void addCellInformationToTooltip(ItemStack is, List<Component> lines) {
Preconditions.checkArgument(is.getItem() == this);
SourceCellHandler.INSTANCE.addCellInformationToTooltip(is, lines);
}

default Optional<TooltipComponent> getCellTooltipImage(ItemStack is) {
Preconditions.checkArgument(is.getItem() == this);
return SourceCellHandler.INSTANCE.getTooltipImage(is);
}
}
4 changes: 2 additions & 2 deletions src/main/java/gripe/_90/arseng/me/cell/SourceCellHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public SourceCellInventory getCellInventory(ItemStack is, @Nullable ISaveProvide
return isCell(is) ? new SourceCellInventory((ISourceCellItem) is.getItem(), is, container) : null;
}

void addCellInformationToTooltip(ItemStack is, List<Component> lines) {
public void addCellInformationToTooltip(ItemStack is, List<Component> lines) {
var handler = getCellInventory(is, null);

if (handler != null) {
lines.add(Tooltips.bytesUsed(handler.getUsedBytes(), handler.getTotalBytes()));
}
}

Optional<TooltipComponent> getTooltipImage(ItemStack is) {
public Optional<TooltipComponent> getTooltipImage(ItemStack is) {
var handler = getCellInventory(is, null);
if (handler == null) return Optional.empty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gripe/_90/arseng/me/key/SourceKeyType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/gripe/_90/arseng/mixin/ScribesTileMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> consumedStacks;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gripe/_90/arseng/part/SourceAcceptorPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gripe/_90/arseng/part/SpellP2PTunnelPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 4777eaa

Please sign in to comment.