use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project BetterStorage by copygirl.
the class ClientProxy method drawBlockHighlight.
@SubscribeEvent
public void drawBlockHighlight(DrawBlockHighlightEvent event) {
EntityPlayer player = event.player;
World world = player.worldObj;
MovingObjectPosition target = WorldUtils.rayTrace(player, event.partialTicks);
if ((target == null) || (target.typeOfHit != MovingObjectType.BLOCK))
return;
int x = target.blockX;
int y = target.blockY;
int z = target.blockZ;
AxisAlignedBB box = null;
Block block = world.getBlock(x, y, z);
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (block instanceof TileArmorStand)
box = getArmorStandHighlightBox(player, world, x, y, z, target.hitVec);
else if (block == Blocks.iron_door)
box = getIronDoorHightlightBox(player, world, x, y, z, target.hitVec, block);
else if (tileEntity instanceof IHasAttachments)
box = getAttachmentPointsHighlightBox(player, tileEntity, target);
if (box == null)
return;
double xOff = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.partialTicks;
double yOff = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.partialTicks;
double zOff = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.partialTicks;
box.offset(-xOff, -yOff, -zOff);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
GL11.glLineWidth(2.0F);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDepthMask(false);
RenderGlobal.drawOutlinedBoundingBox(box, -1);
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
event.setCanceled(true);
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project BetterStorage by copygirl.
the class CommonProxy method onPlayerTick.
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {
if (event.side == Side.SERVER && event.phase == Phase.END) {
//Cleanup in case the backpack is not equipped correctly, due to changing the backpackChestplate setting.
ItemStack stack = event.player.getEquipmentInSlot(EquipmentSlot.CHEST);
if (stack != null && stack.getItem() instanceof ItemBackpack && !BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate)) {
//First thing that never should happen...
event.player.setCurrentItemOrArmor(EquipmentSlot.CHEST, null);
ItemBackpack.setBackpack(event.player, stack, ItemBackpack.getBackpackData(event.player).contents);
} else if ((stack == null || (stack.getItem() != null && !(stack.getItem() instanceof ItemBackpack))) && ItemBackpack.getBackpackData(event.player).backpack != null && BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate)) {
//And that.
ItemStack backpack = ItemBackpack.getBackpack(event.player);
//Not really a good practice, I'd say.
ItemBackpack.getBackpackData(event.player).backpack = null;
if (stack != null) {
//Drop the armor if the player had some and decided to switch the setting anyways.
WorldUtils.dropStackFromEntity(event.player, stack, 4.0F);
}
event.player.setCurrentItemOrArmor(EquipmentSlot.CHEST, backpack);
}
}
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project BetterStorage by copygirl.
the class CommonProxy method onEntityInteract.
@SubscribeEvent
public void onEntityInteract(EntityInteractEvent event) {
if (event.entity.worldObj.isRemote || event.isCanceled())
return;
EntityPlayer player = event.entityPlayer;
Entity target = event.target;
ItemStack holding = player.getCurrentEquippedItem();
if ((target.getClass() == EntityChicken.class) && (holding != null) && (holding.getItem() == Items.name_tag)) {
EntityChicken chicken = (EntityChicken) target;
if (!chicken.isDead && !chicken.isChild() && "Cluckington".equals(holding.getDisplayName()))
EntityCluckington.spawn(chicken);
}
if ((BetterStorageItems.slimeBucket != null) && (target instanceof EntityLiving) && (holding != null) && (holding.getItem() == Items.bucket)) {
ItemBucketSlime.pickUpSlime(player, (EntityLiving) target);
if (player.getCurrentEquippedItem().getItem() instanceof ItemBucketSlime)
preventSlimeBucketUse = true;
}
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project BetterStorage by copygirl.
the class ChristmasEventHandler method onPlayerDeath.
@SubscribeEvent
public void onPlayerDeath(LivingDeathEvent event) {
if (!(event.entity instanceof EntityPlayerMP))
return;
EntityPlayer player = (EntityPlayer) event.entity;
BetterChristmasProperties properties = EntityUtils.getProperties(player, BetterChristmasProperties.class);
NBTTagCompound entityData = player.getEntityData();
NBTTagCompound persistent = entityData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
entityData.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistent);
NBTTagCompound propertiesCompound = new NBTTagCompound();
properties.saveNBTData(propertiesCompound);
persistent.setTag(BetterChristmasProperties.identifier, propertiesCompound);
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project BetterStorage by copygirl.
the class ChristmasEventHandler method onPlayerRespawn.
@SubscribeEvent
public void onPlayerRespawn(PlayerRespawnEvent event) {
EntityPlayer player = event.player;
BetterChristmasProperties properties = EntityUtils.getProperties(player, BetterChristmasProperties.class);
NBTTagCompound entityData = player.getEntityData();
NBTTagCompound persistent = entityData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
NBTTagCompound propertiesCompound = persistent.getCompoundTag(BetterChristmasProperties.identifier);
if (propertiesCompound.hasNoTags())
return;
properties.loadNBTData(propertiesCompound);
persistent.removeTag(BetterChristmasProperties.identifier);
if (persistent.hasNoTags())
entityData.removeTag(EntityPlayer.PERSISTED_NBT_TAG);
}
Aggregations