Posted October 28, 201411 yr I've added a function that stores all your items into a newly spawned chest when you die as long as you have a custom item. It works except for when mobs kill me. [spoiler=DeathChestHandler] package com.multiverse.items; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.PlayerDropsEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class DeathChestHanlder { public DeathChestHanlder() { } @SubscribeEvent public void onPlayerDrops(PlayerDropsEvent event) { boolean saveItems = false; int counter = 0; for(EntityItem droppedStack : event.drops) { if(droppedStack.getEntityItem().getItem() == MultiverseItems.SavingStone) { event.drops.remove(droppedStack); saveItems = true; } } if(saveItems) { int posX = MathHelper.floor_double(event.entityPlayer.posX); int posY = MathHelper.floor_double(event.entityPlayer.posY); int posZ = MathHelper.floor_double(event.entityPlayer.posZ); World world = event.entityPlayer.worldObj; world.setBlock(posX, posY, posZ, Blocks.chest, 0, 2); TileEntityChest chest = (TileEntityChest) world.getTileEntity(posX, posY, posZ); for(EntityItem droppedItemEntity : event.drops) { counter++; ItemStack droppedItem = droppedItemEntity.getEntityItem(); if(counter > chest.getSizeInventory()) { return; } else { chest.setInventorySlotContents(counter - 1, droppedItem); droppedItemEntity.setDead(); } } } } } [spoiler=crash report] ---- Minecraft Crash Report ---- // Ouch. That hurt Time: 10/28/14 4:15 PM Description: Ticking entity java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(Unknown Source) at java.util.ArrayList$Itr.next(Unknown Source) at com.multiverse.items.DeathChestHanlder.onPlayerDrops(DeathChestHanlder.java:23) at cpw.mods.fml.common.eventhandler.ASMEventHandler_10_DeathChestHanlder_onPlayerDrops_PlayerDropsEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) at net.minecraft.entity.player.EntityPlayerMP.onDeath(EntityPlayerMP.java:455) at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:938) at net.minecraft.entity.player.EntityPlayer.attackEntityFrom(EntityPlayer.java:1161) at net.minecraft.entity.player.EntityPlayerMP.attackEntityFrom(EntityPlayerMP.java:532) at net.minecraft.entity.monster.EntityMob.attackEntityAsMob(EntityMob.java:140) at net.minecraft.entity.monster.EntityZombie.attackEntityAsMob(EntityZombie.java:340) at net.minecraft.entity.ai.EntityAIAttackOnCollide.updateTask(EntityAIAttackOnCollide.java:167) at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(EntityAITasks.java:125) at net.minecraft.entity.EntityLiving.updateAITasks(EntityLiving.java:613) at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:1981) at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:431) at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:39) at net.minecraft.entity.monster.EntityZombie.onLivingUpdate(EntityZombie.java:243) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1814) at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:250) at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:47) at net.minecraft.entity.monster.EntityZombie.onUpdate(EntityZombie.java:335) at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2298) at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:684) at net.minecraft.world.World.updateEntity(World.java:2258) at net.minecraft.world.World.updateEntities(World.java:2108) at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:515) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at java.util.ArrayList$Itr.checkForComodification(Unknown Source) at java.util.ArrayList$Itr.next(Unknown Source) at com.multiverse.items.DeathChestHanlder.onPlayerDrops(DeathChestHanlder.java:23) at cpw.mods.fml.common.eventhandler.ASMEventHandler_10_DeathChestHanlder_onPlayerDrops_PlayerDropsEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) at net.minecraft.entity.player.EntityPlayerMP.onDeath(EntityPlayerMP.java:455) at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:938) at net.minecraft.entity.player.EntityPlayer.attackEntityFrom(EntityPlayer.java:1161) at net.minecraft.entity.player.EntityPlayerMP.attackEntityFrom(EntityPlayerMP.java:532) at net.minecraft.entity.monster.EntityMob.attackEntityAsMob(EntityMob.java:140) at net.minecraft.entity.monster.EntityZombie.attackEntityAsMob(EntityZombie.java:340) at net.minecraft.entity.ai.EntityAIAttackOnCollide.updateTask(EntityAIAttackOnCollide.java:167) at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(EntityAITasks.java:125) at net.minecraft.entity.EntityLiving.updateAITasks(EntityLiving.java:613) at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:1981) at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:431) at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:39) at net.minecraft.entity.monster.EntityZombie.onLivingUpdate(EntityZombie.java:243) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1814) at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:250) at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:47) at net.minecraft.entity.monster.EntityZombie.onUpdate(EntityZombie.java:335) at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2298) at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:684) at net.minecraft.world.World.updateEntity(World.java:2258) -- Entity being ticked -- Details: Entity Type: Zombie (net.minecraft.entity.monster.EntityZombie) Entity ID: 8216 Entity Name: Zombie Entity's Exact location: -252.75, 64.00, -54.06 Entity's Block location: World: (-253,64,-55), Chunk: (at 3,4,9 in -16,-4; contains blocks -256,0,-64 to -241,255,-49), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1) Entity's Momentum: -0.05, -0.08, -0.05 Stacktrace: at net.minecraft.world.World.updateEntities(World.java:2108) at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:515) -- Affected level -- Details: Level name: New World All players: 1 total; [EntityPlayerMP['Player890'/284, l='New World', x=-252.10, y=65.09, z=-53.86]] Chunk stats: ServerChunkCache: 257 Drop: 0 Level seed: -4326943415393502365 Level generator: ID 00 - default, ver 1. Features enabled: true Level generator options: Level spawn location: World: (-251,64,-48), Chunk: (at 5,4,0 in -16,-3; contains blocks -256,0,-48 to -241,255,-33), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1) Level time: 3265 game time, 15001 day time Level dimension: 0 Level storage version: 0x04ABD - Anvil Level weather: Rain time: 87523 (now: false), thunder time: 172592 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true Stacktrace: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 8.1 (amd64) version 6.3 Java Version: 1.7.0_71, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 877677696 bytes (837 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94 FML: MCP v9.05 FML v7.10.85.1230 Minecraft Forge 10.13.2.1230 4 mods loaded, 4 mods active mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{7.10.85.1230} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.2.1230.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{10.13.2.1230} [Minecraft Forge] (forgeSrc-1.7.10-10.13.2.1230.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available multiverse{1.0} [Multiverse Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Player Count: 1 / 8; [EntityPlayerMP['Player890'/284, l='New World', x=-252.10, y=65.09, z=-53.86]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
October 29, 201411 yr for(EntityItem droppedStack : event.drops) { if(droppedStack.getEntityItem().getItem() == MultiverseItems.SavingStone) { event.drops.remove(droppedStack); saveItems = true; } } You cannot do remove() directly on a list while you're iterating through it. You need to use an iterator and use that to remove the element: http://stackoverflow.com/a/223929 Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
October 29, 201411 yr Author for(EntityItem droppedStack : event.drops) { if(droppedStack.getEntityItem().getItem() == MultiverseItems.SavingStone) { event.drops.remove(droppedStack); saveItems = true; } } You cannot do remove() directly on a list while you're iterating through it. You need to use an iterator and use that to remove the element: http://stackoverflow.com/a/223929 Thanks, that worked. I also added "break;" so it wouldn't remove every Saving Stone. Here's the new code: for (Iterator<EntityItem> iterator = event.drops.iterator(); iterator.hasNext() { EntityItem droppedStack = iterator.next(); if (droppedStack.getEntityItem().getItem() == MultiverseItems.SavingStone){ iterator.remove(); saveItems = true; break; } }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.