2020-09-09 16:49:01 +02:00
|
|
|
package de.ellpeck.actuallyadditions.common.blocks;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
2020-09-09 16:49:01 +02:00
|
|
|
import de.ellpeck.actuallyadditions.common.blocks.base.BlockContainerBase;
|
|
|
|
import de.ellpeck.actuallyadditions.common.tile.TileEntityBreaker;
|
|
|
|
import de.ellpeck.actuallyadditions.common.tile.TileEntityPlacer;
|
2020-09-08 16:41:52 +02:00
|
|
|
import net.minecraft.block.Block;
|
2020-09-09 17:47:51 +02:00
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.item.BlockItemUseContext;
|
|
|
|
import net.minecraft.state.DirectionProperty;
|
|
|
|
import net.minecraft.state.StateContainer;
|
|
|
|
import net.minecraft.state.properties.BlockStateProperties;
|
2015-04-19 01:50:02 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2020-09-09 17:47:51 +02:00
|
|
|
import net.minecraft.util.*;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-09-09 17:47:51 +02:00
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
|
|
|
import net.minecraft.world.IBlockReader;
|
2015-04-19 01:50:02 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2020-09-09 17:47:51 +02:00
|
|
|
import javax.annotation.Nullable;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
2020-09-09 17:47:51 +02:00
|
|
|
public class BlockBreaker extends BlockContainerBase {
|
|
|
|
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
2016-05-19 20:05:12 +02:00
|
|
|
private final boolean isPlacer;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
2020-09-08 16:41:52 +02:00
|
|
|
public BlockBreaker(boolean isPlacer) {
|
2020-09-09 17:47:51 +02:00
|
|
|
super(STONE_PROPS);
|
2015-04-19 01:50:02 +02:00
|
|
|
this.isPlacer = isPlacer;
|
2020-09-09 17:47:51 +02:00
|
|
|
|
|
|
|
setDefaultState(getStateContainer().getBaseState().with(FACING, Direction.SOUTH));
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
|
2020-09-09 17:47:51 +02:00
|
|
|
@Nullable
|
2015-04-19 01:50:02 +02:00
|
|
|
@Override
|
2020-09-09 17:47:51 +02:00
|
|
|
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
2016-05-14 17:50:10 +02:00
|
|
|
return this.isPlacer ? new TileEntityPlacer() : new TileEntityBreaker();
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-09-09 17:47:51 +02:00
|
|
|
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
|
|
|
if (this.tryToggleRedstone(world, pos, player)) { return ActionResultType.SUCCESS; }
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!world.isRemote) {
|
|
|
|
TileEntityBreaker breaker = (TileEntityBreaker) world.getTileEntity(pos);
|
|
|
|
if (breaker != null) {
|
2020-09-09 17:47:51 +02:00
|
|
|
// todo: come back to this once we have guis
|
|
|
|
// NetworkHooks.openGui(player, new SimpleNamedContainerProvider(());
|
|
|
|
// player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.BREAKER.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
|
2015-10-02 16:48:01 +02:00
|
|
|
}
|
2020-09-09 17:47:51 +02:00
|
|
|
return ActionResultType.SUCCESS;
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
2020-09-09 17:47:51 +02:00
|
|
|
return ActionResultType.SUCCESS;
|
2015-10-23 16:48:56 +02:00
|
|
|
}
|
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
@Override
|
2020-09-09 17:47:51 +02:00
|
|
|
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
|
|
|
super.fillStateContainer(builder);
|
|
|
|
builder.add(FACING);
|
2015-12-19 10:30:39 +01:00
|
|
|
}
|
|
|
|
|
2020-09-09 17:47:51 +02:00
|
|
|
@Nullable
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2020-09-09 17:47:51 +02:00
|
|
|
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
|
|
|
// @todo: might be wrong
|
|
|
|
return getDefaultState().with(FACING, context.getFace().getOpposite());
|
2016-11-21 16:23:48 +01:00
|
|
|
}
|
|
|
|
|
2020-09-09 17:47:51 +02:00
|
|
|
// @Override
|
|
|
|
// public IBlockState withRotation(IBlockState state, Rotation rot) {
|
|
|
|
// return state.withProperty(BlockDirectional.FACING, rot.rotate(state.getValue(BlockDirectional.FACING)));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public IBlockState withMirror(IBlockState state, Mirror mirror) {
|
|
|
|
// return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING)));
|
|
|
|
// }
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|