From 707b8784cbac1f7de89c38ffaa752e223c2f0514 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Fri, 1 Sep 2023 16:50:47 +0200 Subject: [PATCH 1/2] refactor: remove duplication around energy item / block item --- .../platform/api/PlatformApi.java | 5 +- .../platform/api/PlatformApiProxy.java | 13 ++- .../api/item/AbstractEnergyBlockItem.java | 58 ++++++------- .../platform/api/item/AbstractEnergyItem.java | 37 ++------- .../platform/api/item/EnergyItemHelper.java | 25 ++++++ .../platform/common/PlatformApiImpl.java | 15 ++-- .../block/entity/ControllerBlockEntity.java | 6 +- .../common/content/CreativeModeTabItems.java | 4 +- .../internal/item/EnergyItemHelperImpl.java | 82 +++++++++++++++++++ .../common/item/AbstractNetworkBoundItem.java | 3 +- .../item/block/ControllerBlockItem.java | 25 +----- .../rei/RefinedStorageREIClientPlugin.java | 4 +- .../rei/RefinedStorageREIClientPlugin.java | 4 +- 13 files changed, 166 insertions(+), 115 deletions(-) create mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/EnergyItemHelper.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/EnergyItemHelperImpl.java diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java index b874ce9cc..a9e5da57d 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java @@ -19,6 +19,7 @@ import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; @@ -75,8 +76,6 @@ public interface PlatformApi { MutableComponent createTranslation(String category, String value, Object... args); - MutableComponent createStoredWithCapacityTranslation(long stored, long capacity, double pct); - ComponentMapFactory getNetworkComponentMapFactory(); PlatformRegistry getGridSynchronizerRegistry(); @@ -143,5 +142,7 @@ GridScrollingStrategy createGridScrollingStrategy(AbstractContainerMenu containe Optional getEnergyStorage(ItemStack stack); + EnergyItemHelper getEnergyItemHelper(); + EnergyStorage asItemEnergyStorage(EnergyStorage energyStorage, ItemStack stack); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java index ac6613efe..d93c0da34 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java @@ -19,6 +19,7 @@ import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; @@ -121,13 +122,6 @@ public MutableComponent createTranslation(final String category, final String va return ensureLoaded().createTranslation(category, value, args); } - @Override - public MutableComponent createStoredWithCapacityTranslation(final long stored, - final long capacity, - final double pct) { - return ensureLoaded().createStoredWithCapacityTranslation(stored, capacity, pct); - } - @Override public ComponentMapFactory getNetworkComponentMapFactory() { return ensureLoaded().getNetworkComponentMapFactory(); @@ -286,6 +280,11 @@ public Optional getEnergyStorage(final ItemStack stack) { return ensureLoaded().getEnergyStorage(stack); } + @Override + public EnergyItemHelper getEnergyItemHelper() { + return ensureLoaded().getEnergyItemHelper(); + } + @Override public EnergyStorage asItemEnergyStorage(final EnergyStorage energyStorage, final ItemStack stack) { return ensureLoaded().asItemEnergyStorage(energyStorage, stack); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyBlockItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyBlockItem.java index 4323d7e85..071661175 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyBlockItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyBlockItem.java @@ -1,25 +1,24 @@ package com.refinedmods.refinedstorage2.platform.api.item; -import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; - import java.util.List; -import java.util.function.Supplier; -import java.util.stream.Stream; import javax.annotation.Nullable; -import net.minecraft.ChatFormatting; +import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; -import net.minecraft.util.Mth; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; 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; public abstract class AbstractEnergyBlockItem extends BlockItem implements EnergyItem { - protected AbstractEnergyBlockItem(final Block block, final Properties properties) { + private final EnergyItemHelper helper; + + protected AbstractEnergyBlockItem(final Block block, final Properties properties, final EnergyItemHelper helper) { super(block, properties); + this.helper = helper; } @Override @@ -30,49 +29,38 @@ public void appendHoverText( final TooltipFlag flag ) { super.appendHoverText(stack, level, lines, flag); - PlatformApi.INSTANCE.getEnergyStorage(stack).ifPresent(energyStorage -> { - final long stored = energyStorage.getStored(); - final long capacity = energyStorage.getCapacity(); - final double pct = stored / (double) capacity; - lines.add(PlatformApi.INSTANCE.createStoredWithCapacityTranslation(stored, capacity, pct) - .withStyle(ChatFormatting.GRAY)); - }); + helper.addTooltip(stack, lines); } @Override public boolean isBarVisible(final ItemStack stack) { - return PlatformApi.INSTANCE.getEnergyStorage(stack).isPresent(); + return helper.isBarVisible(stack); } @Override public int getBarWidth(final ItemStack stack) { - return PlatformApi.INSTANCE.getEnergyStorage(stack).map(energyStorage -> (int) Math.round( - (energyStorage.getStored() / (double) energyStorage.getCapacity()) * 13D - )).orElse(0); + return helper.getBarWidth(stack); } @Override public int getBarColor(final ItemStack stack) { - return PlatformApi.INSTANCE.getEnergyStorage(stack).map(energyStorage -> Mth.hsvToRgb( - Math.max(0.0F, (float) energyStorage.getStored() / (float) energyStorage.getCapacity()) / 3.0F, - 1.0F, - 1.0F - )).orElse(0); + return helper.getBarColor(stack); } public ItemStack createAtEnergyCapacity() { - final ItemStack stack = new ItemStack(this); - PlatformApi.INSTANCE.getEnergyStorage(stack).ifPresent(energyStorage -> energyStorage.receive( - energyStorage.getCapacity(), - Action.EXECUTE - )); - return stack; + return helper.createAtEnergyCapacity(this); } - public static Stream createAllAtEnergyCapacity(final List> items) { - return items.stream().map(Supplier::get) - .filter(AbstractEnergyBlockItem.class::isInstance) - .map(AbstractEnergyBlockItem.class::cast) - .map(AbstractEnergyBlockItem::createAtEnergyCapacity); + @Override + protected boolean updateCustomBlockEntityTag( + final BlockPos pos, + final Level level, + @Nullable final Player player, + final ItemStack stack, + final BlockState blockState + ) { + final boolean result = super.updateCustomBlockEntityTag(pos, level, player, stack, blockState); + helper.passEnergyToBlockEntity(pos, level, stack); + return result; } } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyItem.java index 9295c068c..b21dadda4 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyItem.java @@ -1,22 +1,20 @@ package com.refinedmods.refinedstorage2.platform.api.item; -import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; - import java.util.List; import javax.annotation.Nullable; -import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; -import net.minecraft.util.Mth; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; public abstract class AbstractEnergyItem extends Item implements EnergyItem { - protected AbstractEnergyItem(final Properties properties) { + private final EnergyItemHelper helper; + + protected AbstractEnergyItem(final Properties properties, final EnergyItemHelper helper) { super(properties); + this.helper = helper; } @Override @@ -27,42 +25,25 @@ public void appendHoverText( final TooltipFlag flag ) { super.appendHoverText(stack, level, lines, flag); - PlatformApi.INSTANCE.getEnergyStorage(stack).ifPresent(energyStorage -> { - final long stored = energyStorage.getStored(); - final long capacity = energyStorage.getCapacity(); - final double pct = stored / (double) capacity; - lines.add(PlatformApi.INSTANCE.createStoredWithCapacityTranslation(stored, capacity, pct) - .withStyle(ChatFormatting.GRAY)); - }); + helper.addTooltip(stack, lines); } @Override public boolean isBarVisible(final ItemStack stack) { - return PlatformApi.INSTANCE.getEnergyStorage(stack).isPresent(); + return helper.isBarVisible(stack); } @Override public int getBarWidth(final ItemStack stack) { - return PlatformApi.INSTANCE.getEnergyStorage(stack).map(energyStorage -> (int) Math.round( - (energyStorage.getStored() / (double) energyStorage.getCapacity()) * 13D - )).orElse(0); + return helper.getBarWidth(stack); } @Override public int getBarColor(final ItemStack stack) { - return PlatformApi.INSTANCE.getEnergyStorage(stack).map(energyStorage -> Mth.hsvToRgb( - Math.max(0.0F, (float) energyStorage.getStored() / (float) energyStorage.getCapacity()) / 3.0F, - 1.0F, - 1.0F - )).orElse(0); + return helper.getBarColor(stack); } public ItemStack createAtEnergyCapacity() { - final ItemStack stack = new ItemStack(this); - PlatformApi.INSTANCE.getEnergyStorage(stack).ifPresent(energyStorage -> energyStorage.receive( - energyStorage.getCapacity(), - Action.EXECUTE - )); - return stack; + return helper.createAtEnergyCapacity(this); } } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/EnergyItemHelper.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/EnergyItemHelper.java new file mode 100644 index 000000000..7d7160f0f --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/EnergyItemHelper.java @@ -0,0 +1,25 @@ +package com.refinedmods.refinedstorage2.platform.api.item; + +import java.util.List; + +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") +public interface EnergyItemHelper { + void addTooltip(ItemStack stack, List lines); + + boolean isBarVisible(ItemStack stack); + + int getBarWidth(ItemStack stack); + + int getBarColor(ItemStack stack); + + ItemStack createAtEnergyCapacity(Item item); + + void passEnergyToBlockEntity(BlockPos pos, Level level, ItemStack stack); +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java index 13f827d08..15caba72e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java @@ -23,6 +23,7 @@ import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; @@ -44,6 +45,7 @@ import com.refinedmods.refinedstorage2.platform.common.internal.grid.CompositeGridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.common.internal.grid.CompositeGridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.common.internal.grid.NoOpGridSynchronizer; +import com.refinedmods.refinedstorage2.platform.common.internal.item.EnergyItemHelperImpl; import com.refinedmods.refinedstorage2.platform.common.internal.item.StorageContainerItemHelperImpl; import com.refinedmods.refinedstorage2.platform.common.internal.network.LevelConnectionProvider; import com.refinedmods.refinedstorage2.platform.common.internal.registry.PlatformRegistryImpl; @@ -131,6 +133,7 @@ public class PlatformApiImpl implements PlatformApi { private final Map, ResourceRendering> resourceRenderingMap = new HashMap<>(); private final CompositeWirelessTransmitterRangeModifier wirelessTransmitterRangeModifier = new CompositeWirelessTransmitterRangeModifier(); + private final EnergyItemHelper energyItemHelper = new EnergyItemHelperImpl(); @Override public PlatformRegistry> getStorageTypeRegistry() { @@ -217,13 +220,6 @@ public MutableComponent createTranslation(final String category, final String va return IdentifierUtil.createTranslation(category, value, args); } - @Override - public MutableComponent createStoredWithCapacityTranslation(final long stored, - final long capacity, - final double pct) { - return IdentifierUtil.createStoredWithCapacityTranslation(stored, capacity, pct); - } - @Override public ComponentMapFactory getNetworkComponentMapFactory() { return networkComponentMapFactory; @@ -408,6 +404,11 @@ public Optional getEnergyStorage(final ItemStack stack) { return Platform.INSTANCE.getEnergyStorage(stack); } + @Override + public EnergyItemHelper getEnergyItemHelper() { + return energyItemHelper; + } + @Override public EnergyStorage asItemEnergyStorage(final EnergyStorage energyStorage, final ItemStack stack) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java index 5f760ea06..b487a290f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java @@ -100,7 +100,7 @@ private void saveRenderingInfo(final CompoundTag tag) { public void load(final CompoundTag tag) { super.load(tag); if (tag.contains(TAG_STORED)) { - loadEnergy(tag.getLong(TAG_STORED)); + energyStorage.receive(tag.getLong(TAG_STORED), Action.EXECUTE); } } @@ -135,8 +135,4 @@ public long getActualCapacity() { public EnergyStorage getEnergyStorage() { return energyStorage; } - - public void loadEnergy(final long stored) { - energyStorage.receive(stored, Action.EXECUTE); - } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java index 0fe1369f1..a4803c336 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.content; -import com.refinedmods.refinedstorage2.platform.api.item.AbstractEnergyBlockItem; +import com.refinedmods.refinedstorage2.platform.common.internal.item.EnergyItemHelperImpl; import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.item.ProcessorItem; @@ -24,7 +24,7 @@ public static void append(final Consumer consumer) { private static void appendBlocks(final Consumer consumer) { final Consumer itemConsumer = item -> consumer.accept(new ItemStack(item)); Items.INSTANCE.getControllers().stream().map(Supplier::get).forEach(itemConsumer); - AbstractEnergyBlockItem.createAllAtEnergyCapacity(Items.INSTANCE.getControllers()).forEach(consumer); + EnergyItemHelperImpl.createAllAtEnergyCapacity(Items.INSTANCE.getControllers()).forEach(consumer); Items.INSTANCE.getCreativeControllers().stream().map(Supplier::get).forEach(itemConsumer); Items.INSTANCE.getCables().stream().map(Supplier::get).forEach(itemConsumer); Items.INSTANCE.getImporters().stream().map(Supplier::get).forEach(itemConsumer); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/EnergyItemHelperImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/EnergyItemHelperImpl.java new file mode 100644 index 000000000..8faba40e9 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/EnergyItemHelperImpl.java @@ -0,0 +1,82 @@ +package com.refinedmods.refinedstorage2.platform.common.internal.item; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.blockentity.EnergyBlockEntity; +import com.refinedmods.refinedstorage2.platform.api.item.AbstractEnergyBlockItem; +import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; + +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Stream; + +import net.minecraft.ChatFormatting; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createStoredWithCapacityTranslation; + +public class EnergyItemHelperImpl implements EnergyItemHelper { + @Override + public void addTooltip(final ItemStack stack, final List lines) { + PlatformApi.INSTANCE.getEnergyStorage(stack).ifPresent(energyStorage -> { + final long stored = energyStorage.getStored(); + final long capacity = energyStorage.getCapacity(); + final double pct = stored / (double) capacity; + lines.add(createStoredWithCapacityTranslation(stored, capacity, pct).withStyle(ChatFormatting.GRAY)); + }); + } + + @Override + public boolean isBarVisible(final ItemStack stack) { + return PlatformApi.INSTANCE.getEnergyStorage(stack).isPresent(); + } + + @Override + public int getBarWidth(final ItemStack stack) { + return PlatformApi.INSTANCE.getEnergyStorage(stack).map(energyStorage -> (int) Math.round( + (energyStorage.getStored() / (double) energyStorage.getCapacity()) * 13D + )).orElse(0); + } + + @Override + public int getBarColor(final ItemStack stack) { + return PlatformApi.INSTANCE.getEnergyStorage(stack).map(energyStorage -> Mth.hsvToRgb( + Math.max(0.0F, (float) energyStorage.getStored() / (float) energyStorage.getCapacity()) / 3.0F, + 1.0F, + 1.0F + )).orElse(0); + } + + @Override + public ItemStack createAtEnergyCapacity(final Item item) { + final ItemStack stack = item.getDefaultInstance(); + PlatformApi.INSTANCE.getEnergyStorage(stack).ifPresent(energyStorage -> energyStorage.receive( + energyStorage.getCapacity(), + Action.EXECUTE + )); + return stack; + } + + @Override + public void passEnergyToBlockEntity(final BlockPos pos, final Level level, final ItemStack stack) { + if (level.isClientSide() || !(level.getBlockEntity(pos) instanceof EnergyBlockEntity energyBlockEntity)) { + return; + } + PlatformApi.INSTANCE.getEnergyStorage(stack).ifPresent( + energyStorage -> energyBlockEntity.getEnergyStorage().receive(energyStorage.getStored(), Action.EXECUTE) + ); + } + + public static Stream createAllAtEnergyCapacity(final List> items) { + return items.stream().map(Supplier::get) + .filter(AbstractEnergyBlockItem.class::isInstance) + .map(AbstractEnergyBlockItem.class::cast) + .map(AbstractEnergyBlockItem::createAtEnergyCapacity); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/AbstractNetworkBoundItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/AbstractNetworkBoundItem.java index b6e85b60f..946a14343 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/AbstractNetworkBoundItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/AbstractNetworkBoundItem.java @@ -1,5 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.item; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.item.AbstractEnergyItem; import com.refinedmods.refinedstorage2.platform.api.item.HelpTooltipComponent; import com.refinedmods.refinedstorage2.platform.api.network.node.PlatformNetworkNodeContainer; @@ -41,7 +42,7 @@ public abstract class AbstractNetworkBoundItem extends AbstractEnergyItem { private static final String TAG_DIMENSION = "dim"; protected AbstractNetworkBoundItem(final Properties properties) { - super(properties); + super(properties, PlatformApi.INSTANCE.getEnergyItemHelper()); } public boolean isBound(final ItemStack stack) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ControllerBlockItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ControllerBlockItem.java index b52ab71d8..8bc37651e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ControllerBlockItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ControllerBlockItem.java @@ -6,20 +6,14 @@ import com.refinedmods.refinedstorage2.platform.api.item.AbstractEnergyBlockItem; import com.refinedmods.refinedstorage2.platform.api.item.HelpTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.block.entity.ControllerBlockEntity; import java.util.Optional; -import javax.annotation.Nullable; -import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; @@ -28,7 +22,7 @@ public class ControllerBlockItem extends AbstractEnergyBlockItem { private final Component name; public ControllerBlockItem(final Block block, final Component displayName) { - super(block, new Item.Properties().stacksTo(1)); + super(block, new Item.Properties().stacksTo(1), PlatformApi.INSTANCE.getEnergyItemHelper()); this.name = displayName; } @@ -54,21 +48,4 @@ public Optional createEnergyStorage(final ItemStack stack) { ); return Optional.of(PlatformApi.INSTANCE.asItemEnergyStorage(energyStorage, stack)); } - - @Override - protected boolean updateCustomBlockEntityTag( - final BlockPos pos, - final Level level, - @Nullable final Player player, - final ItemStack stack, - final BlockState blockState - ) { - final boolean result = super.updateCustomBlockEntityTag(pos, level, player, stack, blockState); - if (!level.isClientSide() && level.getBlockEntity(pos) instanceof ControllerBlockEntity controllerBlockEntity) { - PlatformApi.INSTANCE.getEnergyStorage(stack).ifPresent( - energyStorage -> controllerBlockEntity.loadEnergy(energyStorage.getStored()) - ); - } - return result; - } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/integration/recipemod/rei/RefinedStorageREIClientPlugin.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/integration/recipemod/rei/RefinedStorageREIClientPlugin.java index 47654f689..f11ede392 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/integration/recipemod/rei/RefinedStorageREIClientPlugin.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/integration/recipemod/rei/RefinedStorageREIClientPlugin.java @@ -2,13 +2,13 @@ import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.item.AbstractEnergyBlockItem; import com.refinedmods.refinedstorage2.platform.common.block.ColorableBlock; import com.refinedmods.refinedstorage2.platform.common.content.BlockColorMap; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.content.ContentIds; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.Tags; +import com.refinedmods.refinedstorage2.platform.common.internal.item.EnergyItemHelperImpl; import com.refinedmods.refinedstorage2.platform.common.screen.AbstractBaseScreen; import java.util.function.Supplier; @@ -73,7 +73,7 @@ public void registerCollapsibleEntries(final CollapsibleEntryRegistry registry) registry.group( createIdentifier("fully_charged_controller"), createTranslation("block", "controller.rei_fully_charged"), - AbstractEnergyBlockItem.createAllAtEnergyCapacity(Items.INSTANCE.getControllers()) + EnergyItemHelperImpl.createAllAtEnergyCapacity(Items.INSTANCE.getControllers()) .map(EntryStacks::of).collect(Collectors.toList()) ); groupItems( diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/recipemod/rei/RefinedStorageREIClientPlugin.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/recipemod/rei/RefinedStorageREIClientPlugin.java index d07b17dd0..95f94a182 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/recipemod/rei/RefinedStorageREIClientPlugin.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/recipemod/rei/RefinedStorageREIClientPlugin.java @@ -2,13 +2,13 @@ import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.item.AbstractEnergyBlockItem; import com.refinedmods.refinedstorage2.platform.common.block.ColorableBlock; import com.refinedmods.refinedstorage2.platform.common.content.BlockColorMap; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.content.ContentIds; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.Tags; +import com.refinedmods.refinedstorage2.platform.common.internal.item.EnergyItemHelperImpl; import com.refinedmods.refinedstorage2.platform.common.screen.AbstractBaseScreen; import java.util.function.Supplier; @@ -72,7 +72,7 @@ public void registerCollapsibleEntries(final CollapsibleEntryRegistry registry) registry.group( createIdentifier("fully_charged_controller"), createTranslation("block", "controller.rei_fully_charged"), - AbstractEnergyBlockItem.createAllAtEnergyCapacity(Items.INSTANCE.getControllers()) + EnergyItemHelperImpl.createAllAtEnergyCapacity(Items.INSTANCE.getControllers()) .map(EntryStacks::of).collect(Collectors.toList()) ); groupItems( From 2cd3946dab3765a347c259df6159cedd24002fed Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Fri, 1 Sep 2023 17:54:50 +0200 Subject: [PATCH 2/2] refactor: api for network bound items --- .../platform/api/PlatformApi.java | 3 + .../platform/api/PlatformApiProxy.java | 6 + .../api/item/AbstractEnergyBlockItem.java | 2 + .../platform/api/item/AbstractEnergyItem.java | 2 + .../item/AbstractNetworkBoundEnergyItem.java | 49 +++++++++ .../api/item/NetworkBoundItemHelper.java | 26 +++++ .../api/item/NetworkBoundItemSession.java | 16 +++ .../platform/common/PlatformApiImpl.java | 8 ++ .../AbstractBaseContainerMenu.java | 5 +- .../slot/PlayerSlotReference.java | 4 +- .../common/internal/grid/WirelessGrid.java | 53 ++------- .../internal/grid/WirelessGridOperations.java | 14 +-- .../item/NetworkBoundItemHelperImpl.java} | 104 ++++++++---------- .../item/NetworkBoundItemSessionImpl.java} | 48 +++++--- .../common/item/WirelessGridItem.java | 33 +++--- .../item/block/ControllerBlockItem.java | 1 - .../NetworkItemItemPropertyFunction.java | 4 +- 17 files changed, 230 insertions(+), 148 deletions(-) create mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractNetworkBoundEnergyItem.java create mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/NetworkBoundItemHelper.java create mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/NetworkBoundItemSession.java rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/{item/AbstractNetworkBoundItem.java => internal/item/NetworkBoundItemHelperImpl.java} (69%) rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/{item/NetworkBoundItemContext.java => internal/item/NetworkBoundItemSessionImpl.java} (51%) diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java index a9e5da57d..68c119669 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java @@ -20,6 +20,7 @@ import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemHelper; import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; @@ -145,4 +146,6 @@ GridScrollingStrategy createGridScrollingStrategy(AbstractContainerMenu containe EnergyItemHelper getEnergyItemHelper(); EnergyStorage asItemEnergyStorage(EnergyStorage energyStorage, ItemStack stack); + + NetworkBoundItemHelper getNetworkBoundItemHelper(); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java index d93c0da34..5411ec11f 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java @@ -20,6 +20,7 @@ import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemHelper; import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; @@ -290,6 +291,11 @@ public EnergyStorage asItemEnergyStorage(final EnergyStorage energyStorage, fina return ensureLoaded().asItemEnergyStorage(energyStorage, stack); } + @Override + public NetworkBoundItemHelper getNetworkBoundItemHelper() { + return ensureLoaded().getNetworkBoundItemHelper(); + } + private PlatformApi ensureLoaded() { if (delegate == null) { throw new IllegalStateException("Platform API not loaded yet"); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyBlockItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyBlockItem.java index 071661175..52870ecec 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyBlockItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyBlockItem.java @@ -12,7 +12,9 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; +import org.apiguardian.api.API; +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") public abstract class AbstractEnergyBlockItem extends BlockItem implements EnergyItem { private final EnergyItemHelper helper; diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyItem.java index b21dadda4..e4dbd9b95 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractEnergyItem.java @@ -8,7 +8,9 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; +import org.apiguardian.api.API; +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") public abstract class AbstractEnergyItem extends Item implements EnergyItem { private final EnergyItemHelper helper; diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractNetworkBoundEnergyItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractNetworkBoundEnergyItem.java new file mode 100644 index 000000000..46c31e34b --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractNetworkBoundEnergyItem.java @@ -0,0 +1,49 @@ +package com.refinedmods.refinedstorage2.platform.api.item; + +import java.util.List; +import java.util.Optional; +import javax.annotation.Nullable; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") +public abstract class AbstractNetworkBoundEnergyItem extends AbstractEnergyItem { + protected final NetworkBoundItemHelper networkBoundItemHelper; + + protected AbstractNetworkBoundEnergyItem(final Properties properties, + final EnergyItemHelper energyItemHelper, + final NetworkBoundItemHelper networkBoundItemHelper) { + super(properties, energyItemHelper); + this.networkBoundItemHelper = networkBoundItemHelper; + } + + @Override + public InteractionResult useOn(final UseOnContext ctx) { + return networkBoundItemHelper.bind(ctx); + } + + @Override + public Optional getTooltipImage(final ItemStack stack) { + return networkBoundItemHelper.getTooltipImage(stack); + } + + @Override + public void appendHoverText(final ItemStack stack, + @Nullable final Level level, + final List tooltip, + final TooltipFlag flag) { + super.appendHoverText(stack, level, tooltip, flag); + networkBoundItemHelper.addTooltip(stack, tooltip); + } + + public boolean isBound(final ItemStack stack) { + return networkBoundItemHelper.isBound(stack); + } +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/NetworkBoundItemHelper.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/NetworkBoundItemHelper.java new file mode 100644 index 000000000..211398d14 --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/NetworkBoundItemHelper.java @@ -0,0 +1,26 @@ +package com.refinedmods.refinedstorage2.platform.api.item; + +import java.util.List; +import java.util.Optional; + +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") +public interface NetworkBoundItemHelper { + void addTooltip(ItemStack stack, List lines); + + InteractionResult bind(UseOnContext ctx); + + Optional getTooltipImage(ItemStack stack); + + NetworkBoundItemSession openSession(ItemStack stack, ServerPlayer player, InteractionHand hand); + + boolean isBound(ItemStack stack); +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/NetworkBoundItemSession.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/NetworkBoundItemSession.java new file mode 100644 index 000000000..4ecf4618a --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/NetworkBoundItemSession.java @@ -0,0 +1,16 @@ +package com.refinedmods.refinedstorage2.platform.api.item; + +import com.refinedmods.refinedstorage2.api.network.Network; + +import java.util.Optional; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") +public interface NetworkBoundItemSession { + Optional resolveNetwork(); + + boolean isActive(); + + void drainEnergy(long amount); +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java index 15caba72e..a6fa5acb4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java @@ -24,6 +24,7 @@ import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemHelper; import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; @@ -46,6 +47,7 @@ import com.refinedmods.refinedstorage2.platform.common.internal.grid.CompositeGridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.common.internal.grid.NoOpGridSynchronizer; import com.refinedmods.refinedstorage2.platform.common.internal.item.EnergyItemHelperImpl; +import com.refinedmods.refinedstorage2.platform.common.internal.item.NetworkBoundItemHelperImpl; import com.refinedmods.refinedstorage2.platform.common.internal.item.StorageContainerItemHelperImpl; import com.refinedmods.refinedstorage2.platform.common.internal.network.LevelConnectionProvider; import com.refinedmods.refinedstorage2.platform.common.internal.registry.PlatformRegistryImpl; @@ -134,6 +136,7 @@ public class PlatformApiImpl implements PlatformApi { private final CompositeWirelessTransmitterRangeModifier wirelessTransmitterRangeModifier = new CompositeWirelessTransmitterRangeModifier(); private final EnergyItemHelper energyItemHelper = new EnergyItemHelperImpl(); + private final NetworkBoundItemHelper networkBoundItemHelper = new NetworkBoundItemHelperImpl(); @Override public PlatformRegistry> getStorageTypeRegistry() { @@ -414,4 +417,9 @@ public EnergyStorage asItemEnergyStorage(final EnergyStorage energyStorage, final ItemStack stack) { return new ItemEnergyStorage(stack, energyStorage); } + + @Override + public NetworkBoundItemHelper getNetworkBoundItemHelper() { + return networkBoundItemHelper; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java index e503cf6dd..16bce7c38 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java @@ -74,8 +74,7 @@ protected void addPlayerInventory(final Inventory inventory, final int inventory for (int i = 0; i < 9; i++) { final int x = inventoryX + i * 18; final int y = inventoryY + 4 + (3 * 18); - final boolean disabled = disabledPlayerInventorySlot != null - && disabledPlayerInventorySlot.getSlotIndex() == id; + final boolean disabled = disabledPlayerInventorySlot != null && disabledPlayerInventorySlot.isDisabled(id); addSlot(disabled ? new DisabledSlot(inventory, id, x, y) : new Slot(inventory, id, x, y)); id++; } @@ -107,6 +106,6 @@ public void clicked(final int id, final int dragType, final ClickType clickType, private boolean isSwappingDisabledSlotWithNumberKeys(final int dragType, final ClickType clickType) { return disabledPlayerInventorySlot != null && clickType == ClickType.SWAP - && dragType == disabledPlayerInventorySlot.getSlotIndex(); + && disabledPlayerInventorySlot.isDisabled(dragType); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/slot/PlayerSlotReference.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/slot/PlayerSlotReference.java index 79624d01b..ddcef11e4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/slot/PlayerSlotReference.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/slot/PlayerSlotReference.java @@ -17,8 +17,8 @@ public ItemStack resolve(final Player player) { return player.getInventory().getItem(slotIndex); } - public int getSlotIndex() { - return slotIndex; + public boolean isDisabled(final int playerSlotIndex) { + return playerSlotIndex == slotIndex; } public void writeToBuf(final ByteBuf buf) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java index 86e5ef01e..c624df9ba 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java @@ -5,12 +5,9 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; -import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridWatchers; -import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage; @@ -19,68 +16,38 @@ import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.blockentity.wirelesstransmitter.WirelessTransmitter; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; -import com.refinedmods.refinedstorage2.platform.api.network.node.PlatformNetworkNodeContainer; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemSession; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.common.item.NetworkBoundItemContext; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Optional; -import net.minecraft.server.MinecraftServer; - public class WirelessGrid implements Grid { - private final MinecraftServer server; - private final NetworkBoundItemContext ctx; + private final NetworkBoundItemSession session; private final GridWatchers watchers; - public WirelessGrid(final MinecraftServer server, final NetworkBoundItemContext ctx) { - this.server = server; - this.ctx = ctx; + public WirelessGrid(final NetworkBoundItemSession session) { + this.session = session; this.watchers = new GridWatchers(PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getAll()); } - private Optional getNetwork() { - if (ctx.getNetworkReference() == null) { - return Optional.empty(); - } - return Optional.ofNullable(server.getLevel(ctx.getNetworkReference().dimensionKey())) - .filter(level -> level.isLoaded(ctx.getNetworkReference().pos())) - .map(level -> level.getBlockEntity(ctx.getNetworkReference().pos())) - .filter(PlatformNetworkNodeContainer.class::isInstance) - .map(PlatformNetworkNodeContainer.class::cast) - .map(PlatformNetworkNodeContainer::getNode) - .map(NetworkNode::getNetwork) - .filter(this::isInRange); - } - - private boolean isInRange(final Network network) { - return network.getComponent(GraphNetworkComponent.class) - .getContainers(WirelessTransmitter.class) - .stream() - .anyMatch(wirelessTransmitter -> wirelessTransmitter.isInRange( - ctx.getPlayerLevel(), - ctx.getPlayerPosition() - )); - } - private Optional getStorage() { - return getNetwork().map(network -> network.getComponent(StorageNetworkComponent.class)); + return session.resolveNetwork().map(network -> network.getComponent(StorageNetworkComponent.class)); } @Override public void addWatcher(final GridWatcher watcher, final Class actorType) { - getNetwork().ifPresent(network -> watchers.addWatcher(watcher, actorType, network)); + session.resolveNetwork().ifPresent(network -> watchers.addWatcher(watcher, actorType, network)); } @Override public void removeWatcher(final GridWatcher watcher) { - getNetwork().ifPresent(network -> watchers.removeWatcher(watcher, network)); + session.resolveNetwork().ifPresent(network -> watchers.removeWatcher(watcher, network)); } @Override @@ -91,10 +58,10 @@ public Storage getItemStorage() { @Override public boolean isActive() { - final boolean networkActive = getNetwork().map( + final boolean networkActive = session.resolveNetwork().map( network -> network.getComponent(EnergyNetworkComponent.class).getStored() > 0 ).orElse(false); - return networkActive && ctx.isActive(); + return networkActive && session.isActive(); } @Override @@ -109,7 +76,7 @@ public GridOperations createOperations(final PlatformStorageChannelType storage.getStorageChannel(storageChannelType)) .map(storageChannel -> storageChannelType.createGridOperations(storageChannel, actor)) - .map(gridOperations -> (GridOperations) new WirelessGridOperations<>(gridOperations, ctx, watchers)) + .map(gridOperations -> (GridOperations) new WirelessGridOperations<>(gridOperations, session, watchers)) .orElseGet(this::createNoOpGridOperations); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGridOperations.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGridOperations.java index 89801bf3f..4b239a038 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGridOperations.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGridOperations.java @@ -6,19 +6,19 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridWatchers; import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage; import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemSession; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.item.NetworkBoundItemContext; public class WirelessGridOperations implements GridOperations { private final GridOperations delegate; - private final NetworkBoundItemContext ctx; + private final NetworkBoundItemSession session; private final GridWatchers watchers; public WirelessGridOperations(final GridOperations delegate, - final NetworkBoundItemContext ctx, + final NetworkBoundItemSession session, final GridWatchers watchers) { this.delegate = delegate; - this.ctx = ctx; + this.session = session; this.watchers = watchers; } @@ -45,9 +45,9 @@ public boolean insert(final T resource, } private void drain(final long amount) { - final boolean wasActive = ctx.isActive(); - ctx.drain(amount); - final boolean isActive = ctx.isActive(); + final boolean wasActive = session.isActive(); + session.drainEnergy(amount); + final boolean isActive = session.isActive(); if (wasActive != isActive) { watchers.activeChanged(isActive); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/AbstractNetworkBoundItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/NetworkBoundItemHelperImpl.java similarity index 69% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/AbstractNetworkBoundItem.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/NetworkBoundItemHelperImpl.java index 946a14343..029b832ab 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/AbstractNetworkBoundItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/NetworkBoundItemHelperImpl.java @@ -1,16 +1,14 @@ -package com.refinedmods.refinedstorage2.platform.common.item; +package com.refinedmods.refinedstorage2.platform.common.internal.item; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.item.AbstractEnergyItem; import com.refinedmods.refinedstorage2.platform.api.item.HelpTooltipComponent; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemHelper; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemSession; import com.refinedmods.refinedstorage2.platform.api.network.node.PlatformNetworkNodeContainer; import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.function.Consumer; -import javax.annotation.Nullable; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; @@ -21,17 +19,16 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public abstract class AbstractNetworkBoundItem extends AbstractEnergyItem { +public class NetworkBoundItemHelperImpl implements NetworkBoundItemHelper { private static final MutableComponent UNBOUND = createTranslation("item", "network_item.unbound") .withStyle(ChatFormatting.RED); private static final Component UNBOUND_HELP = createTranslation("item", "network_item.unbound.help"); @@ -41,10 +38,7 @@ public abstract class AbstractNetworkBoundItem extends AbstractEnergyItem { private static final String TAG_Z = "z"; private static final String TAG_DIMENSION = "dim"; - protected AbstractNetworkBoundItem(final Properties properties) { - super(properties, PlatformApi.INSTANCE.getEnergyItemHelper()); - } - + @Override public boolean isBound(final ItemStack stack) { final CompoundTag tag = stack.getTag(); if (tag == null) { @@ -53,37 +47,22 @@ public boolean isBound(final ItemStack stack) { return tag.contains(TAG_X) && tag.contains(TAG_Y) && tag.contains(TAG_Z) && tag.contains(TAG_DIMENSION); } - private Optional getNetworkReference(final ItemStack stack) { - if (!isBound(stack)) { - return Optional.empty(); - } - final CompoundTag tag = Objects.requireNonNull(stack.getTag()); - final int x = tag.getInt(TAG_X); - final int y = tag.getInt(TAG_Y); - final int z = tag.getInt(TAG_Z); - final ResourceLocation dimension = new ResourceLocation(tag.getString(TAG_DIMENSION)); - return Optional.of(new NetworkBoundItemContext.NetworkReference( - ResourceKey.create(Registries.DIMENSION, dimension), - new BlockPos(x, y, z) - )); - } - - protected void tryUse( - final ItemStack stack, - final ServerPlayer player, - final PlayerSlotReference slotReference, - final Consumer contextConsumer - ) { - final Optional networkReference = getNetworkReference(stack); - contextConsumer.accept(new NetworkBoundItemContext( - player, - slotReference, - networkReference.orElse(null) - )); + @Override + public void addTooltip(final ItemStack stack, final List lines) { + getNetworkReference(stack).ifPresentOrElse( + network -> lines.add(createTranslation( + "item", + "network_item.bound_to", + network.pos().getX(), + network.pos().getY(), + network.pos().getZ() + ).withStyle(ChatFormatting.GRAY)), + () -> lines.add(UNBOUND) + ); } @Override - public InteractionResult useOn(final UseOnContext ctx) { + public InteractionResult bind(final UseOnContext ctx) { if (ctx.getPlayer() == null) { return InteractionResult.PASS; } @@ -100,24 +79,6 @@ public InteractionResult useOn(final UseOnContext ctx) { return InteractionResult.SUCCESS; } - @Override - public void appendHoverText(final ItemStack stack, - @Nullable final Level level, - final List tooltip, - final TooltipFlag flag) { - super.appendHoverText(stack, level, tooltip, flag); - getNetworkReference(stack).ifPresentOrElse( - network -> tooltip.add(createTranslation( - "item", - "network_item.bound_to", - network.pos().getX(), - network.pos().getY(), - network.pos().getZ() - ).withStyle(ChatFormatting.GRAY)), - () -> tooltip.add(UNBOUND) - ); - } - @Override public Optional getTooltipImage(final ItemStack stack) { if (isBound(stack)) { @@ -125,4 +86,31 @@ public Optional getTooltipImage(final ItemStack stack) { } return Optional.of(new HelpTooltipComponent(UNBOUND_HELP)); } + + @Override + public NetworkBoundItemSession openSession(final ItemStack stack, + final ServerPlayer player, + final InteractionHand hand) { + final Optional networkReference = getNetworkReference(stack); + return new NetworkBoundItemSessionImpl( + player, + PlayerSlotReference.of(player, hand), + networkReference.orElse(null) + ); + } + + private Optional getNetworkReference(final ItemStack stack) { + if (!isBound(stack)) { + return Optional.empty(); + } + final CompoundTag tag = Objects.requireNonNull(stack.getTag()); + final int x = tag.getInt(TAG_X); + final int y = tag.getInt(TAG_Y); + final int z = tag.getInt(TAG_Z); + final ResourceLocation dimension = new ResourceLocation(tag.getString(TAG_DIMENSION)); + return Optional.of(new NetworkBoundItemSessionImpl.NetworkReference( + ResourceKey.create(Registries.DIMENSION, dimension), + new BlockPos(x, y, z) + )); + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/NetworkBoundItemContext.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/NetworkBoundItemSessionImpl.java similarity index 51% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/NetworkBoundItemContext.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/NetworkBoundItemSessionImpl.java index e5064def1..e0c997059 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/NetworkBoundItemContext.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/NetworkBoundItemSessionImpl.java @@ -1,9 +1,16 @@ -package com.refinedmods.refinedstorage2.platform.common.item; +package com.refinedmods.refinedstorage2.platform.common.internal.item; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; +import com.refinedmods.refinedstorage2.platform.api.blockentity.wirelesstransmitter.WirelessTransmitter; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemSession; +import com.refinedmods.refinedstorage2.platform.api.network.node.PlatformNetworkNodeContainer; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; +import java.util.Optional; import javax.annotation.Nullable; import net.minecraft.core.BlockPos; @@ -12,14 +19,14 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; -public class NetworkBoundItemContext { +public class NetworkBoundItemSessionImpl implements NetworkBoundItemSession { private final Player player; private final Vec3 playerPosition; private final PlayerSlotReference playerSlotReference; @Nullable private final NetworkReference networkReference; - public NetworkBoundItemContext( + public NetworkBoundItemSessionImpl( final Player player, final PlayerSlotReference playerSlotReference, @Nullable final NetworkReference networkReference @@ -34,31 +41,46 @@ public NetworkBoundItemContext( this.networkReference = networkReference; } - public Vec3 getPlayerPosition() { - return playerPosition; + @Override + public Optional resolveNetwork() { + if (networkReference == null) { + return Optional.empty(); + } + return Optional.ofNullable(player.getServer()) + .map(server -> server.getLevel(networkReference.dimensionKey())) + .filter(level -> level.isLoaded(networkReference.pos())) + .map(level -> level.getBlockEntity(networkReference.pos())) + .filter(PlatformNetworkNodeContainer.class::isInstance) + .map(PlatformNetworkNodeContainer.class::cast) + .map(PlatformNetworkNodeContainer::getNode) + .map(NetworkNode::getNetwork) + .filter(this::isInRange); } - public ResourceKey getPlayerLevel() { - return player.level().dimension(); + private boolean isInRange(final Network network) { + return network.getComponent(GraphNetworkComponent.class) + .getContainers(WirelessTransmitter.class) + .stream() + .anyMatch(wirelessTransmitter -> wirelessTransmitter.isInRange( + player.level().dimension(), + playerPosition + )); } + @Override public boolean isActive() { return Platform.INSTANCE.getEnergyStorage(playerSlotReference.resolve(player)) .map(energyStorage -> energyStorage.getStored() > 0) .orElse(true); } - public void drain(final long amount) { + @Override + public void drainEnergy(final long amount) { Platform.INSTANCE.getEnergyStorage(playerSlotReference.resolve(player)).ifPresent( energyStorage -> energyStorage.extract(amount, Action.EXECUTE) ); } - @Nullable - public NetworkReference getNetworkReference() { - return networkReference; - } - public record NetworkReference(ResourceKey dimensionKey, BlockPos pos) { } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/WirelessGridItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/WirelessGridItem.java index 15fd00057..a27de499c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/WirelessGridItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/WirelessGridItem.java @@ -4,6 +4,8 @@ import com.refinedmods.refinedstorage2.api.network.impl.energy.EnergyStorageImpl; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; +import com.refinedmods.refinedstorage2.platform.api.item.AbstractNetworkBoundEnergyItem; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemSession; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; import com.refinedmods.refinedstorage2.platform.common.internal.grid.WirelessGrid; @@ -11,7 +13,6 @@ import java.util.Optional; -import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; @@ -20,11 +21,15 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -public class WirelessGridItem extends AbstractNetworkBoundItem { +public class WirelessGridItem extends AbstractNetworkBoundEnergyItem { private final boolean creative; public WirelessGridItem(final boolean creative) { - super(new Item.Properties().stacksTo(1)); + super( + new Item.Properties().stacksTo(1), + PlatformApi.INSTANCE.getEnergyItemHelper(), + PlatformApi.INSTANCE.getNetworkBoundItemHelper() + ); this.creative = creative; } @@ -32,29 +37,19 @@ public WirelessGridItem(final boolean creative) { public InteractionResultHolder use(final Level level, final Player player, final InteractionHand hand) { final ItemStack stack = player.getItemInHand(hand); if (player instanceof ServerPlayer serverPlayer && level.getServer() != null) { - final PlayerSlotReference slotReference = PlayerSlotReference.of(player, hand); - tryUse( - stack, - serverPlayer, - slotReference, - ctx -> open(level.getServer(), serverPlayer, ctx, slotReference) - ); + final NetworkBoundItemSession session = networkBoundItemHelper.openSession(stack, serverPlayer, hand); + open(serverPlayer, hand, session); } return InteractionResultHolder.consume(stack); } - private void open( - final MinecraftServer server, - final ServerPlayer player, - final NetworkBoundItemContext ctx, - final PlayerSlotReference slotReference - ) { - ctx.drain(Platform.INSTANCE.getConfig().getWirelessGrid().getOpenEnergyUsage()); - final Grid grid = new WirelessGrid(server, ctx); + private void open(final ServerPlayer player, final InteractionHand hand, final NetworkBoundItemSession session) { + session.drainEnergy(Platform.INSTANCE.getConfig().getWirelessGrid().getOpenEnergyUsage()); + final Grid grid = new WirelessGrid(session); Platform.INSTANCE.getMenuOpener().openMenu(player, new WirelessGridExtendedMenuProvider( grid, PlatformApi.INSTANCE.getStorageChannelTypeRegistry(), - slotReference + PlayerSlotReference.of(player, hand) )); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ControllerBlockItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ControllerBlockItem.java index 8bc37651e..c03d60f9d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ControllerBlockItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ControllerBlockItem.java @@ -17,7 +17,6 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -// TODO: Make network bound item api accessible. public class ControllerBlockItem extends AbstractEnergyBlockItem { private final Component name; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/NetworkItemItemPropertyFunction.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/NetworkItemItemPropertyFunction.java index 8d6b046cf..abed03a94 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/NetworkItemItemPropertyFunction.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/NetworkItemItemPropertyFunction.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.render; -import com.refinedmods.refinedstorage2.platform.common.item.AbstractNetworkBoundItem; +import com.refinedmods.refinedstorage2.platform.api.item.AbstractNetworkBoundEnergyItem; import javax.annotation.Nullable; @@ -18,7 +18,7 @@ public float unclampedCall(final ItemStack itemStack, @Nullable final ClientLevel clientLevel, @Nullable final LivingEntity livingEntity, final int i) { - if (itemStack.getItem() instanceof AbstractNetworkBoundItem boundItem) { + if (itemStack.getItem() instanceof AbstractNetworkBoundEnergyItem boundItem) { return boundItem.isBound(itemStack) ? 1 : 0; } return 0;