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);
}
}
}
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();
}
}
}
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);
}
}
}
}
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--;
}
}
}
}
}
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);
}
Aggregations