From a2cfca14d18593a1f8118666ae73cb000c239d12 Mon Sep 17 00:00:00 2001 From: makeo Date: Mon, 11 Jan 2016 21:30:16 +0100 Subject: [PATCH] -Fixed crashes 2 --- .../gadomancy/common/aura/AuraEffects.java | 5 +- .../common/events/EventHandlerWorld.java | 67 ++++++++++--------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/main/java/makeo/gadomancy/common/aura/AuraEffects.java b/src/main/java/makeo/gadomancy/common/aura/AuraEffects.java index dd35dc9..13c0a9e 100644 --- a/src/main/java/makeo/gadomancy/common/aura/AuraEffects.java +++ b/src/main/java/makeo/gadomancy/common/aura/AuraEffects.java @@ -460,10 +460,13 @@ public class AuraEffects { public void doBlockEffect(ChunkCoordinates originTile, ChunkCoordinates selectedBlock, World world) { EntityLiving mob = world.rand.nextBoolean() ? new EntitySkeleton(world) : new EntityZombie(world); if(setAndCheckPosition(mob, selectedBlock, world, true) && world.difficultySetting != EnumDifficulty.PEACEFUL) { + for(int i = 0; i < 5; i++) { + mob.setCurrentItemOrArmor(i, null); + } int totalCount = (world.rand.nextInt(3) == 0 ? 1 : 0) + 2; do { - int slot = mob.getEquipmentInSlot(0) == null ? 0 : mob.getEquipmentInSlot(4) == null ? 4 : world.rand.nextInt(5); + int slot = mob.getEquipmentInSlot(0) == null ? 0 : (mob.getEquipmentInSlot(4) == null ? 4 : (world.rand.nextInt(3)+1)); if(mob.getEquipmentInSlot(slot) == null) { ItemStack[] items = ITEMS_SOUL[slot]; ItemStack stack = items[world.rand.nextInt(items.length)]; diff --git a/src/main/java/makeo/gadomancy/common/events/EventHandlerWorld.java b/src/main/java/makeo/gadomancy/common/events/EventHandlerWorld.java index 705e572..63f3f47 100644 --- a/src/main/java/makeo/gadomancy/common/events/EventHandlerWorld.java +++ b/src/main/java/makeo/gadomancy/common/events/EventHandlerWorld.java @@ -27,6 +27,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; import net.minecraft.util.StatCollector; import net.minecraft.world.Explosion; import net.minecraft.world.GameRules; @@ -43,10 +44,7 @@ import thaumcraft.common.config.ConfigBlocks; import thaumcraft.common.items.wands.ItemWandCasting; import thaumcraft.common.tiles.TileJarFillable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * This class is part of the Gadomancy Mod @@ -57,49 +55,58 @@ import java.util.Map; * Created by makeo @ 05.07.2015 13:20 */ public class EventHandlerWorld { - public List trackedItems = new ArrayList(); + public Map trackedItems = new HashMap(); @SubscribeEvent(priority = EventPriority.LOW) public void on(EntityJoinWorldEvent event) { if(!event.world.isRemote && event.entity instanceof EntityItem && isDisguised(((EntityItem) event.entity).getEntityItem())) { - trackedItems.add((EntityItem) event.entity); + long time = event.world.getTotalWorldTime() + event.world.rand.nextInt(60) + 40; + trackedItems.put((EntityItem) event.entity, time); } } @SubscribeEvent public void on(TickEvent.WorldTickEvent event) { - if(event.phase == TickEvent.Phase.START && !event.world.isRemote && event.world.getTotalWorldTime() % 30 == 0 && event.world.rand.nextBoolean()) { - for(int i = 0; i < trackedItems.size(); i++) { - EntityItem entity = trackedItems.get(i); + if(event.phase == TickEvent.Phase.START && !event.world.isRemote && event.world.getTotalWorldTime() % 10 == 0) { + + Iterator> iterator = trackedItems.entrySet().iterator(); + while(iterator.hasNext()) { + Map.Entry entry = iterator.next(); + EntityItem entity = entry.getKey(); + if(event.world == entity.worldObj) { if(entity.isDead || !isDisguised(entity.getEntityItem())) { - trackedItems.remove(i); - i--; + iterator.remove(); continue; } - int x = (int) entity.posX - 1; - int y = (int) entity.posY; - int z = (int) entity.posZ - 1; - if(entity.delayBeforeCanPickup <= 0 && ConfigBlocks.blockFluidPure == event.world.getBlock(x, y, z) - && event.world.getBlockMetadata(x, y, z) == 0) { - NBTTagCompound compound = NBTHelper.getPersistentData(entity.getEntityItem()); - NBTBase base = compound.getTag("disguise"); - if(base instanceof NBTTagCompound) { - ItemStack stack = ItemStack.loadItemStackFromNBT((NBTTagCompound) base); - EntityItem newEntity = new EntityItem(event.world, entity.posX, entity.posY, entity.posZ, stack); - ItemUtils.applyRandomDropOffset(newEntity, event.world.rand); - event.world.spawnEntityInWorld(newEntity); - } - compound.removeTag("disguise"); - if(compound.hasNoTags()) { - NBTHelper.removePersistentData(entity.getEntityItem()); - if(entity.getEntityItem().getTagCompound().hasNoTags()) { - entity.getEntityItem().setTagCompound(null); + int x = MathHelper.floor_double(entity.posX); + int y = MathHelper.floor_double(entity.posY); + int z = MathHelper.floor_double(entity.posZ); + + if(entity.delayBeforeCanPickup <= 0 && entity.worldObj.getTotalWorldTime() - entry.getValue() > 0) { + if(ConfigBlocks.blockFluidPure == event.world.getBlock(x, y, z) + && event.world.getBlockMetadata(x, y, z) == 0) { + NBTTagCompound compound = NBTHelper.getPersistentData(entity.getEntityItem()); + NBTBase base = compound.getTag("disguise"); + if(base instanceof NBTTagCompound) { + ItemStack stack = ItemStack.loadItemStackFromNBT((NBTTagCompound) base); + EntityItem newEntity = new EntityItem(event.world, entity.posX, entity.posY, entity.posZ, stack); + ItemUtils.applyRandomDropOffset(newEntity, event.world.rand); + event.world.spawnEntityInWorld(newEntity); } + compound.removeTag("disguise"); + if(compound.hasNoTags()) { + NBTHelper.removePersistentData(entity.getEntityItem()); + if(entity.getEntityItem().getTagCompound().hasNoTags()) { + entity.getEntityItem().setTagCompound(null); + } + } + event.world.setBlockToAir(x, y, z); } - event.world.setBlockToAir(x, y, z); + } else { + Gadomancy.proxy.spawnBubbles(event.world, (float)entity.posX, (float)entity.posY, (float)entity.posZ, 0.2f); } } }