Jump to content

[1.7.10][Solved]Added Death Chest mod into my mod, I crash when dying from mobs.


dragon3025

Recommended Posts

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'

 

Link to comment
Share on other sites

	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.

Link to comment
Share on other sites

	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;
	    }
	}

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Captain WebGenesis is a Cyber skilled hacker with special abilities and skills that enact penetration to help victims of Crypto Fraudulent activities who are faced with cyber challenges get back their lost funds. Simply file your complaint through the website (https://captainwebgenesis. com) and have all your crypto recovered back.
    • The crash log keeps saying something about the tick rate. Can someone please help me fix?   ---- Minecraft Crash Report ---- // Everything's going to plan. No, really, that was supposed to happen. Time: 2024-06-21 16:24:55 Description: Exception in server tick loop java.lang.NullPointerException: Cannot invoke "com.cobblemon.mod.common.api.conditional.RegistryLikeCondition.fits(Object, net.minecraft.core.Registry)" because "condition" is null at com.cobblemon.mod.common.api.spawning.condition.SpawningCondition.fits(SpawningCondition.java:85) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.condition.AreaTypeSpawningCondition.fits(AreaTypeSpawningCondition.java:30) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.condition.GroundedTypeSpawningCondition.fits(GroundedTypeSpawningCondition.java:28) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.condition.GroundedTypeSpawningCondition.fits(GroundedTypeSpawningCondition.java:24) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.condition.SpawningCondition.isSatisfiedBy(SpawningCondition.java:68) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.detail.SpawnDetail.isSatisfiedBy(SpawnDetail.java:78) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.spawner.Spawner$DefaultImpls.getMatchingSpawns(Spawner.java:42) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.spawner.TickingSpawner.getMatchingSpawns(TickingSpawner.java:31) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.selection.FlatContextWeightedSelector.getSelectionData(FlatContextWeightedSelector.java:79) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.selection.FlatContextWeightedSelector.select(FlatContextWeightedSelector.java:106) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.spawner.AreaSpawner.run(AreaSpawner.java:94) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.spawner.TickingSpawner.tick(TickingSpawner.java:71) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.SpawnerManager.onServerTick(SpawnerManager.java:58) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.events.ServerTickHandler.onTick(ServerTickHandler.java:20) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.Cobblemon$initialize$7.invoke(Cobblemon.java:368) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.Cobblemon$initialize$7.invoke(Cobblemon.java:368) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.reactive.ObservableSubscription.handle(ObservableSubscription.java:16) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.reactive.SimpleObservable.emit(SimpleObservable.java:39) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.forge.event.ForgePlatformEventHandler.onTick(ForgePlatformEventHandler.kt:172) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.forge.event.__ForgePlatformEventHandler_onTick_ServerTickEvent.invoke(.dynamic) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading,pl:eventbus:B} at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {} at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.2.17-universal.jar%23138!/:?] {re:classloading} at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23133!/:?] {re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23133!/:?] {re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23133!/:?] {re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:840) ~[?:?] {re:mixin}
    • okay i've managed to fix it. looks like i made the stupidest error known to man. i hadn't installed forge to the client, which i assumed only affected the launcher which wouldn't affect me because i used a third party one. evidently not. the more you know
    • tried a fresh install of above and beyond with java 8 installed. got a popup that says "Error: Unable to access jarfile forge-1.16.5-36.2.8.jar". every good programmer knows getting a different error means you've made progress!
    • https://paste.ee/p/Ntb3m
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.