diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterfaceHopping.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterfaceHopping.java index d14ac8a22..cc4b3244c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterfaceHopping.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemInterfaceHopping.java @@ -12,20 +12,30 @@ package de.ellpeck.actuallyadditions.mod.blocks; import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemInterfaceHopping; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import javax.annotation.Nullable; public class BlockItemInterfaceHopping extends BlockItemInterface { + public static final DirectionProperty FACING = BlockStateProperties.FACING_HOPPER; public BlockItemInterfaceHopping() { super(); + this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.DOWN)); } @Override @@ -44,4 +54,26 @@ public class BlockItemInterfaceHopping extends BlockItemInterface { public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType entityType) { return level.isClientSide? TileEntityItemInterfaceHopping::clientTick : TileEntityItemInterfaceHopping::serverTick; } + + @Override + public BlockState getStateForPlacement(BlockPlaceContext pContext) { + Direction direction = pContext.getClickedFace().getOpposite(); + return this.defaultBlockState() + .setValue(FACING, direction.getAxis() == Direction.Axis.Y ? Direction.DOWN : direction); + } + + @Override + public BlockState rotate(BlockState pState, Rotation pRotation) { + return pState.setValue(FACING, pRotation.rotate(pState.getValue(FACING))); + } + + @Override + public BlockState mirror(BlockState pState, Mirror pMirror) { + return pState.rotate(pMirror.getRotation(pState.getValue(FACING))); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder pBuilder) { + pBuilder.add(FACING); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java index c09dec95a..799247186 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java @@ -24,6 +24,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.phys.AABB; import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.items.IItemHandler; @@ -61,7 +62,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface { List items = level.getEntities(EntityType.ITEM, axisAlignedBB, EntitySelector.ENTITY_STILL_ALIVE); if (items != null && !items.isEmpty()) { for (ItemEntity item : items) { - if (item != null && item.isAlive()) { + if (item != null) { if (ActuallyAdditions.commonCapsLoaded) { Object slotless = tile.itemHandler.getSlotlessHandler(); // TODO: [port] add back? @@ -78,11 +79,12 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface { Optional handler = Optional.ofNullable(tile.itemHandler.getNormalHandler()); handler.ifPresent(cap -> { + System.out.println(cap.getSlots()); for (int i = 0; i < cap.getSlots(); i++) { ItemStack left = cap.insertItem(i, item.getItem(), false); item.setItem(left); - if (!StackUtil.isValid(left)) { + if (left.isEmpty()) { item.discard(); break; } @@ -125,8 +127,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface { } BlockState state = this.level.getBlockState(this.getBlockPos()); - //Direction facing = state.getValue(BlockStateProperties.FACING); - Direction facing = Direction.DOWN; //TODO temp, facing missing + Direction facing = state.getValue(BlockStateProperties.FACING_HOPPER); BlockPos toPos = this.getBlockPos().relative(facing); if (this.level.isLoaded(toPos)) {