2012-08-06 02:15:13 +00:00
|
|
|
package net.minecraftforge.common;
|
|
|
|
|
2013-06-30 12:50:11 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2013-12-13 07:32:36 +00:00
|
|
|
import java.util.Set;
|
2013-12-17 01:18:48 +00:00
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
2013-12-13 07:32:36 +00:00
|
|
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
2012-12-13 07:27:57 +00:00
|
|
|
import net.minecraft.block.Block;
|
2013-06-30 12:50:11 +00:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2012-12-13 07:27:57 +00:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-10-09 00:00:02 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2013-12-13 07:32:36 +00:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.init.Items;
|
2013-10-09 00:00:02 +00:00
|
|
|
import net.minecraft.inventory.Container;
|
2014-04-03 01:33:13 +00:00
|
|
|
import net.minecraft.inventory.ContainerRepair;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
2012-12-13 07:27:57 +00:00
|
|
|
import net.minecraft.item.ItemArmor;
|
|
|
|
import net.minecraft.item.ItemAxe;
|
|
|
|
import net.minecraft.item.ItemPickaxe;
|
|
|
|
import net.minecraft.item.ItemSpade;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-10-09 00:00:02 +00:00
|
|
|
import net.minecraft.item.ItemSword;
|
2013-12-21 08:10:35 +00:00
|
|
|
import net.minecraft.network.NetHandlerPlayServer;
|
2013-12-13 07:32:36 +00:00
|
|
|
import net.minecraft.network.Packet;
|
2013-12-21 08:10:35 +00:00
|
|
|
import net.minecraft.network.play.server.S23PacketBlockChange;
|
2013-10-09 00:00:02 +00:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2013-08-11 02:39:06 +00:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2013-12-21 08:10:35 +00:00
|
|
|
import net.minecraft.util.ChatComponentTranslation;
|
2012-12-13 07:27:57 +00:00
|
|
|
import net.minecraft.util.DamageSource;
|
2013-08-11 02:39:06 +00:00
|
|
|
import net.minecraft.util.MathHelper;
|
2012-12-13 07:27:57 +00:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
2013-12-21 08:10:35 +00:00
|
|
|
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
2012-12-13 07:27:57 +00:00
|
|
|
import net.minecraft.util.WeightedRandom;
|
|
|
|
import net.minecraft.world.World;
|
2013-12-21 08:10:35 +00:00
|
|
|
import net.minecraft.world.WorldSettings.GameType;
|
2014-04-03 01:33:13 +00:00
|
|
|
import net.minecraftforge.event.AnvilUpdateEvent;
|
2013-06-30 12:50:11 +00:00
|
|
|
import net.minecraftforge.event.ServerChatEvent;
|
2012-09-11 22:27:34 +00:00
|
|
|
import net.minecraftforge.event.entity.item.ItemTossEvent;
|
2013-06-30 12:50:11 +00:00
|
|
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingFallEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
|
2013-10-05 11:10:00 +00:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerOpenContainerEvent;
|
2013-10-09 00:00:02 +00:00
|
|
|
import net.minecraftforge.event.world.BlockEvent;
|
2013-12-21 08:10:35 +00:00
|
|
|
import static net.minecraft.init.Blocks.*;
|
2012-08-06 02:15:13 +00:00
|
|
|
|
|
|
|
public class ForgeHooks
|
|
|
|
{
|
2013-12-13 07:32:36 +00:00
|
|
|
static class SeedEntry extends WeightedRandom.Item
|
2012-08-06 02:15:13 +00:00
|
|
|
{
|
|
|
|
public final ItemStack seed;
|
|
|
|
public SeedEntry(ItemStack seed, int weight)
|
|
|
|
{
|
|
|
|
super(weight);
|
|
|
|
this.seed = seed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static final List<SeedEntry> seedList = new ArrayList<SeedEntry>();
|
2012-09-09 14:02:21 +00:00
|
|
|
|
2012-08-06 02:41:18 +00:00
|
|
|
public static ItemStack getGrassSeed(World world)
|
|
|
|
{
|
|
|
|
SeedEntry entry = (SeedEntry)WeightedRandom.getRandomItem(world.rand, seedList);
|
|
|
|
if (entry == null || entry.seed == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return entry.seed.copy();
|
|
|
|
}
|
2012-09-09 14:02:21 +00:00
|
|
|
|
2012-08-06 10:35:57 +00:00
|
|
|
private static boolean toolInit = false;
|
2013-12-24 04:34:39 +00:00
|
|
|
//static HashSet<List> toolEffectiveness = new HashSet<List>();
|
2012-09-09 14:02:21 +00:00
|
|
|
|
2012-08-06 10:35:57 +00:00
|
|
|
public static boolean canHarvestBlock(Block block, EntityPlayer player, int metadata)
|
|
|
|
{
|
2014-02-05 08:05:37 +00:00
|
|
|
if (block.getMaterial().isToolNotRequired())
|
2012-08-06 10:35:57 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-11 21:45:48 +00:00
|
|
|
|
2012-08-06 10:35:57 +00:00
|
|
|
ItemStack stack = player.inventory.getCurrentItem();
|
2013-12-21 08:10:35 +00:00
|
|
|
String tool = block.getHarvestTool(metadata);
|
|
|
|
if (stack == null || tool == null)
|
2012-08-06 10:35:57 +00:00
|
|
|
{
|
2014-02-05 08:05:37 +00:00
|
|
|
return player.canHarvestBlock(block);
|
2012-08-06 10:35:57 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 08:10:35 +00:00
|
|
|
int toolLevel = stack.getItem().getHarvestLevel(stack, tool);
|
|
|
|
if (toolLevel < 0)
|
2012-08-06 10:35:57 +00:00
|
|
|
{
|
2014-02-05 08:05:37 +00:00
|
|
|
return player.canHarvestBlock(block);
|
2012-08-06 10:35:57 +00:00
|
|
|
}
|
2012-08-11 21:45:48 +00:00
|
|
|
|
2013-12-21 08:10:35 +00:00
|
|
|
return toolLevel >= block.getHarvestLevel(metadata);
|
2012-08-06 10:35:57 +00:00
|
|
|
}
|
2013-04-10 20:37:25 +00:00
|
|
|
|
2012-12-26 06:02:30 +00:00
|
|
|
public static boolean canToolHarvestBlock(Block block, int metadata, ItemStack stack)
|
|
|
|
{
|
2013-12-21 08:10:35 +00:00
|
|
|
String tool = block.getHarvestTool(metadata);
|
|
|
|
if (stack == null || tool == null) return false;
|
|
|
|
return stack.getItem().getHarvestLevel(stack, tool) >= block.getHarvestLevel(metadata);
|
2012-12-26 06:02:30 +00:00
|
|
|
}
|
2012-08-06 10:35:57 +00:00
|
|
|
|
|
|
|
public static float blockStrength(Block block, EntityPlayer player, World world, int x, int y, int z)
|
|
|
|
{
|
|
|
|
int metadata = world.getBlockMetadata(x, y, z);
|
2014-02-05 08:05:37 +00:00
|
|
|
float hardness = block.getBlockHardness(world, x, y, z);
|
2012-08-06 10:35:57 +00:00
|
|
|
if (hardness < 0.0F)
|
|
|
|
{
|
|
|
|
return 0.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!canHarvestBlock(block, player, metadata))
|
|
|
|
{
|
2014-04-01 21:40:53 +00:00
|
|
|
return player.getBreakSpeed(block, true, metadata, x, y, z) / hardness / 100F;
|
2012-08-06 10:35:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-01 21:40:53 +00:00
|
|
|
return player.getBreakSpeed(block, false, metadata, x, y, z) / hardness / 30F;
|
2012-08-06 10:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isToolEffective(ItemStack stack, Block block, int metadata)
|
|
|
|
{
|
2013-12-21 08:10:35 +00:00
|
|
|
for (String type : stack.getItem().getToolClasses(stack))
|
|
|
|
{
|
|
|
|
if (block.isToolEffective(type, metadata))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-08-06 10:35:57 +00:00
|
|
|
}
|
2012-09-09 14:02:21 +00:00
|
|
|
|
2012-08-06 10:35:57 +00:00
|
|
|
static void initTools()
|
|
|
|
{
|
|
|
|
if (toolInit)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
toolInit = true;
|
|
|
|
|
2013-12-13 07:32:36 +00:00
|
|
|
Set<Block> blocks = ReflectionHelper.getPrivateValue(ItemPickaxe.class, null, 0);
|
|
|
|
for (Block block : blocks)
|
2012-08-06 10:35:57 +00:00
|
|
|
{
|
2013-12-21 08:10:35 +00:00
|
|
|
block.setHarvestLevel("pickaxe", 0);
|
2012-08-06 10:35:57 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 07:32:36 +00:00
|
|
|
blocks = ReflectionHelper.getPrivateValue(ItemSpade.class, null, 0);
|
|
|
|
for (Block block : blocks)
|
2012-08-06 10:35:57 +00:00
|
|
|
{
|
2013-12-21 08:10:35 +00:00
|
|
|
block.setHarvestLevel("shovel", 0);
|
2012-08-06 10:35:57 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 07:32:36 +00:00
|
|
|
blocks = ReflectionHelper.getPrivateValue(ItemAxe.class, null, 0);
|
|
|
|
for (Block block : blocks)
|
2012-08-06 10:35:57 +00:00
|
|
|
{
|
2013-12-21 08:10:35 +00:00
|
|
|
block.setHarvestLevel("axe", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Blocks.obsidian.setHarvestLevel("pickaxe", 3);
|
|
|
|
for (Block block : new Block[]{emerald_ore, emerald_block, diamond_ore, diamond_block, gold_ore, gold_block, redstone_ore, lit_redstone_ore})
|
|
|
|
{
|
|
|
|
block.setHarvestLevel("pickaxe", 2);
|
|
|
|
}
|
|
|
|
Blocks.iron_ore.setHarvestLevel("pickaxe", 1);
|
|
|
|
Blocks.iron_block.setHarvestLevel("pickaxe", 1);
|
|
|
|
Blocks.lapis_ore.setHarvestLevel("pickaxe", 1);
|
|
|
|
Blocks.lapis_block.setHarvestLevel("pickaxe", 1);
|
2012-08-06 10:35:57 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 22:07:53 +00:00
|
|
|
public static int getTotalArmorValue(EntityPlayer player)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
for (int x = 0; x < player.inventory.armorInventory.length; x++)
|
|
|
|
{
|
|
|
|
ItemStack stack = player.inventory.armorInventory[x];
|
|
|
|
if (stack != null && stack.getItem() instanceof ISpecialArmor)
|
|
|
|
{
|
|
|
|
ret += ((ISpecialArmor)stack.getItem()).getArmorDisplay(player, stack, x);
|
|
|
|
}
|
|
|
|
else if (stack != null && stack.getItem() instanceof ItemArmor)
|
|
|
|
{
|
|
|
|
ret += ((ItemArmor)stack.getItem()).damageReduceAmount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2012-09-09 14:02:21 +00:00
|
|
|
|
2012-08-06 22:07:53 +00:00
|
|
|
static
|
|
|
|
{
|
2013-12-13 07:32:36 +00:00
|
|
|
seedList.add(new SeedEntry(new ItemStack(Items.wheat_seeds), 10));
|
2012-08-06 22:07:53 +00:00
|
|
|
initTools();
|
|
|
|
}
|
2012-08-07 08:24:06 +00:00
|
|
|
|
2012-08-10 09:09:11 +00:00
|
|
|
/**
|
|
|
|
* Called when a player uses 'pick block', calls new Entity and Block hooks.
|
|
|
|
*/
|
|
|
|
public static boolean onPickBlock(MovingObjectPosition target, EntityPlayer player, World world)
|
|
|
|
{
|
|
|
|
ItemStack result = null;
|
|
|
|
boolean isCreative = player.capabilities.isCreativeMode;
|
|
|
|
|
2013-12-21 08:10:35 +00:00
|
|
|
if (target.typeOfHit == MovingObjectType.BLOCK)
|
2012-08-10 09:09:11 +00:00
|
|
|
{
|
|
|
|
int x = target.blockX;
|
|
|
|
int y = target.blockY;
|
|
|
|
int z = target.blockZ;
|
2014-02-05 08:05:37 +00:00
|
|
|
Block block = world.getBlock(x, y, z);
|
2012-08-10 09:09:11 +00:00
|
|
|
|
2013-12-21 08:10:35 +00:00
|
|
|
if (block.isAir(world, x, y, z))
|
2012-08-10 09:09:11 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-21 08:10:35 +00:00
|
|
|
result = block.getPickBlock(target, world, x, y, z);
|
2012-08-10 09:09:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-21 08:10:35 +00:00
|
|
|
if (target.typeOfHit != MovingObjectType.ENTITY || target.entityHit == null || !isCreative)
|
2012-08-10 09:09:11 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = target.entityHit.getPickedResult(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int x = 0; x < 9; x++)
|
|
|
|
{
|
|
|
|
ItemStack stack = player.inventory.getStackInSlot(x);
|
2012-10-31 17:16:46 +00:00
|
|
|
if (stack != null && stack.isItemEqual(result) && ItemStack.areItemStackTagsEqual(stack, result))
|
2012-08-10 09:09:11 +00:00
|
|
|
{
|
|
|
|
player.inventory.currentItem = x;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isCreative)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int slot = player.inventory.getFirstEmptyStack();
|
|
|
|
if (slot < 0 || slot >= 9)
|
|
|
|
{
|
2012-08-22 20:46:01 +00:00
|
|
|
slot = player.inventory.currentItem;
|
2012-08-10 09:09:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
player.inventory.setInventorySlotContents(slot, result);
|
2012-08-14 06:05:39 +00:00
|
|
|
player.inventory.currentItem = slot;
|
2012-08-10 09:09:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-08-23 01:02:14 +00:00
|
|
|
|
|
|
|
//Optifine Helper Functions u.u, these are here specifically for Optifine
|
|
|
|
//Note: When using Optfine, these methods are invoked using reflection, which
|
|
|
|
//incurs a major performance penalty.
|
2013-06-30 12:50:11 +00:00
|
|
|
public static void onLivingSetAttackTarget(EntityLivingBase entity, EntityLivingBase target)
|
2012-08-23 01:02:14 +00:00
|
|
|
{
|
|
|
|
MinecraftForge.EVENT_BUS.post(new LivingSetAttackTargetEvent(entity, target));
|
|
|
|
}
|
|
|
|
|
2013-06-30 12:50:11 +00:00
|
|
|
public static boolean onLivingUpdate(EntityLivingBase entity)
|
2012-08-23 01:02:14 +00:00
|
|
|
{
|
|
|
|
return MinecraftForge.EVENT_BUS.post(new LivingUpdateEvent(entity));
|
|
|
|
}
|
|
|
|
|
2013-06-30 12:50:11 +00:00
|
|
|
public static boolean onLivingAttack(EntityLivingBase entity, DamageSource src, float amount)
|
2012-08-23 01:02:14 +00:00
|
|
|
{
|
|
|
|
return MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, amount));
|
|
|
|
}
|
|
|
|
|
2013-06-30 12:50:11 +00:00
|
|
|
public static float onLivingHurt(EntityLivingBase entity, DamageSource src, float amount)
|
2012-08-23 01:02:14 +00:00
|
|
|
{
|
|
|
|
LivingHurtEvent event = new LivingHurtEvent(entity, src, amount);
|
|
|
|
return (MinecraftForge.EVENT_BUS.post(event) ? 0 : event.ammount);
|
|
|
|
}
|
|
|
|
|
2013-06-30 12:50:11 +00:00
|
|
|
public static boolean onLivingDeath(EntityLivingBase entity, DamageSource src)
|
2012-08-23 01:02:14 +00:00
|
|
|
{
|
|
|
|
return MinecraftForge.EVENT_BUS.post(new LivingDeathEvent(entity, src));
|
|
|
|
}
|
|
|
|
|
2013-06-30 12:50:11 +00:00
|
|
|
public static boolean onLivingDrops(EntityLivingBase entity, DamageSource source, ArrayList<EntityItem> drops, int lootingLevel, boolean recentlyHit, int specialDropValue)
|
2012-08-23 01:02:14 +00:00
|
|
|
{
|
|
|
|
return MinecraftForge.EVENT_BUS.post(new LivingDropsEvent(entity, source, drops, lootingLevel, recentlyHit, specialDropValue));
|
|
|
|
}
|
|
|
|
|
2013-06-30 12:50:11 +00:00
|
|
|
public static float onLivingFall(EntityLivingBase entity, float distance)
|
2012-08-23 01:02:14 +00:00
|
|
|
{
|
|
|
|
LivingFallEvent event = new LivingFallEvent(entity, distance);
|
|
|
|
return (MinecraftForge.EVENT_BUS.post(event) ? 0.0f : event.distance);
|
|
|
|
}
|
|
|
|
|
2013-06-30 12:50:11 +00:00
|
|
|
public static boolean isLivingOnLadder(Block block, World world, int x, int y, int z, EntityLivingBase entity)
|
2013-06-14 18:51:28 +00:00
|
|
|
{
|
2013-12-13 07:32:36 +00:00
|
|
|
if (!ForgeModContainer.fullBoundingBoxLadders)
|
2013-08-11 02:39:06 +00:00
|
|
|
{
|
|
|
|
return block != null && block.isLadder(world, x, y, z, entity);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AxisAlignedBB bb = entity.boundingBox;
|
|
|
|
int mX = MathHelper.floor_double(bb.minX);
|
|
|
|
int mY = MathHelper.floor_double(bb.minY);
|
|
|
|
int mZ = MathHelper.floor_double(bb.minZ);
|
2013-09-25 05:46:18 +00:00
|
|
|
for (int y2 = mY; y2 < bb.maxY; y2++)
|
2013-08-11 02:39:06 +00:00
|
|
|
{
|
|
|
|
for (int x2 = mX; x2 < bb.maxX; x2++)
|
|
|
|
{
|
|
|
|
for (int z2 = mZ; z2 < bb.maxZ; z2++)
|
|
|
|
{
|
2014-02-05 08:05:37 +00:00
|
|
|
block = world.getBlock(x2, y2, z2);
|
2013-08-11 02:39:06 +00:00
|
|
|
if (block != null && block.isLadder(world, x2, y2, z2, entity))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-14 18:51:28 +00:00
|
|
|
}
|
2012-08-23 01:02:14 +00:00
|
|
|
|
2013-06-30 12:50:11 +00:00
|
|
|
public static void onLivingJump(EntityLivingBase entity)
|
2012-08-23 01:02:14 +00:00
|
|
|
{
|
|
|
|
MinecraftForge.EVENT_BUS.post(new LivingJumpEvent(entity));
|
|
|
|
}
|
2012-09-11 22:27:34 +00:00
|
|
|
|
2013-12-21 08:10:35 +00:00
|
|
|
public static EntityItem onPlayerTossEvent(EntityPlayer player, ItemStack item, boolean includeName)
|
2012-09-11 22:27:34 +00:00
|
|
|
{
|
|
|
|
player.captureDrops = true;
|
2013-12-21 08:10:35 +00:00
|
|
|
EntityItem ret = player.func_146097_a(item, false, includeName);
|
2012-09-11 22:27:34 +00:00
|
|
|
player.capturedDrops.clear();
|
|
|
|
player.captureDrops = false;
|
|
|
|
|
2013-08-19 17:45:57 +00:00
|
|
|
if (ret == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-09-11 22:27:34 +00:00
|
|
|
ItemTossEvent event = new ItemTossEvent(ret, player);
|
|
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.joinEntityItemWithWorld(event.entityItem);
|
|
|
|
return event.entityItem;
|
|
|
|
}
|
2013-04-10 23:56:31 +00:00
|
|
|
|
|
|
|
public static float getEnchantPower(World world, int x, int y, int z)
|
|
|
|
{
|
2014-02-05 08:05:37 +00:00
|
|
|
return world.getBlock(x, y, z).getEnchantPowerBonus(world, x, y, z);
|
2013-04-10 23:56:31 +00:00
|
|
|
}
|
2013-06-30 12:50:11 +00:00
|
|
|
|
2013-12-21 08:10:35 +00:00
|
|
|
public static ChatComponentTranslation onServerChatEvent(NetHandlerPlayServer net, String raw, ChatComponentTranslation comp)
|
2013-06-30 12:50:11 +00:00
|
|
|
{
|
2014-02-05 08:05:37 +00:00
|
|
|
ServerChatEvent event = new ServerChatEvent(net.playerEntity, raw, comp);
|
2013-06-30 12:50:11 +00:00
|
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return event.component;
|
|
|
|
}
|
2013-12-28 02:26:42 +00:00
|
|
|
|
2013-10-05 11:10:00 +00:00
|
|
|
public static boolean canInteractWith(EntityPlayer player, Container openContainer)
|
|
|
|
{
|
|
|
|
PlayerOpenContainerEvent event = new PlayerOpenContainerEvent(player, openContainer);
|
|
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
return event.getResult() == Event.Result.DEFAULT ? event.canInteractWith : event.getResult() == Event.Result.ALLOW ? true : false;
|
|
|
|
}
|
2013-12-28 02:26:42 +00:00
|
|
|
|
2013-12-21 08:10:35 +00:00
|
|
|
public static BlockEvent.BreakEvent onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, int x, int y, int z)
|
2013-10-09 00:00:02 +00:00
|
|
|
{
|
|
|
|
// Logic from tryHarvestBlock for pre-canceling the event
|
|
|
|
boolean preCancelEvent = false;
|
|
|
|
if (gameType.isAdventure() && !entityPlayer.isCurrentToolAdventureModeExempt(x, y, z))
|
|
|
|
{
|
|
|
|
preCancelEvent = true;
|
|
|
|
}
|
|
|
|
else if (gameType.isCreative() && entityPlayer.getHeldItem() != null && entityPlayer.getHeldItem().getItem() instanceof ItemSword)
|
|
|
|
{
|
|
|
|
preCancelEvent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell client the block is gone immediately then process events
|
2014-02-05 08:05:37 +00:00
|
|
|
if (world.getTileEntity(x, y, z) == null)
|
2013-10-09 00:00:02 +00:00
|
|
|
{
|
2013-12-21 08:10:35 +00:00
|
|
|
S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world);
|
|
|
|
packet.field_148883_d = Blocks.air;
|
|
|
|
packet.field_148884_e = 0;
|
2014-02-05 08:05:37 +00:00
|
|
|
entityPlayer.playerNetServerHandler.sendPacket(packet);
|
2013-10-09 00:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Post the block break event
|
2014-02-05 08:05:37 +00:00
|
|
|
Block block = world.getBlock(x, y, z);
|
2013-10-09 00:00:02 +00:00
|
|
|
int blockMetadata = world.getBlockMetadata(x, y, z);
|
|
|
|
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, blockMetadata, entityPlayer);
|
|
|
|
event.setCanceled(preCancelEvent);
|
|
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
|
|
|
|
// Handle if the event is canceled
|
|
|
|
if (event.isCanceled())
|
|
|
|
{
|
|
|
|
// Let the client know the block still exists
|
2014-02-05 08:05:37 +00:00
|
|
|
entityPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
|
2013-12-28 02:26:42 +00:00
|
|
|
|
2013-10-09 00:00:02 +00:00
|
|
|
// Update any tile entity data for this block
|
2014-02-05 08:05:37 +00:00
|
|
|
TileEntity tileentity = world.getTileEntity(x, y, z);
|
2013-10-09 00:00:02 +00:00
|
|
|
if (tileentity != null)
|
|
|
|
{
|
2014-02-05 08:05:37 +00:00
|
|
|
Packet pkt = tileentity.getDescriptionPacket();
|
2013-11-16 23:26:00 +00:00
|
|
|
if (pkt != null)
|
|
|
|
{
|
2014-02-05 08:05:37 +00:00
|
|
|
entityPlayer.playerNetServerHandler.sendPacket(pkt);
|
2013-11-16 23:26:00 +00:00
|
|
|
}
|
2013-10-09 00:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return event;
|
|
|
|
}
|
2014-04-03 01:33:13 +00:00
|
|
|
|
|
|
|
public static boolean onAnvilChange(ContainerRepair container, ItemStack left, ItemStack right, IInventory outputSlot, String name, int baseCost)
|
|
|
|
{
|
|
|
|
AnvilUpdateEvent e = new AnvilUpdateEvent(left, right, name, baseCost);
|
|
|
|
if (MinecraftForge.EVENT_BUS.post(e)) return false;
|
|
|
|
if (e.output == null) return true;
|
|
|
|
|
|
|
|
outputSlot.setInventorySlotContents(0, e.output);
|
|
|
|
container.maximumCost = e.cost;
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-06 02:15:13 +00:00
|
|
|
}
|