Update BlockKeyboardRight.java

This commit is contained in:
Mysticpasta1 2022-06-21 17:10:48 -05:00
parent d35c9c23a6
commit ffa8996f74

View File

@ -4,25 +4,18 @@
package net.montoyo.wd.block; package net.montoyo.wd.block;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.EnumPushReaction; import net.minecraft.world.entity.Entity;
import net.minecraft.block.material.Material; import net.minecraft.world.entity.player.Player;
import net.minecraft.block.properties.IProperty; import net.minecraft.world.item.ItemStack;
import net.minecraft.block.properties.PropertyInteger; import net.minecraft.world.level.BlockGetter;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.world.level.Explosion;
import net.minecraft.block.state.IBlockState; import net.minecraft.world.level.Level;
import net.minecraft.entity.Entity; import net.minecraft.world.level.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.item.ItemStack; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.material.Material;
import net.minecraft.util.EnumFacing; import net.minecraft.world.phys.AABB;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.core.DefaultPeripheral; import net.montoyo.wd.core.DefaultPeripheral;
import net.montoyo.wd.core.IPeripheral; import net.montoyo.wd.core.IPeripheral;
@ -36,17 +29,14 @@ import java.util.Random;
public class BlockKeyboardRight extends Block implements IPeripheral { public class BlockKeyboardRight extends Block implements IPeripheral {
public static final PropertyInteger facing = PropertyInteger.create("facing", 0, 3); public static final IntegerProperty facing = IntegerProperty.create("facing", 0, 3);
private static final IProperty[] properties = new IProperty[] { facing }; public static final AABB KEYBOARD_AABB = new AABB(0.0, 0.0, 0.0, 1.0, 1.0 / 16.0, 1.0);
public static final AxisAlignedBB KEYBOARD_AABB = new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0 / 16.0, 1.0);
public BlockKeyboardRight() { public BlockKeyboardRight() {
super(Material.ROCK); super(Properties.of(Material.STONE)
setHardness(1.5f); .strength(1.5f, 10.f));
setResistance(10.f); //("keyboard")
setUnlocalizedName("webdisplays.peripheral.keyboard"); //fullBlock = false;
setRegistryName("keyboard");
fullBlock = false;
} }
@Override @Override
@ -61,54 +51,54 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
} }
@Override @Override
public boolean isFullCube(IBlockState state) { public boolean isFullCube(BlockState state) {
return false; return false;
} }
@Override @Override
public boolean isFullBlock(IBlockState state) { public boolean isFullBlock(BlockState state) {
return false; return false;
} }
@Override @Override
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) { public boolean isNormalCube(BlockState state, BlockGetter world, BlockPos pos) {
return false; return false;
} }
@Override @Override
public boolean isOpaqueCube(IBlockState state) { public boolean isOpaqueCube(BlockState state) {
return false; return false;
} }
@Override @Override
public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face) { public boolean doesSideBlockRendering(BlockState state, BlockGetter world, BlockPos pos, EnumFacing face) {
return false; return false;
} }
@Override @Override
@Nonnull @Nonnull
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { public AABB getBoundingBox(BlockState state, IBlockAccess source, BlockPos pos) {
return KEYBOARD_AABB; return KEYBOARD_AABB;
} }
@Override @Override
@Nonnull @Nonnull
public IBlockState getStateFromMeta(int meta) { public BlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(facing, meta); return getDefaultState().withProperty(facing, meta);
} }
@Override @Override
public int getMetaFromState(IBlockState state) { public int getMetaFromState(BlockState state) {
return state.getValue(facing); return state.getValue(facing);
} }
@Override @Override
@Nonnull @Nonnull
public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player) { public ItemStack getPickBlock(@Nonnull BlockState state, RayTraceResult target, @Nonnull Level world, @Nonnull BlockPos pos, EntityPlayer player) {
return new ItemStack(WebDisplays.INSTANCE.blockPeripheral, 1, 0); return new ItemStack(WebDisplays.INSTANCE.blockPeripheral, 1, 0);
} }
private TileEntityKeyboard getTileEntity(World world, BlockPos pos) { private TileEntityKeyboard getTileEntity(Level world, BlockPos pos) {
for(EnumFacing nf: EnumFacing.HORIZONTALS) { for(EnumFacing nf: EnumFacing.HORIZONTALS) {
BlockPos np = pos.add(nf.getDirectionVec()); BlockPos np = pos.add(nf.getDirectionVec());
IBlockState ns = world.getBlockState(np); IBlockState ns = world.getBlockState(np);
@ -126,14 +116,14 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
} }
@Override @Override
public boolean connect(World world, BlockPos pos, IBlockState state, Vector3i scrPos, BlockSide scrSide) { public boolean connect(Level world, BlockPos pos, BlockState state, Vector3i scrPos, BlockSide scrSide) {
TileEntityKeyboard keyboard = getTileEntity(world, pos); TileEntityKeyboard keyboard = getTileEntity(world, pos);
return keyboard != null && keyboard.connect(world, pos, state, scrPos, scrSide); return keyboard != null && keyboard.connect(world, pos, state, scrPos, scrSide);
} }
@Override @Override
@Nonnull @Nonnull
public EnumPushReaction getMobilityFlag(IBlockState state) { public EnumPushReaction getMobilityFlag(BlockState state) {
return EnumPushReaction.IGNORE; return EnumPushReaction.IGNORE;
} }
@ -155,10 +145,10 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
return true; return true;
} }
public void removeLeftPiece(World world, BlockPos pos, boolean dropItem) { public void removeLeftPiece(Level world, BlockPos pos, boolean dropItem) {
for(EnumFacing nf: EnumFacing.HORIZONTALS) { for(EnumFacing nf: EnumFacing.HORIZONTALS) {
BlockPos np = pos.add(nf.getDirectionVec()); BlockPos np = pos.add(nf.getDirectionVec());
IBlockState ns = world.getBlockState(np); BlockState ns = world.getBlockState(np);
if(ns.getBlock() instanceof BlockPeripheral && ns.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) { if(ns.getBlock() instanceof BlockPeripheral && ns.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) {
if(dropItem) if(dropItem)
@ -171,8 +161,8 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
} }
@Override @Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block neighborType, BlockPos neighbor) { public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor) {
if(world.isRemote) if(world.isClientSide)
return; return;
if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isAirBlock(neighbor)) { if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isAirBlock(neighbor)) {
@ -182,23 +172,23 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
} }
@Override @Override
public boolean removedByPlayer(@Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer ply, boolean willHarvest) { public boolean removedByPlayer(@Nonnull BlockState state, Level world, @Nonnull BlockPos pos, @Nonnull Player ply, boolean willHarvest) {
if(!world.isRemote) if(!world.isClientSide)
removeLeftPiece(world, pos, !ply.isCreative()); removeLeftPiece(world, pos, !ply.isCreative());
return super.removedByPlayer(state, world, pos, ply, willHarvest); return super.removedByPlayer(state, world, pos, ply, willHarvest);
} }
@Override @Override
public void onBlockDestroyedByExplosion(World world, BlockPos pos, Explosion explosionIn) { public void onBlockDestroyedByExplosion(Level world, BlockPos pos, Explosion explosionIn) {
if(!world.isRemote) if(!world.isClientSide)
removeLeftPiece(world, pos, true); removeLeftPiece(world, pos, true);
} }
@Override @Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) { public void onEntityCollidedWithBlock(Level world, BlockPos pos, BlockState state, Entity entity) {
double rpos = (entity.posY - ((double) pos.getY())) * 16.0; double rpos = (entity.getY() - ((double) pos.getY())) * 16.0;
if(!world.isRemote && rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) { if(!world.isClientSide && rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) {
TileEntityKeyboard tek = getTileEntity(world, pos); TileEntityKeyboard tek = getTileEntity(world, pos);
if(tek != null) if(tek != null)
@ -207,7 +197,7 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
} }
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { public boolean onBlockActivated(Level world, BlockPos pos, BlockState state, Player player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if(player.isSneaking()) if(player.isSneaking())
return false; return false;