Search in sources :

Example 51 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project PneumaticCraft by MineMaarten.

the class CommonHUDHandler method tickEnd.

@SubscribeEvent
public void tickEnd(TickEvent.PlayerTickEvent event) {
    if (event.phase == TickEvent.Phase.END) {
        EntityPlayer player = event.player;
        if (this == PneumaticCraft.proxy.getCommonHudHandler()) {
            getHandlerForPlayer(player).tickEnd(event);
        } else {
            ItemStack helmetStack = player.getCurrentArmor(3);
            if (helmetStack != null && helmetStack.getItem() == Itemss.pneumaticHelmet) {
                helmetPressure = ((IPressurizable) helmetStack.getItem()).getPressure(helmetStack);
                if (ticksExisted == 0) {
                    checkHelmetInventory(helmetStack);
                }
                ticksExisted++;
                if (!player.worldObj.isRemote) {
                    if (ticksExisted > getStartupTime() && !player.capabilities.isCreativeMode) {
                        ((IPressurizable) helmetStack.getItem()).addAir(helmetStack, (int) -UpgradeRenderHandlerList.instance().getAirUsage(player, false));
                    }
                }
            } else {
                ticksExisted = 0;
            }
            if (!player.worldObj.isRemote)
                handleHacking(player);
        }
    }
}
Also used : IPressurizable(pneumaticCraft.api.item.IPressurizable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 52 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project PneumaticCraft by MineMaarten.

the class TickHandlerPneumaticCraft method tickEnd.

@SubscribeEvent
public void tickEnd(TickEvent.WorldTickEvent event) {
    if (event.phase == TickEvent.Phase.END) {
        World world = event.world;
        checkLightning(world);
        DroneClaimManager.getInstance(world).update();
        if (!event.world.isRemote && event.world.provider.dimensionId == 0 && event.world.getWorldTime() % (24000 / AmadronOfferPeriodicConfig.timesPerDay) == 1) {
            AmadronOfferManager.getInstance().shufflePeriodicOffers();
        }
        if (!event.world.isRemote && event.world.getTotalWorldTime() % 100 == 0) {
            // In case world are going to get their own thread: MinecraftServer.getServer().worldTickTimes.get(event.world.provider.dimensionId)
            double tickTime = net.minecraft.util.MathHelper.average(MinecraftServer.getServer().tickTimeArray) * 1.0E-6D;
            NetworkHandler.sendToDimension(new PacketServerTickTime(tickTime), event.world.provider.dimensionId);
            if (event.world.getTotalWorldTime() % 600 == 0)
                AmadronOfferManager.getInstance().tryRestockCustomOffers();
        }
    }
}
Also used : PacketServerTickTime(pneumaticCraft.common.network.PacketServerTickTime) World(net.minecraft.world.World) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 53 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project Minechem by iopleke.

the class PotionCoatingSubscribe method entityAttacked.

@SubscribeEvent
public void entityAttacked(LivingAttackEvent event) {
    if (event.source.getSourceOfDamage() instanceof EntityLivingBase) {
        EntityLivingBase entity = (EntityLivingBase) event.source.getSourceOfDamage();
        ItemStack weapon = entity.getHeldItem();
        if (weapon == null) {
            return;
        }
        NBTTagList list = weapon.getEnchantmentTagList();
        if (list == null) {
            return;
        }
        for (int i = 0; i < list.tagCount(); i++) {
            NBTTagCompound enchantmentTag = list.getCompoundTagAt(i);
            Enchantment enchant = Enchantment.enchantmentsList[enchantmentTag.getShort("id")];
            if (enchant instanceof PotionEnchantmentCoated) {
                ((PotionEnchantmentCoated) enchant).applyEffect(event.entityLiving);
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) EntityLivingBase(net.minecraft.entity.EntityLivingBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 54 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project Minechem by iopleke.

the class PolytoolEventHandler method onDrop.

@SubscribeEvent
public void onDrop(LivingDropsEvent event) {
    // Thanks to mDiyo
    if ("player".equals(event.source.damageType)) {
        EntityPlayer player = (EntityPlayer) event.source.getEntity();
        ItemStack stack = player.getCurrentEquippedItem();
        if (stack != null && stack.getItem() instanceof PolytoolItem) {
            float powerSilicon = PolytoolItem.getPowerOfType(stack, ElementEnum.Si);
            if (powerSilicon > 0) {
                int amount = (int) Math.ceil(random.nextDouble() * powerSilicon);
                Iterator iter = event.drops.iterator();
                if (random.nextInt(16) < 1 + powerSilicon) {
                    ArrayList<EntityItem> trueResult = new ArrayList<EntityItem>();
                    while (iter.hasNext()) {
                        EntityItem entityItem = (EntityItem) iter.next();
                        ItemStack item = entityItem.getEntityItem();
                        while (item.stackSize > 0) {
                            // Always avoid chances
                            DecomposerRecipe recipe = DecomposerRecipeHandler.instance.getRecipe(item);
                            if (recipe != null) {
                                ArrayList<ItemStack> items = MinechemUtil.convertChemicalsIntoItemStacks(recipe.getOutput());
                                for (ItemStack itemStack : items) {
                                    trueResult.add(new EntityItem(entityItem.worldObj, entityItem.posX, entityItem.posY, entityItem.posZ, itemStack));
                                }
                            } else {
                                trueResult.add(entityItem);
                                break;
                            }
                            item.stackSize--;
                        }
                    }
                    event.drops.clear();
                    event.drops.addAll(trueResult);
                }
            }
        }
        if (event.entityLiving instanceof EntitySkeleton || event.entityLiving instanceof EntityZombie || event.entityLiving instanceof EntityPlayer) {
            EntityLivingBase enemy = event.entityLiving;
            if (stack != null && stack.getItem() instanceof PolytoolItem) {
                // Nitrogen preservation
                if (enemy instanceof EntityZombie) {
                    float power = PolytoolItem.getPowerOfType(stack, ElementEnum.N);
                    if (power > 0) {
                        int amount = (int) Math.ceil(random.nextDouble() * power);
                        addDrops(event, new ItemStack(Items.cooked_beef, amount, 0));
                        Iterator iter = event.drops.iterator();
                        while (iter.hasNext()) {
                            EntityItem entityItem = (EntityItem) iter.next();
                            if (entityItem.getEntityItem().getItem() == Items.rotten_flesh) {
                                iter.remove();
                            }
                        }
                    }
                }
                // Calcium bonus
                if (enemy instanceof EntitySkeleton) {
                    float power = PolytoolItem.getPowerOfType(stack, ElementEnum.Ca);
                    if (power > 0) {
                        int amount = (int) Math.ceil(random.nextDouble() * power);
                        Iterator iter = event.drops.iterator();
                        while (iter.hasNext()) {
                            EntityItem entityItem = (EntityItem) iter.next();
                            if (entityItem.getEntityItem().getItem() == Items.bone) {
                                entityItem.getEntityItem().stackSize += amount;
                            }
                        }
                    }
                }
                // Beryllium beheading
                float beheading = PolytoolItem.getPowerOfType(stack, ElementEnum.Be);
                while (beheading > 5) {
                    if (beheading > 0 && random.nextInt(5) < beheading * 10) {
                        if (event.entityLiving instanceof EntitySkeleton) {
                            EntitySkeleton skeleton = (EntitySkeleton) enemy;
                            addDrops(event, new ItemStack(Items.skull, 1, skeleton.getSkeletonType()));
                        } else if (event.entityLiving instanceof EntityZombie) {
                            addDrops(event, new ItemStack(Items.skull, 1, 2));
                        } else if (event.entityLiving instanceof EntityPlayer) {
                            ItemStack dropStack = new ItemStack(Items.skull, 1, 3);
                            NBTTagCompound nametag = new NBTTagCompound();
                            nametag.setString("SkullOwner", player.getDisplayName());
                            addDrops(event, dropStack);
                        }
                    }
                    // More head drops if level>5
                    beheading--;
                }
            }
        }
    }
}
Also used : EntitySkeleton(net.minecraft.entity.monster.EntitySkeleton) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityZombie(net.minecraft.entity.monster.EntityZombie) Iterator(java.util.Iterator) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) DecomposerRecipe(minechem.tileentity.decomposer.DecomposerRecipe) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 55 with SubscribeEvent

use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project ArsMagica2 by Mithion.

the class PowerNodeCache method onWorldUnload.

@SubscribeEvent
public void onWorldUnload(WorldEvent.Unload event) {
    World world = event.world;
    saveWorldToFile(world);
}
Also used : World(net.minecraft.world.World) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)138 EntityPlayer (net.minecraft.entity.player.EntityPlayer)57 ItemStack (net.minecraft.item.ItemStack)48 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)18 Minecraft (net.minecraft.client.Minecraft)14 EntityLivingBase (net.minecraft.entity.EntityLivingBase)14 World (net.minecraft.world.World)14 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)12 ArrayList (java.util.ArrayList)10 EntityItem (net.minecraft.entity.item.EntityItem)10 SideOnly (cpw.mods.fml.relauncher.SideOnly)9 ChunkPosition (net.minecraft.world.ChunkPosition)9 ChatComponentText (net.minecraft.util.ChatComponentText)8 PlayerPointer (riskyken.armourersWorkshop.common.data.PlayerPointer)8 Block (net.minecraft.block.Block)7 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)6 AffinityData (am2.playerextensions.AffinityData)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)5