mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 07:13:28 +01:00
Add back directionality to the hopping item interface
This commit is contained in:
parent
b8e284d947
commit
bd392b0a5b
2 changed files with 37 additions and 4 deletions
|
@ -12,20 +12,30 @@ package de.ellpeck.actuallyadditions.mod.blocks;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemInterfaceHopping;
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemInterfaceHopping;
|
||||||
import net.minecraft.core.BlockPos;
|
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.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
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.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
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.CollisionContext;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class BlockItemInterfaceHopping extends BlockItemInterface {
|
public class BlockItemInterfaceHopping extends BlockItemInterface {
|
||||||
|
public static final DirectionProperty FACING = BlockStateProperties.FACING_HOPPER;
|
||||||
public BlockItemInterfaceHopping() {
|
public BlockItemInterfaceHopping() {
|
||||||
super();
|
super();
|
||||||
|
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.DOWN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,4 +54,26 @@ public class BlockItemInterfaceHopping extends BlockItemInterface {
|
||||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> entityType) {
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> entityType) {
|
||||||
return level.isClientSide? TileEntityItemInterfaceHopping::clientTick : TileEntityItemInterfaceHopping::serverTick;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
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.minecraft.world.phys.AABB;
|
||||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||||
import net.neoforged.neoforge.items.IItemHandler;
|
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);
|
List<ItemEntity> items = level.getEntities(EntityType.ITEM, axisAlignedBB, EntitySelector.ENTITY_STILL_ALIVE);
|
||||||
if (items != null && !items.isEmpty()) {
|
if (items != null && !items.isEmpty()) {
|
||||||
for (ItemEntity item : items) {
|
for (ItemEntity item : items) {
|
||||||
if (item != null && item.isAlive()) {
|
if (item != null) {
|
||||||
if (ActuallyAdditions.commonCapsLoaded) {
|
if (ActuallyAdditions.commonCapsLoaded) {
|
||||||
Object slotless = tile.itemHandler.getSlotlessHandler();
|
Object slotless = tile.itemHandler.getSlotlessHandler();
|
||||||
// TODO: [port] add back?
|
// TODO: [port] add back?
|
||||||
|
@ -78,11 +79,12 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface {
|
||||||
|
|
||||||
Optional<IItemHandler> handler = Optional.ofNullable(tile.itemHandler.getNormalHandler());
|
Optional<IItemHandler> handler = Optional.ofNullable(tile.itemHandler.getNormalHandler());
|
||||||
handler.ifPresent(cap -> {
|
handler.ifPresent(cap -> {
|
||||||
|
System.out.println(cap.getSlots());
|
||||||
for (int i = 0; i < cap.getSlots(); i++) {
|
for (int i = 0; i < cap.getSlots(); i++) {
|
||||||
ItemStack left = cap.insertItem(i, item.getItem(), false);
|
ItemStack left = cap.insertItem(i, item.getItem(), false);
|
||||||
item.setItem(left);
|
item.setItem(left);
|
||||||
|
|
||||||
if (!StackUtil.isValid(left)) {
|
if (left.isEmpty()) {
|
||||||
item.discard();
|
item.discard();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -125,8 +127,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockState state = this.level.getBlockState(this.getBlockPos());
|
BlockState state = this.level.getBlockState(this.getBlockPos());
|
||||||
//Direction facing = state.getValue(BlockStateProperties.FACING);
|
Direction facing = state.getValue(BlockStateProperties.FACING_HOPPER);
|
||||||
Direction facing = Direction.DOWN; //TODO temp, facing missing
|
|
||||||
|
|
||||||
BlockPos toPos = this.getBlockPos().relative(facing);
|
BlockPos toPos = this.getBlockPos().relative(facing);
|
||||||
if (this.level.isLoaded(toPos)) {
|
if (this.level.isLoaded(toPos)) {
|
||||||
|
|
Loading…
Reference in a new issue