Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.irisya.irisyamod.block;
- import fr.irisya.irisyamod.container.FoundryContainer;
- import fr.irisya.irisyamod.tiles.FoundryTileEntity;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockState;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.entity.player.ServerPlayerEntity;
- import net.minecraft.item.BlockItemUseContext;
- import net.minecraft.state.StateContainer;
- import net.minecraft.state.DirectionProperty;
- import net.minecraft.util.ActionResultType;
- import net.minecraft.util.Direction;
- import net.minecraft.util.Hand;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.network.NetworkHooks;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.text.TranslationTextComponent;
- import net.minecraft.util.text.ITextComponent;
- import net.minecraft.inventory.container.SimpleNamedContainerProvider;
- public class FoundryBlock extends Block {
- public static final DirectionProperty FACING = DirectionProperty.create("facing", Direction.Plane.HORIZONTAL);
- public FoundryBlock(Properties properties) {
- super(properties);
- this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
- }
- @Override
- public BlockState getStateForPlacement(BlockItemUseContext context) {
- return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection());
- }
- @Override
- protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> builder) {
- builder.add(FACING);
- }
- @Override
- public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, net.minecraft.util.math.BlockRayTraceResult result) {
- System.out.println("1");
- if (!world.isClientSide) {
- System.out.println("2");
- if (player.distanceToSqr(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5) <= 5.0) {
- System.out.println("3");
- TileEntity tileEntity = world.getBlockEntity(pos);
- System.out.println("4: " + tileEntity);
- if (tileEntity instanceof FoundryTileEntity) {
- System.out.println("5");
- NetworkHooks.openGui((ServerPlayerEntity) player, new SimpleNamedContainerProvider(
- (windowId, playerInventory, playerEntity) -> new FoundryContainer(windowId, playerInventory, tileEntity),
- getTitle()), pos);
- }
- }
- }
- return ActionResultType.SUCCESS;
- }
- private ITextComponent getTitle() {
- return new TranslationTextComponent("container.foundry");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement