Fixed off hand handling in block activation

This commit is contained in:
Unknown 2018-01-25 23:55:40 +01:00
parent f74e99c926
commit 8e7b6d235c
23 changed files with 115 additions and 26 deletions

View file

@ -47,6 +47,10 @@ public class BlockLaser extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityLaser) {

View file

@ -65,6 +65,10 @@ public class BlockLaserMedium extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityLaserMedium) {

View file

@ -34,6 +34,10 @@ public class BlockAcceleratorControlPoint extends BlockAbstractAccelerator imple
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (entityPlayer.getHeldItem(EnumHand.MAIN_HAND) == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);

View file

@ -33,6 +33,10 @@ public class BlockAcceleratorController extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (!(tileEntity instanceof TileEntityAcceleratorController)) {
return false;

View file

@ -82,10 +82,14 @@ public class BlockAirGenerator extends BlockAbstractContainer {
@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStackHeld, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote || hand == EnumHand.OFF_HAND) {
if (world.isRemote) {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityAirGenerator) {
TileEntityAirGenerator airGenerator = (TileEntityAirGenerator)tileEntity;

View file

@ -92,10 +92,14 @@ public class BlockAirGeneratorTiered extends BlockAbstractContainer {
@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStackHeld, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote || hand == EnumHand.OFF_HAND) {
if (world.isRemote) {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityAirGenerator) {
TileEntityAirGenerator airGenerator = (TileEntityAirGenerator)tileEntity;

View file

@ -78,6 +78,10 @@ public class BlockShipScanner extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityShipScanner) {

View file

@ -76,6 +76,10 @@ public class BlockLaserTreeFarm extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityLaserTreeFarm) {

View file

@ -76,6 +76,10 @@ public class BlockMiningLaser extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityMiningLaser) {

View file

@ -45,6 +45,10 @@ public class BlockCamera extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityCamera) {

View file

@ -80,6 +80,10 @@ public class BlockCloakingCore extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityCloakingCore) {
TileEntityCloakingCore cloakingCore = (TileEntityCloakingCore) tileEntity;

View file

@ -43,6 +43,10 @@ public class BlockMonitor extends BlockAbstractRotatingContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);

View file

@ -81,6 +81,10 @@ public class BlockRadar extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityRadar) {

View file

@ -157,9 +157,6 @@ public class BlockEnergyBank extends BlockAbstractContainer implements IExplosio
final Item item = Item.getItemFromBlock(this);
ClientProxy.modelInitialisation(item);
// Bind our TESR to our tile entity
// ClientRegistry.bindTileEntitySpecialRenderer(TileEntityForceFieldProjector.class, new TileEntityForceFieldProjectorRenderer());
// register (smart) baked model
for (final EnumDisabledInputOutput enumDisabledInputOutput : CONFIG.getAllowedValues()) {
for (final EnumTier enumTier : BlockProperties.TIER.getAllowedValues()) {
@ -197,11 +194,15 @@ public class BlockEnergyBank extends BlockAbstractContainer implements IExplosio
}
@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStackHeld, EnumFacing facing, float hitX, float hitY, float hitZ) {
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStackHeld, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (!(tileEntity instanceof TileEntityEnergyBank)) {
return false;
@ -216,22 +217,22 @@ public class BlockEnergyBank extends BlockAbstractContainer implements IExplosio
}
final ItemStack itemStack = new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(blockState));
switch (tileEntityEnergyBank.getMode(facing)) {
case INPUT:
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.guide.prefix")
.appendSibling(new TextComponentTranslation(itemStack.getUnlocalizedName() + ".name"))
.appendSibling(new TextComponentTranslation("warpdrive.energy.side.changedToInput", facing.name())) );
return true;
case OUTPUT:
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.guide.prefix")
.appendSibling(new TextComponentTranslation(itemStack.getUnlocalizedName() + ".name"))
.appendSibling(new TextComponentTranslation("warpdrive.energy.side.changedToOutput", facing.name())) );
return true;
case DISABLED:
default:
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.guide.prefix")
.appendSibling(new TextComponentTranslation(itemStack.getUnlocalizedName() + ".name"))
.appendSibling(new TextComponentTranslation("warpdrive.energy.side.changedToDisabled", facing.name())) );
return true;
case INPUT:
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.guide.prefix",
new TextComponentTranslation(itemStack.getUnlocalizedName() + ".name"))
.appendSibling(new TextComponentTranslation("warpdrive.energy.side.changedToInput", facing.name())) );
return true;
case OUTPUT:
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.guide.prefix",
new TextComponentTranslation(itemStack.getUnlocalizedName() + ".name"))
.appendSibling(new TextComponentTranslation("warpdrive.energy.side.changedToOutput", facing.name())) );
return true;
case DISABLED:
default:
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.guide.prefix",
new TextComponentTranslation(itemStack.getUnlocalizedName() + ".name"))
.appendSibling(new TextComponentTranslation("warpdrive.energy.side.changedToDisabled", facing.name())) );
return true;
}
}
@ -266,8 +267,7 @@ public class BlockEnergyBank extends BlockAbstractContainer implements IExplosio
tileEntityEnergyBank.dismountUpgrade(enumComponentType);
// upgrade dismounted
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.upgrade.result.dismounted", enumComponentType.name()));
return false;
return true;
}
} else if (itemStackHeld == null) {// no sneaking and no item in hand => show status
@ -304,6 +304,7 @@ public class BlockEnergyBank extends BlockAbstractContainer implements IExplosio
tileEntityEnergyBank.mountUpgrade(enumComponentType);
// upgrade mounted
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.upgrade.result.mounted", enumComponentType.name()));
return true;
}
return false;

View file

@ -35,13 +35,16 @@ public class BlockIC2reactorLaserMonitor extends BlockAbstractContainer {
return new TileEntityIC2reactorLaserMonitor();
}
@SideOnly(Side.CLIENT)
@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStackHeld, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityIC2reactorLaserMonitor) {

View file

@ -208,6 +208,10 @@ public class BlockForceFieldProjector extends BlockAbstractForceField {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
TileEntity tileEntity = world.getTileEntity(blockPos);
if (!(tileEntity instanceof TileEntityForceFieldProjector)) {
return false;

View file

@ -88,6 +88,10 @@ public class BlockForceFieldRelay extends BlockAbstractForceField {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
TileEntity tileEntity = world.getTileEntity(blockPos);
if (!(tileEntity instanceof TileEntityForceFieldRelay)) {
return false;

View file

@ -70,10 +70,14 @@ public class BlockLift extends BlockAbstractContainer {
@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStackHeld, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote || hand == EnumHand.OFF_HAND) {
if (world.isRemote) {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityLift) {

View file

@ -45,6 +45,10 @@ public class BlockShipController extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityShipController) {

View file

@ -108,6 +108,10 @@ public class BlockShipCore extends BlockAbstractContainer {
@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStackHeld, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityShipCore) {

View file

@ -63,6 +63,10 @@ public class BlockTransporter extends BlockAbstractContainer {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityTransporter) {

View file

@ -44,6 +44,10 @@ public class BlockLaserCamera extends BlockAbstractContainer {
@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStackHeld, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
TileEntity tileEntity = world.getTileEntity(blockPos);
if (!ClientCameraHandler.isOverlayEnabled) {

View file

@ -43,11 +43,16 @@ public class BlockWeaponController extends BlockAbstractContainer {
return 1;
}
@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStackHeld, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return false;
}
if (hand != EnumHand.MAIN_HAND) {
return true;
}
if (itemStackHeld == null) {
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityWeaponController) {