Skip to content

Commit

Permalink
Fix toolboxes not giving a comparator output (#6978)
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr authored Jan 10, 2025
1 parent d97f01a commit 4abc72a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand All @@ -22,7 +23,6 @@
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;
Expand All @@ -38,6 +38,7 @@
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;

Expand Down Expand Up @@ -171,7 +172,7 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
public Class<ToolboxBlockEntity> getBlockEntityClass() {
return ToolboxBlockEntity.class;
}

@Override
public BlockEntityType<? extends ToolboxBlockEntity> getBlockEntityType() {
return AllBlockEntityTypes.TOOLBOX.get();
Expand All @@ -181,9 +182,14 @@ public DyeColor getColor() {
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ public boolean hasAnalogOutputSignal(BlockState p_149740_1_) {

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -73,6 +80,13 @@ public static boolean isSameInventory(IItemHandler h1, IItemHandler h2) {
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;
Expand Down

0 comments on commit 4abc72a

Please sign in to comment.