use of gregapi.block.prefixblock.PrefixBlockTileEntity in project gregtech6 by GregTech6.
the class GT_API_Proxy method onPlayerInteraction.
@SubscribeEvent
public void onPlayerInteraction(PlayerInteractEvent aEvent) {
if (aEvent.entityPlayer == null || aEvent.entityPlayer.worldObj == null || aEvent.action == null || aEvent.world.provider == null)
return;
PLAYER_LAST_CLICKED.put(aEvent.entityPlayer, new ChunkCoordinates(aEvent.x, aEvent.y, aEvent.z));
ItemStack aStack = aEvent.entityPlayer.inventory.getCurrentItem();
Block aBlock = WD.block(aEvent.world, aEvent.x, aEvent.y, aEvent.z);
TileEntity aTileEntity = aEvent.world.getTileEntity(aEvent.x, aEvent.y, aEvent.z);
if (aEvent.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
// Fixing a Vanilla Dupe Bug with stacked Music Discs and the Jukebox.
if (aTileEntity instanceof TileEntityJukebox) {
ItemStack tStack = ((TileEntityJukebox) aTileEntity).func_145856_a();
if (tStack != null)
tStack.stackSize = 1;
return;
}
// You can easily recycle most things in GT6 anyways, so this should not be needed.
if (IL.TF_Uncrafting.equal(aBlock)) {
UT.Entities.chat(aEvent.entityPlayer, CHAT_GREG + "No cheating! ;)");
aEvent.setCanceled(T);
return;
}
// Just rightclick the Trophy to get the Achievement/Progress.
if (IL.TF_Trophy.equal(aBlock)) {
UT.Inventories.checkAchievements(aEvent.entityPlayer, ST.make(aBlock.getItemDropped(0, RNGSUS, 0), 1, aBlock.getDamageValue(aEvent.world, aEvent.x, aEvent.y, aEvent.z)));
return;
}
// Some Clientside Only Stuff.
if (aEvent.entityPlayer.worldObj.isRemote && !aEvent.entityPlayer.isSneaking()) {
if (aTileEntity instanceof PrefixBlockTileEntity) {
// Show uses for Bedrock Ore when clicking it.
if (aBlock == BlocksGT.oreBedrock || aBlock == BlocksGT.oreSmallBedrock) {
RM.BedrockOreList.openNEI();
// RM.BedrockOreList.guiUsesNEI(ST.make((Block)BlocksGT.oreBedrock, 1, ((PrefixBlockTileEntity)aTileEntity).mMetaData));
}
}
}
if (ST.valid(aStack)) {
// Preventing a Railcraft Crash with Fluid Container Items.
if (aStack.getItem() instanceof IFluidContainerItem && !aEvent.entityPlayer.isSneaking() && aTileEntity != null && aTileEntity.getClass().getName().startsWith("mods.railcraft.common")) {
aEvent.setCanceled(T);
return;
}
/* I think this was for fixing some Adventure Mode related thing. Probably placing Scaffolds with Leftclick was broken, but I ended up fixing it another way.
if (MD.IC2.mLoaded && SIDES_HORIZONTAL[aEvent.face] && !aEvent.entityPlayer.isSneaking() && !aEvent.entityPlayer.capabilities.allowEdit && !aEvent.world.canPlaceEntityOnSide(aBlock, aEvent.x+OFFSETS_X[aEvent.face], aEvent.y, aEvent.z+OFFSETS_Z[aEvent.face], F, aEvent.face, aEvent.entityPlayer, aStack)) {
if (IL.IC2_Scaffold.equal(aBlock) && IL.IC2_Scaffold.equal(aStack, F, T)) {
aBlock.onBlockClicked(aEvent.world, aEvent.x, aEvent.y, aEvent.z, aEvent.entityPlayer);
aEvent.entityPlayer.swingItem();
aEvent.setCanceled(T);
return;
}
if (IL.IC2_Scaffold_Iron.equal(aBlock) && IL.IC2_Scaffold_Iron.equal(aStack, F, T)) {
aBlock.onBlockClicked(aEvent.world, aEvent.x, aEvent.y, aEvent.z, aEvent.entityPlayer);
aEvent.entityPlayer.swingItem();
aEvent.setCanceled(T);
return;
}
}*/
if (!(aStack.getItem() instanceof IItemNoGTOverride)) {
// Dollies won't work on GT6 TileEntities, so to prevent a Crash and deleted Resources, I just disable the interaction.
if (IL.JABBA_Dolly.equal(aStack, T, T) || IL.JABBA_Dolly_Diamond.equal(aStack, T, T)) {
if (aTileEntity instanceof ITileEntitySpecificPlacementBehavior) {
UT.Entities.chat(aEvent.entityPlayer, CHAT_GREG + "The Dolly Code is sadly not smart enough to move this TileEntity.", CHAT_GREG + "It would crash if it actually did, so be glad I prevented that mistake.", CHAT_GREG + "Would be great if it did work though...");
aEvent.setCanceled(T);
}
return;
}
// Instant breaking for those Wrenches.
if (IL.BC_Wrench.equal(aStack, T, T) || IL.FR_Wrench.equal(aStack, T, T) || IL.SC2_Wrench.equal(aStack, T, T) || IL.AE_Wrench_Certus.equal(aStack, T, T) || IL.AE_Wrench_Quartz.equal(aStack, T, T) || IL.TE_Wrench.equal(aStack, T, T) || IL.TE_Wrench_Battle.equal(aStack, T, T)) {
List<String> tChatReturn = new ArrayListNoNulls<>();
long tDamage = IBlockToolable.Util.onToolClickWithoutCompat(TOOL_wrench, Long.MAX_VALUE, 3, aEvent.entityPlayer, tChatReturn, aEvent.entityPlayer.inventory, aEvent.entityPlayer.isSneaking(), aStack, aEvent.entityPlayer.worldObj, (byte) aEvent.face, aEvent.x, aEvent.y, aEvent.z, 0.5F, 0.5F, 0.5F);
UT.Entities.sendchat(aEvent.entityPlayer, tChatReturn, F);
if (tDamage > 0) {
ST.use(aEvent.entityPlayer, aStack);
UT.Sounds.send(aEvent.world, SFX.MC_BREAK, 1.0F, 1.0F, aEvent.x, aEvent.y, aEvent.z);
aEvent.setCanceled(T);
}
return;
}
// Instant breaking for those Soft Hammers.
if (IL.MFR_Hammer.equal(aStack, T, T)) {
List<String> tChatReturn = new ArrayListNoNulls<>();
long tDamage = IBlockToolable.Util.onToolClickWithoutCompat(TOOL_softhammer, Long.MAX_VALUE, 3, aEvent.entityPlayer, tChatReturn, aEvent.entityPlayer.inventory, aEvent.entityPlayer.isSneaking(), aStack, aEvent.entityPlayer.worldObj, (byte) aEvent.face, aEvent.x, aEvent.y, aEvent.z, 0.5F, 0.5F, 0.5F);
UT.Entities.sendchat(aEvent.entityPlayer, tChatReturn, F);
if (tDamage > 0) {
ST.use(aEvent.entityPlayer, aStack);
UT.Sounds.send(aEvent.world, SFX.MC_BREAK, 1.0F, 1.0F, aEvent.x, aEvent.y, aEvent.z);
aEvent.setCanceled(T);
}
return;
}
// Instant breaking for those Hard Hammers.
if (IL.IE_Hammer.equal(aStack, F, T) || IL.A97_Hammer.equal(aStack, T, T) || IL.SC2_Hammer.equal(aStack, T, T) || IL.SC2_Hammer_Gilded.equal(aStack, T, T)) {
List<String> tChatReturn = new ArrayListNoNulls<>();
long tDamage = IBlockToolable.Util.onToolClickWithoutCompat(TOOL_hammer, Long.MAX_VALUE, 3, aEvent.entityPlayer, tChatReturn, aEvent.entityPlayer.inventory, aEvent.entityPlayer.isSneaking(), aStack, aEvent.entityPlayer.worldObj, (byte) aEvent.face, aEvent.x, aEvent.y, aEvent.z, 0.5F, 0.5F, 0.5F);
UT.Entities.sendchat(aEvent.entityPlayer, tChatReturn, F);
if (tDamage > 0) {
ST.use(aEvent.entityPlayer, aStack);
UT.Sounds.send(aEvent.world, SFX.MC_BREAK, 1.0F, 1.0F, aEvent.x, aEvent.y, aEvent.z);
aEvent.setCanceled(T);
}
return;
}
// Make Railcrafts Crowbars work on GT6 Stuff.
if (IL.RC_Crowbar_Iron.equal(aStack, T, T) || IL.RC_Crowbar_Steel.equal(aStack, T, T) || IL.RC_Crowbar_Thaumium.equal(aStack, T, T) || IL.RC_Crowbar_Voidmetal.equal(aStack, T, T)) {
List<String> tChatReturn = new ArrayListNoNulls<>();
long tDamage = IBlockToolable.Util.onToolClickWithoutCompat(TOOL_crowbar, Long.MAX_VALUE, 2, aEvent.entityPlayer, tChatReturn, aEvent.entityPlayer.inventory, aEvent.entityPlayer.isSneaking(), aStack, aEvent.entityPlayer.worldObj, (byte) aEvent.face, aEvent.x, aEvent.y, aEvent.z, 0.5F, 0.5F, 0.5F);
UT.Entities.sendchat(aEvent.entityPlayer, tChatReturn, F);
if (tDamage > 0) {
aStack.damageItem((int) UT.Code.units(tDamage, 10000, 1, T), aEvent.entityPlayer);
if (aStack.getItemDamage() >= aStack.getMaxDamage())
ST.use(aEvent.entityPlayer, aStack);
aEvent.setCanceled(T);
}
return;
}
// Make Forestry Scoops work on GT6 Stuff.
if (IL.FR_Scoop.equal(aStack, T, T)) {
List<String> tChatReturn = new ArrayListNoNulls<>();
long tDamage = IBlockToolable.Util.onToolClickWithoutCompat(TOOL_scoop, Long.MAX_VALUE, 0, aEvent.entityPlayer, tChatReturn, aEvent.entityPlayer.inventory, aEvent.entityPlayer.isSneaking(), aStack, aEvent.world, (byte) aEvent.face, aEvent.x, aEvent.y, aEvent.z, 0.5F, 0.5F, 0.5F);
UT.Entities.sendchat(aEvent.entityPlayer, tChatReturn, F);
if (tDamage > 0) {
aStack.damageItem((int) UT.Code.units(tDamage, 10000, 1, T), aEvent.entityPlayer);
if (aStack.getItemDamage() >= aStack.getMaxDamage())
ST.use(aEvent.entityPlayer, aStack);
aEvent.setCanceled(T);
}
return;
}
// Make Railcrafts Firestone work as Flint and Steel on TNT and GT6 Machines
if (IL.RC_Firestone_Refined.equal(aStack, T, T) || IL.RC_Firestone_Cracked.equal(aStack, T, T)) {
List<String> tChatReturn = new ArrayListNoNulls<>();
long tDamage = IBlockToolable.Util.onToolClickWithoutCompat(TOOL_igniter, Long.MAX_VALUE, Long.MAX_VALUE, aEvent.entityPlayer, tChatReturn, aEvent.entityPlayer.inventory, aEvent.entityPlayer.isSneaking(), aStack, aEvent.world, (byte) aEvent.face, aEvent.x, aEvent.y, aEvent.z, 0.5F, 0.5F, 0.5F);
UT.Entities.sendchat(aEvent.entityPlayer, tChatReturn, F);
if (tDamage > 0) {
aStack.damageItem((int) UT.Code.units(tDamage, 10000, 1, T), aEvent.entityPlayer);
if (aStack.getItemDamage() >= aStack.getMaxDamage())
ST.use(aEvent.entityPlayer, aStack);
UT.Sounds.send(aEvent.world, SFX.MC_IGNITE, 1.0F, 1.0F, aEvent.x, aEvent.y, aEvent.z);
aEvent.setCanceled(T);
}
return;
}
// Make Twilight Forests Lamp of Cinders work as infinite Flint and Steel on TNT and GT6 Machines. Should be a good reward for getting to it.
if (IL.TF_Lamp_of_Cinders.equal(aStack, T, T)) {
List<String> tChatReturn = new ArrayListNoNulls<>();
long tDamage = IBlockToolable.Util.onToolClick(TOOL_igniter, Long.MAX_VALUE, Long.MAX_VALUE, aEvent.entityPlayer, tChatReturn, aEvent.entityPlayer.inventory, aEvent.entityPlayer.isSneaking(), aStack, aEvent.world, (byte) aEvent.face, aEvent.x, aEvent.y, aEvent.z, 0.5F, 0.5F, 0.5F);
UT.Entities.sendchat(aEvent.entityPlayer, tChatReturn, F);
if (tDamage > 0)
aEvent.setCanceled(T);
return;
}
if (IL.TF_Transformation_Powder.equal(aStack, T, T)) {
// Make Twilight Forests Transformation Powder work on Mob Spawners
if (aTileEntity instanceof TileEntityMobSpawner) {
if (aEvent.world.isRemote)
return;
MobSpawnerBaseLogic tSpawner = ((TileEntityMobSpawner) aTileEntity).func_145881_a();
String tResult = TRANSFORMATION_POWDER_SPAWNER_MAP.get(tSpawner.getEntityNameToSpawn());
if (UT.Code.stringValid(tResult)) {
if (ST.use(aEvent.entityPlayer, aStack, 16)) {
tSpawner.setEntityName(tResult);
// I hope this works sync the new Mob Data over.
aEvent.world.markBlockForUpdate(aEvent.x, aEvent.y, aEvent.z);
} else {
UT.Entities.sendchat(aEvent.entityPlayer, "You need 16 Bags of Transformation Powder to convert this!");
}
} else {
UT.Entities.sendchat(aEvent.entityPlayer, "This Spawner does not have a Counterpart to convert into!");
}
aEvent.setCanceled(T);
return;
}
}
}
}
}
// Make sure that shelvable Items don't do a Rightclick Action instead of being shelved.
if (aEvent.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK || aEvent.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR) {
if (ST.valid(aStack)) {
if (aTileEntity instanceof ITileEntityBookShelf && ((ITileEntityBookShelf) aTileEntity).isShelfFace((byte) aEvent.face)) {
aEvent.useBlock = Result.ALLOW;
if (BooksGT.BOOK_REGISTER.containsKey(aStack, T))
aEvent.useItem = Result.DENY;
return;
}
}
}
}
Aggregations