Jump to content

Getting Error while Creating a new Explosion (Writing into PalettedContainer from multiple threads)


IDK_

Recommended Posts

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

Link to comment
Share on other sites

34 minutes ago, IDK_ said:

Please give me some help with this Problem.

You are approaching this the wrong way I am afraid. You cannot create an explosion on the client-side, and you cannot have mutable static variables like you have. If I were you, I would override the appropriate methods in your boom rod item class (such as onUse(), onItemUseFinish() etc) and create the explosion there. That way you can skip the event subscribers altogether.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • KLIK DISINI UNTUK DAFTAR       WsoSlot88 Situs Bandar Togel Terpercaya dengan Hadiah 4D Tertinggi yaitu 10 juta WsoSlot88 adalah BO Agen Togel Terpercaya yang sudah berdiri sejak tahun 2016 yang terkenal dengan proses transaksi deposit dan withdraw yang super cepat serta jaminan pembayaran untuk berapa pun kemenangan yang didapat oleh para member nya. Jadi anda para pecinta game Togel Online dan Slot Gacor tidak perlu takut atau ragu bermain di BO WsoSlot88, karena jika anda Jackpot Paus berapapun, pasti akan dibayar lunas oleh WsoSlot88.   67 Pasaran Togel yang paling dicari oleh para pecinta Togel Online yaitu : - Pasaran Togel Hongkong (HK) - Pasaran Togel Sydney (SDY) - Pasaran Togel Singapore (SGP) - Pasaran Togel Cambodia (CM) - Pasaran Togel Taiwan (TW) - Pasaran Togel Jepang (JPN) - Pasaran Togel China (CN) - Pasaran Togel Chicago - Pasaran Togel Malaysia - Pasaran Togel Vegas - Pasaran Togel Miami - Pasaran Togel Vietnam - Pasaran Togel Carolina - Pasaran Togel Bullseye - Dan masih banyak pasaran togel terkenal lainnya
    • I can play my server & others can connect to it but it cannot load certain chunks & times out because it's bottlenecked by the default 4GB. I know this to be the case because when copy+pastaing the exact server world into curseforge singleplayer with 8G+, all the heavy chunks load in fine.  I have JavaSDK 17.0.9 x64-bit & reinstalled twice already as well as trying with Java 8 also installed & without.  I tried using: java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.20.1-47.2.0/win_args.txt %* pause but all that gives me is: Error: Could not find or load main class java Caused by: java.lang.ClassNotFoundException: java  Any ideas or help would be appreciate. 
    • KLIK DISINI UNTUK DAFTAR     Situs Slot Thailand Terpercaya adalah situs yang menyediakan permainan slot online dengan tema dan layanan yang sesuai dengan kebutuhan dan preferensi pemain asal Thailand. Situs-situs ini biasanya menawarkan permainan slot dengan server khusus yang berasal dari Thailand, yang diklaim memiliki tingkat kemenangan yang tinggi dan mudah mendapatkan jackpot. Beberapa situs juga menyediakan permainan slot dengan server dari negara lain, seperti Rusia dan Singapura, yang juga populer di kalangan pemain Thailand.  
    • I was trying to use viaforge (latest version) on forge 1.20.2 and then it crashed showing exit code 1 heres the log : 04Dec2023 11:40:52.058] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, Goldenretriver, --version, 1.16.5-forge-36.2.34, --gameDir, C:\Users\rashr\AppData\Roaming\.minecraft, --assetsDir, C:\Users\rashr\AppData\Roaming\.minecraft\assets, --assetIndex, 1.16, --uuid, a688ba406e4f4635a428d7555a467474, --accessToken, ????????, --userType, msa, --versionType, release, --launchTarget, fmlclient, --fml.forgeVersion, 36.2.34, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20210115.111550] [04Dec2023 11:40:52.061] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 8.1.3+8.1.3+main-8.1.x.c94d18ec starting: java version 1.8.0_51 by Oracle Corporation [04Dec2023 11:40:52.071] [main/DEBUG] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Found launch services [minecraft,testharness,fmlclient,fmlserver] [04Dec2023 11:40:52.075] [main/WARN] [cpw.mods.modlauncher.SecureJarHandler/]: LEGACY JDK DETECTED, SECURED JAR HANDLING DISABLED [04Dec2023 11:40:52.082] [main/DEBUG] [cpw.mods.modlauncher.NameMappingServiceHandler/MODLAUNCHER]: Found naming services : [] [04Dec2023 11:40:52.118] [main/DEBUG] [cpw.mods.modlauncher.LaunchPluginHandler/MODLAUNCHER]: Found launch plugins: [mixin,eventbus,object_holder_definalize,runtime_enum_extender,accesstransformer,capability_inject_definalize,runtimedistcleaner] [04Dec2023 11:40:52.125] [main/DEBUG] [cpw.mods.modlauncher.TransformationServicesHandler/MODLAUNCHER]: Discovering transformation services [04Dec2023 11:40:52.132] [main/DEBUG] [cpw.mods.modlauncher.TransformationServicesHandler/MODLAUNCHER]: Found additional transformation services from discovery services: [C:\Users\rashr\AppData\Roaming\.minecraft\mods\viaforge-1.12.2-3.4.3.jar]
  • Topics

×
×
  • Create New...

Important Information

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