mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-28 22:05:01 +01:00
Fix toolboxes not giving a comparator output (#6978)
This commit is contained in:
parent
d97f01add8
commit
4abc72a5a2
3 changed files with 27 additions and 11 deletions
|
@ -8,6 +8,7 @@ import com.simibubi.create.AllBlockEntityTypes;
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
import com.simibubi.create.AllShapes;
|
import com.simibubi.create.AllShapes;
|
||||||
import com.simibubi.create.foundation.block.IBE;
|
import com.simibubi.create.foundation.block.IBE;
|
||||||
|
import com.simibubi.create.foundation.item.ItemHelper;
|
||||||
import com.simibubi.create.foundation.utility.BlockHelper;
|
import com.simibubi.create.foundation.utility.BlockHelper;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
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.DyeColor;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
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.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
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.BlockHitResult;
|
||||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
|
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
import net.minecraftforge.common.util.FakePlayer;
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
|
|
||||||
|
@ -171,7 +172,7 @@ public class ToolboxBlock extends HorizontalDirectionalBlock implements SimpleWa
|
||||||
public Class<ToolboxBlockEntity> getBlockEntityClass() {
|
public Class<ToolboxBlockEntity> getBlockEntityClass() {
|
||||||
return ToolboxBlockEntity.class;
|
return ToolboxBlockEntity.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockEntityType<? extends ToolboxBlockEntity> getBlockEntityType() {
|
public BlockEntityType<? extends ToolboxBlockEntity> getBlockEntityType() {
|
||||||
return AllBlockEntityTypes.TOOLBOX.get();
|
return AllBlockEntityTypes.TOOLBOX.get();
|
||||||
|
@ -181,9 +182,14 @@ public class ToolboxBlock extends HorizontalDirectionalBlock implements SimpleWa
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Ingredient getMainBox() {
|
@Override
|
||||||
return Ingredient.of(AllBlocks.TOOLBOXES.get(DyeColor.BROWN)
|
public boolean hasAnalogOutputSignal(BlockState pState) {
|
||||||
.get());
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAnalogOutputSignal(BlockState pState, Level pLevel, BlockPos pPos) {
|
||||||
|
return ItemHelper.calcRedstoneFromBlockEntity(this, pLevel, pPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,11 +159,7 @@ public class ItemVaultBlock extends Block implements IWrenchable, IBE<ItemVaultB
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAnalogOutputSignal(BlockState pState, Level pLevel, BlockPos pPos) {
|
public int getAnalogOutputSignal(BlockState pState, Level pLevel, BlockPos pPos) {
|
||||||
return getBlockEntityOptional(pLevel, pPos)
|
return ItemHelper.calcRedstoneFromBlockEntity(this, pLevel, pPos);
|
||||||
.map(vte -> vte.getCapability(ForgeCapabilities.ITEM_HANDLER))
|
|
||||||
.map(lo -> lo.map(ItemHelper::calcRedstoneFromInventory)
|
|
||||||
.orElse(0))
|
|
||||||
.orElse(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,11 +2,18 @@ package com.simibubi.create.foundation.item;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
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 org.apache.commons.lang3.mutable.MutableInt;
|
||||||
|
|
||||||
import com.simibubi.create.foundation.utility.Pair;
|
import com.simibubi.create.foundation.utility.Pair;
|
||||||
|
@ -26,7 +33,7 @@ public class ItemHelper {
|
||||||
public static boolean sameItem(ItemStack stack, ItemStack otherStack) {
|
public static boolean sameItem(ItemStack stack, ItemStack otherStack) {
|
||||||
return !otherStack.isEmpty() && stack.is(otherStack.getItem());
|
return !otherStack.isEmpty() && stack.is(otherStack.getItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Predicate<ItemStack> sameItemPredicate(ItemStack stack) {
|
public static Predicate<ItemStack> sameItemPredicate(ItemStack stack) {
|
||||||
return s -> sameItem(stack, s);
|
return s -> sameItem(stack, s);
|
||||||
}
|
}
|
||||||
|
@ -73,6 +80,13 @@ public class ItemHelper {
|
||||||
return true;
|
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) {
|
public static int calcRedstoneFromInventory(@Nullable IItemHandler inv) {
|
||||||
if (inv == null)
|
if (inv == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue