In my first and until now very small MC 1.16.3 mod I wanted to create a staff wich causes Explosion with a Particle line just for fun and to try out what you can actualy modify with Modding.
But now very often the Player interacts with this Staff (Sometimes the game freezes for a while and then everthing is fine)the game crashes with the following crash log:
[14:07:57] [Render thread/FATAL] [minecraft/Minecraft]: Reported exception thrown!
net.minecraft.crash.ReportedException: Writing into PalettedContainer from multiple threads
at net.minecraft.util.palette.PalettedContainer.lock(PalettedContainer.java:45) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
at net.minecraft.util.palette.PalettedContainer.lockedSwap(PalettedContainer.java:110) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
at net.minecraft.world.chunk.ChunkSection.setBlockState(ChunkSection.java:60) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
at net.minecraft.world.chunk.ChunkSection.setBlockState(ChunkSection.java:54) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
at net.minecraft.world.chunk.Chunk.setBlockState(Chunk.java:256) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
at net.minecraft.world.World.func_241211_a_(World.java:228) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
at net.minecraft.world.World.setBlockState(World.java:205) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
at net.minecraftforge.common.extensions.IForgeBlock.onBlockExploded(IForgeBlock.java:861) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
at net.minecraftforge.common.extensions.IForgeBlockState.onBlockExploded(IForgeBlockState.java:759) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
at net.minecraft.world.Explosion.doExplosionB(Explosion.java:261) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
at net.minecraft.world.World.func_230546_a_(World.java:624) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
at net.minecraft.world.World.createExplosion(World.java:617) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
at com.idk.firstmod.eventhandler.client.InteractEvent.BOOM(InteractEvent.java:140) ~[main/:?] {re:classloading}
at com.idk.firstmod.eventhandler.client.InteractEvent.Tick_Event(InteractEvent.java:98) ~[main/:?] {re:classloading}
at net.minecraftforge.eventbus.ASMEventHandler_7_InteractEvent_Tick_Event_TickEvent.invoke(.dynamic) ~[?:?] {}
at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-3.0.3-service.jar:?] {}
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:297) ~[eventbus-3.0.3-service.jar:?] {}
at net.minecraftforge.fml.hooks.BasicEventHooks.onRenderTickStart(BasicEventHooks.java:75) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:988) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
at net.minecraft.client.Minecraft.run(Minecraft.java:589) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] {}
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?] {}
at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-7.0.1.jar:?] {}
at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {}
Caused by: java.lang.IllegalStateException
at net.minecraft.util.palette.PalettedContainer.lock(PalettedContainer.java:42) ~[forge-1.16.3-34.1.19_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have found out that the createExplosion method causes this crash but I dont know what to do now. Ive also read that may another event would fix this problem but I dont know wich I should use instead.
Here is the Code of my Event Class
package com.idk.firstmod.eventhandler.client;
import com.idk.firstmod.Main;
import com.idk.firstmod.content.itemdata.equipment.toolsdata.ModRods;
import com.idk.firstmod.content.particles.ModParticlesRegistering;
import com.idk.firstmod.util.datatypes.Playerholder;
import com.idk.firstmod.util.datatypes.Spec.DataType_I_1;
import com.idk.firstmod.util.math.AdvancedVector3d;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.entity.ai.goal.AvoidEntityGoal;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particles.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.NoteBlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.graalvm.compiler.nodes.PiNode;
@Mod.EventBusSubscriber(modid = Main.ModID,bus = Mod.EventBusSubscriber.Bus.FORGE,value = Dist.CLIENT)
public class InteractEvent {
protected static final int EXPLOSIONRADIUS = 100;
protected static final int MAXRANGE=30;
protected static final double PRECISION =1000D;
protected static final float SPEED_ =0.8f;
//tells if the Player has used the Stuff
protected static boolean BOOM_Test=false;
private static int Stopper=0;
//To hold the Player and some other Variables just like the position if the player during the Event was fired:
//isValid= if entry is usable(!=null or too old)
//Proccount Number of Processes for this Event
protected static Playerholder<DataType_I_1> Buffer= new Playerholder<DataType_I_1>(6);
@SubscribeEvent
public static void PlayerInteractions(PlayerInteractEvent Event){
PlayerEntity Player = Event.getPlayer();
if(Player.getHeldItemMainhand().getItem()== ModRods.BOOM_ROD.get()) {
Vector3d PlayerLookingDirection = Player.getLookVec();
Vector3d PlayerLocation = Player.getPositionVec();
if(!Buffer.OUTOFSIZE()) {
Buffer.SetPlayerandData(new DataType_I_1(PlayerLocation, PlayerLookingDirection, 0), Player);
BOOM_Test=true;
}
}
}
@SubscribeEvent
public static void Tick_Event(TickEvent Event) {
if (BOOM_Test) {
Stopper++;
if (Stopper > (1/SPEED_)*2.5){Stopper=0;
Playerholder<DataType_I_1>.Pattern<DataType_I_1>[] Data = Buffer.Get();
for (int i = 0; i < Data.length; i++) {
if (!Data[i].isValid) {
continue;
}
Vector3d tst = AdvancedVector3d.Multiply((Data[i].Data.Proccount), Data[i].Data.EventPlayerLookingDir);
Vector3d vec = new Vector3d(Math.round((tst.x + Data[i].Data.EventCoor.x) * PRECISION) / PRECISION, Math.round((tst.y + Data[i].Data.EventCoor.y) * PRECISION) / PRECISION, Math.round((tst.z + Data[i].Data.EventCoor.z) * PRECISION) / PRECISION);
Data[i].Player.world.addParticle(ModParticlesRegistering.FIRSTPARTICLE.get(), vec.x, vec.y, vec.z, 0, 0, 0);
if (!Data[i].Player.world.isAirBlock(new BlockPos(vec.x, vec.y, vec.z))) {
CrExp(vec,Data,i);
double ExplosionDistance = vec.distanceTo(Data[i].Data.EventCoor);
if (!Data[i].Player.isCreative()) {
if (ExplosionDistance < 50) {
Data[i].Player.setHealth((float) (Data[i].Player.getHealth() - (EXPLOSIONRADIUS / ExplosionDistance)) * 1.0f);//rework
}
}
Data[i].isValid = false;
BOOM_Test = isAlive(Data);
return;
} else if (Data[i].Data.Proccount > MAXRANGE) {
Data[i].isValid = false;
BOOM_Test = isAlive(Data);
return;
}
Data[i].Data.Proccount++;
return;
}
}
}
}
private static boolean isAlive(Playerholder<?>.Pattern<?>[] obj) {
for (int i = 0; i < obj.length; i++) {
if(obj[i].isValid==true){
return true;
}
}
return false;
}
public static void CrExp(Vector3d vec, Playerholder<DataType_I_1>.Pattern<DataType_I_1>[]Data,int i) {
Data[i].Player.world.createExplosion(Data[i].Player,vec.x,vec.y,vec.z,EXPLOSIONRADIUS,true, Explosion.Mode.DESTROY);
}
}
Please give me some help with this Problem.
Thanks