mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-05-18 23:51:23 +02:00
80 lines
3.1 KiB
Java
80 lines
3.1 KiB
Java
/*
|
|
* This file ("BlockItemViewerHopping.java") is part of the Actually Additions mod for Minecraft.
|
|
* It is created and owned by Ellpeck and distributed
|
|
* under the Actually Additions License to be found at
|
|
* http://ellpeck.de/actaddlicense
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
*
|
|
* © 2015-2017 Ellpeck
|
|
*/
|
|
|
|
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
|
|
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
|
return VoxelShapes.HOPPING_ITEM_VIEWER_SHAPE;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
return new TileEntityItemInterfaceHopping(pos, state);
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
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);
|
|
}
|
|
}
|