Fix toolboxes not giving a comparator output (#6978)

This commit is contained in:
IThundxr 2025-01-10 12:01:24 -05:00 committed by GitHub
parent d97f01add8
commit 4abc72a5a2
Failed to generate hash of commit
3 changed files with 27 additions and 11 deletions

View file

@ -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<ToolboxBlockEntity> getBlockEntityClass() {
return ToolboxBlockEntity.class;
}
@Override
public BlockEntityType<? extends ToolboxBlockEntity> 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);
}
}

View file

@ -159,11 +159,7 @@ public class ItemVaultBlock extends Block implements IWrenchable, IBE<ItemVaultB
@Override
public int getAnalogOutputSignal(BlockState pState, Level pLevel, BlockPos pPos) {
return getBlockEntityOptional(pLevel, pPos)
.map(vte -> vte.getCapability(ForgeCapabilities.ITEM_HANDLER))
.map(lo -> lo.map(ItemHelper::calcRedstoneFromInventory)
.orElse(0))
.orElse(0);
return ItemHelper.calcRedstoneFromBlockEntity(this, pLevel, pPos);
}
@Override

View file

@ -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<ItemStack> sameItemPredicate(ItemStack stack) {
return s -> sameItem(stack, s);
}
@ -73,6 +80,13 @@ public class ItemHelper {
return true;
}
public static <T extends IBE<? extends BlockEntity>> 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;