Search in sources :

Example 26 with SubscribeEvent

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);
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) TileArmorStand(net.mcft.copy.betterstorage.tile.stand.TileArmorStand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) World(net.minecraft.world.World) IHasAttachments(net.mcft.copy.betterstorage.attachment.IHasAttachments) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 27 with SubscribeEvent

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);
        }
    }
}
Also used : ItemBackpack(net.mcft.copy.betterstorage.item.ItemBackpack) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 28 with SubscribeEvent

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;
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityChicken(net.minecraft.entity.passive.EntityChicken) EntityLiving(net.minecraft.entity.EntityLiving) ItemBucketSlime(net.mcft.copy.betterstorage.item.ItemBucketSlime) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 29 with SubscribeEvent

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);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 30 with SubscribeEvent

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);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)109 EntityPlayer (net.minecraft.entity.player.EntityPlayer)45 ItemStack (net.minecraft.item.ItemStack)45 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)14 EntityLivingBase (net.minecraft.entity.EntityLivingBase)11 World (net.minecraft.world.World)11 Minecraft (net.minecraft.client.Minecraft)10 ChunkPosition (net.minecraft.world.ChunkPosition)9 EntityItem (net.minecraft.entity.item.EntityItem)8 ChatComponentText (net.minecraft.util.ChatComponentText)8 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 AffinityData (am2.playerextensions.AffinityData)5 SideOnly (cpw.mods.fml.relauncher.SideOnly)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Block (net.minecraft.block.Block)5 EntityEnderman (net.minecraft.entity.monster.EntityEnderman)5 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)5 ExtendedProperties (am2.playerextensions.ExtendedProperties)4