From 56e975335e0bad7bb1fd3a427b250bf4e478fa34 Mon Sep 17 00:00:00 2001 From: Arthur Uzulin Date: Tue, 8 Oct 2013 21:27:03 +1100 Subject: [PATCH] Prevent breaking of tank air blocks in creative + survival --- src/tconstruct/blocks/TankAirBlock.java | 11 +++++++++-- src/tconstruct/common/TContent.java | 2 +- src/tconstruct/util/TEventHandler.java | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/tconstruct/blocks/TankAirBlock.java b/src/tconstruct/blocks/TankAirBlock.java index 07886351..3bfbf3e6 100644 --- a/src/tconstruct/blocks/TankAirBlock.java +++ b/src/tconstruct/blocks/TankAirBlock.java @@ -1,11 +1,12 @@ package tconstruct.blocks; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import cpw.mods.fml.relauncher.*; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import tconstruct.blocks.logic.TankAirLogic; import tconstruct.client.block.TankAirRender; @@ -47,4 +48,10 @@ public class TankAirBlock extends BlockContainer { return false; } + + @Override + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) + { + return null; + } } diff --git a/src/tconstruct/common/TContent.java b/src/tconstruct/common/TContent.java index a5b98d4e..21525f35 100644 --- a/src/tconstruct/common/TContent.java +++ b/src/tconstruct/common/TContent.java @@ -405,7 +405,7 @@ public class TContent implements IFuelHandler GameRegistry.registerBlock(castingChannel, CastingChannelItem.class, "CastingChannel"); GameRegistry.registerTileEntity(CastingChannelLogic.class, "CastingChannel"); - tankAir = new TankAirBlock(PHConstruct.airTank, Material.air).setUnlocalizedName("tconstruct.tank.air"); + tankAir = new TankAirBlock(PHConstruct.airTank, Material.air).setBlockUnbreakable().setUnlocalizedName("tconstruct.tank.air"); GameRegistry.registerBlock(tankAir, "TankAir"); GameRegistry.registerTileEntity(TankAirLogic.class, "tconstruct.tank.air"); diff --git a/src/tconstruct/util/TEventHandler.java b/src/tconstruct/util/TEventHandler.java index df3cf44d..bd0d27e1 100644 --- a/src/tconstruct/util/TEventHandler.java +++ b/src/tconstruct/util/TEventHandler.java @@ -1,5 +1,11 @@ package tconstruct.util; +import tconstruct.blocks.TankAirBlock; + +import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; + +import net.minecraftforge.event.entity.player.PlayerInteractEvent; + import net.minecraft.block.Block; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -1554,4 +1560,15 @@ public class TEventHandler } } + //Player interact event - prevent breaking of tank air blocks in creative + @ForgeSubscribe + public void playerInteract(PlayerInteractEvent event){ + if(event.action == Action.LEFT_CLICK_BLOCK){ + Block block = Block.blocksList[event.entity.worldObj.getBlockId(event.x, event.y, event.z)]; + if(block instanceof TankAirBlock){ + event.setCanceled(true); + } + } + } + }