Add back directionality to the hopping item interface

This commit is contained in:
Mrbysco 2024-03-13 00:28:41 +01:00
parent b8e284d947
commit bd392b0a5b
2 changed files with 37 additions and 4 deletions

View file

@ -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 <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> 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<Block, BlockState> pBuilder) {
pBuilder.add(FACING);
}
}

View file

@ -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<ItemEntity> 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<IItemHandler> 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)) {