mirror of
https://github.com/TicTicBoooom-Mods/MasterfulMachinery.git
synced 2026-01-18 16:37:23 +01:00
58 lines
2.0 KiB
Java
58 lines
2.0 KiB
Java
package com.ticticboooom.mods.mm.block;
|
|
|
|
import com.ticticboooom.mods.mm.block.tile.ControllerBlockEntity;
|
|
import net.minecraft.block.AbstractBlock;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.tileentity.TileEntityType;
|
|
import net.minecraft.util.ActionResultType;
|
|
import net.minecraft.util.Hand;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
|
import net.minecraft.world.IBlockReader;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.common.ToolType;
|
|
import net.minecraftforge.fml.RegistryObject;
|
|
import net.minecraftforge.fml.network.NetworkHooks;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
public class ControllerBlock extends Block {
|
|
|
|
private RegistryObject<TileEntityType<?>> type;
|
|
|
|
public ControllerBlock(RegistryObject<TileEntityType<?>> type) {
|
|
super(AbstractBlock.Properties.of(Material.METAL)
|
|
.harvestLevel(1)
|
|
.harvestTool(ToolType.PICKAXE));
|
|
this.type = type;
|
|
}
|
|
|
|
@Override
|
|
public boolean hasTileEntity(BlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
|
return type.get().create();
|
|
}
|
|
|
|
@Override
|
|
public ActionResultType use(BlockState state, World level, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult traceResult) {
|
|
if (!level.isClientSide()) {
|
|
TileEntity blockEntity = level.getBlockEntity(pos);
|
|
if (blockEntity instanceof ControllerBlockEntity) {
|
|
NetworkHooks.openGui(((ServerPlayerEntity) player), (ControllerBlockEntity)blockEntity, pos);
|
|
}
|
|
}
|
|
return ActionResultType.SUCCESS;
|
|
}
|
|
}
|