diff --git a/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxBlock.java b/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxBlock.java index 613ae9153..7afa382f6 100644 --- a/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxBlock.java +++ b/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxBlock.java @@ -8,6 +8,7 @@ import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllShapes; import com.simibubi.create.foundation.block.IBE; +import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.utility.BlockHelper; import net.minecraft.core.BlockPos; @@ -22,7 +23,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; @@ -38,6 +38,7 @@ import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.network.NetworkHooks; @@ -171,7 +172,7 @@ public class ToolboxBlock extends HorizontalDirectionalBlock implements SimpleWa public Class getBlockEntityClass() { return ToolboxBlockEntity.class; } - + @Override public BlockEntityType getBlockEntityType() { return AllBlockEntityTypes.TOOLBOX.get(); @@ -181,9 +182,14 @@ public class ToolboxBlock extends HorizontalDirectionalBlock implements SimpleWa return color; } - public static Ingredient getMainBox() { - return Ingredient.of(AllBlocks.TOOLBOXES.get(DyeColor.BROWN) - .get()); + @Override + public boolean hasAnalogOutputSignal(BlockState pState) { + return true; + } + + @Override + public int getAnalogOutputSignal(BlockState pState, Level pLevel, BlockPos pPos) { + return ItemHelper.calcRedstoneFromBlockEntity(this, pLevel, pPos); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/vault/ItemVaultBlock.java b/src/main/java/com/simibubi/create/content/logistics/vault/ItemVaultBlock.java index 7d3fd37a1..d874732a1 100644 --- a/src/main/java/com/simibubi/create/content/logistics/vault/ItemVaultBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/vault/ItemVaultBlock.java @@ -159,11 +159,7 @@ public class ItemVaultBlock extends Block implements IWrenchable, IBE vte.getCapability(ForgeCapabilities.ITEM_HANDLER)) - .map(lo -> lo.map(ItemHelper::calcRedstoneFromInventory) - .orElse(0)) - .orElse(0); + return ItemHelper.calcRedstoneFromBlockEntity(this, pLevel, pPos); } @Override diff --git a/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java b/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java index d4277e265..d4cdb6151 100644 --- a/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java +++ b/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java @@ -2,11 +2,18 @@ package com.simibubi.create.foundation.item; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.function.Function; import java.util.function.Predicate; import javax.annotation.Nullable; +import com.simibubi.create.foundation.block.IBE; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.common.capabilities.ForgeCapabilities; + import org.apache.commons.lang3.mutable.MutableInt; import com.simibubi.create.foundation.utility.Pair; @@ -26,7 +33,7 @@ public class ItemHelper { public static boolean sameItem(ItemStack stack, ItemStack otherStack) { return !otherStack.isEmpty() && stack.is(otherStack.getItem()); } - + public static Predicate sameItemPredicate(ItemStack stack) { return s -> sameItem(stack, s); } @@ -73,6 +80,13 @@ public class ItemHelper { return true; } + public static > int calcRedstoneFromBlockEntity(T ibe, Level level, BlockPos pos) { + return ibe.getBlockEntityOptional(level, pos) + .map(be -> be.getCapability(ForgeCapabilities.ITEM_HANDLER)) + .map(lo -> lo.map(ItemHelper::calcRedstoneFromInventory).orElse(0)) + .orElse(0); + } + public static int calcRedstoneFromInventory(@Nullable IItemHandler inv) { if (inv == null) return 0;