Jump to content

[SOLVED] [1.19.2] My method call is not changing my entity's texture


TheMajorN
 Share

Recommended Posts

Heya, so I'll explain this in the clearest way I can, but forgive me if it gets confusing:

I'm creating a behavior for my entity, where every now and then it petrifies and animates from statue to golem (It's a tuff golem, I wish it won so I'm making it myself).

I have a method to petrify it that looks like the following (There's also a complimentary animate() method that does the exact opposite):

public void petrify() {
        this.isPetrifying = true;	// The animation controller sets this to false when it's done animating
        this.setSpeed(0.0F);
        this.isAnimated = false;
        this.isPetrified = true;
    }

When it's petrified, I have it set so that it's texture changes to match the petrification.  For testing purposes, I made it so that whenever I right click it with the tuff block, it will induce petrification and animation. <- This changes the texture no problem.

Here's the snippet of code that induces petrification in the mobInteract method in the entity class:

if (itemInPlayerHand.is(Items.TUFF) && player.isCrouching()) {
            if (this.isAnimated) {
                petrify();
            } else {
                animate();
            }
        }

Here's what it looks like in the model class:

@Override
    public ResourceLocation getTextureResource(TuffGolemEntity object) {
        if (object.isPetrified()) {
            return  new ResourceLocation(TuffGolem.MOD_ID, "textures/entities/tuff_golem_petrified.png");
        } else {
            return  new ResourceLocation(TuffGolem.MOD_ID, "textures/entities/tuff_golem.png");
        }
    }

However, when I use the behavior, I call upon this exact method.  When this happens, the movement speed reduces to zero, but the texture doesn't change despite the entity being marked as petrified.  I'm thinking it somehow got convoluted or for some reason the change isn't making it to the model class.

Here's what the behavior method looks like:

protected void start(ServerLevel level, TuffGolemEntity tuffGolem, long l) {
        if (tuffGolem.isPetrified()) {
            tuffGolem.animate();
            TuffGolem.LOGGER.info("Tuff Golem Animated!"); // for testing
        } else {
            tuffGolem.petrify();
            TuffGolem.LOGGER.info("Tuff Golem Petrified!"); // for testing
        }
        tuffGolem.playSound(getAnimateOrPetrifySound);
    }

Here's the full behavior class if you'd like to take a look: https://github.com/TheMajorN/Tuff-Golem/blob/master/src/main/java/com/themajorn/tuffgolem/common/behaviors/PetrifyOrAnimate.java

Here's the full entity class as well: https://github.com/TheMajorN/Tuff-Golem/blob/master/src/main/java/com/themajorn/tuffgolem/common/entities/TuffGolemEntity.java#L242

And finally here's the full model class: https://github.com/TheMajorN/Tuff-Golem/blob/master/src/main/java/com/themajorn/tuffgolem/client/models/TuffGolemModel.java

 

I'd just appreciate any indications as to why I can induce the new texture in the mobInteract method, but can't change the texture with the exact same method in the behavior class.

Edited by TheMajorN
Issue resolved
Link to comment
Share on other sites

Your behaviour class runs on the server. While the mobInteract runs on both the client and server.

https://forge.gemwire.uk/wiki/Sides

So you are only modifying that value on the server. But it needs to be on the client for rendering.

You should define the petrified flag like you have the cloak color so the data is synched from the server to the client.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Hey warjort, I'm fairly new to entity data syncing, and I don't think I did it right.  It still isn't working in the game.

I made the variable in my entity class:

private static final EntityDataAccessor<Byte> DATA_IS_PETRIFIED = SynchedEntityData.defineId(TuffGolemEntity.class, EntityDataSerializers.BYTE);

And added it to the define, addSaveData and addSaveData methods:

protected void defineSynchedData() {
        super.defineSynchedData();
        this.entityData.define(DATA_FLAGS_ID, (byte)0);
        this.entityData.define(DATA_CLOAK_COLOR, DyeColor.WHITE.getId());
        this.entityData.define(DATA_IS_PETRIFIED, isPetrified());
    }

    public void addAdditionalSaveData(CompoundTag tag) {
        super.addAdditionalSaveData(tag);
        tag.put("Inventory", this.inventory.createTag());
        tag.putBoolean("PlayerCreated", this.isPlayerCreated());
        tag.putBoolean("isPetrified", this.isPetrified());
        tag.putByte("CloakColor", (byte)this.getCloakColor().getId());
    }

    public void readAdditionalSaveData(CompoundTag tag) {
        super.readAdditionalSaveData(tag);
        this.inventory.fromTag(tag.getList("Inventory", 10));
        this.setPlayerCreated(tag.getBoolean("PlayerCreated"));
        this.setPetrified(tag.getBoolean("isPetrified"));
        if (tag.contains("CloakColor", 99)) {
            this.setCloakColor(DyeColor.byId(tag.getInt("CloakColor")));
        }
    }

For the readAdditionalSaveData method I took from the setPlayerCreated method and tried to make the setPetrified equivalent:

public void setPetrified(boolean petrified) {
        byte b0 = this.entityData.get(DATA_IS_PETRIFIED);
        if (petrified) {
            this.entityData.set(DATA_IS_PETRIFIED, (byte)(b0 | 1));
        } else {
            this.entityData.set(DATA_IS_PETRIFIED, (byte)(b0 & -2));
        }
    }

Am I missing anything?

Link to comment
Share on other sites

You should just remove the normal isPetrified field.

Then make your isPetrified()/setPetrified() access the entityData.

 

Just doing isPetrifed = false isn't going to call setPetrified() and so it won't sync to the client.

Similarly doing if (isPetrified) on the client isn't going reference the entityData which has the value sent from the server.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

  • TheMajorN changed the title to [SOLVED] [1.19.2] My method call is not changing my entity's texture

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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello, I am currently trying to publish my mod. It works fine apart from that, but when publishing following error comes up: Execution failed for task ':publishMavenJavaPublicationToMavenRepository'. > Failed to publish publication 'mavenJava' to repository 'maven' > Invalid publication 'mavenJava': artifactId (AbsolutelyUnbreakable - 1.18.2) is not a valid Maven identifier ([A-Za-z0-9_\-.]+). I don't know what causes this as it definitely used to work completely fine.   I appreciate any help
    • The imgur link shows a memory dump of the crash but it's hard to get a profile of the exact moment of the crash since it happen pretty randomly
    • Im trying to tun a modded forge serve on a google cloud VM, (not the fist time I do this) so when I run the server locally, evererything works ok, but qhen I start the server online on the VM mods are loaded, shown, but they wont work, like i can get nods items from creative but cant place them beacuse they dissapear. The erro that is Shown on logs is like this Missing Datapack Mod:"Mod name"                                      so like that with a few of them
    • okey thanks for leting me know of the dc!
    • Some weeks ago I played Minecraft 1.19.3 with forge 44.1.0,today I changed the version of forge to 44.1.8,and add optifine,then the game crashed. I have tried any older versions of forge,but none of them worked.And I also tried reinstalling Minecraft 1.19.3 or optifine,but they also didn't work.Removing forge is working but I can't use mods so that I can't remove forge.Who knows the solution?Thanks! 😖 Here's the crash report: ---- Minecraft Crash Report ---- // Daisy, daisy... Time: 2023-02-05 16:59:24 Description: Rendering overlay java.lang.NoClassDefFoundError: net/minecraftforge/common/extensions/IForgeModelBaker     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {}     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:119) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.6.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {}     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:119) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.6.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at net.minecraft.client.resources.model.ModelBakery.lambda$bakeModels$9(ModelBakery.java:209) ~[client-1.19.3-20221207.122022-srg.jar%23162!/:?] {re:classloading,pl:accesstransformer:B,xf:OptiFine:default}     at java.util.HashMap$KeySet.forEach(HashMap.java:1008) ~[?:?] {}     at net.minecraft.client.resources.model.ModelBakery.m_245909_(ModelBakery.java:204) ~[client-1.19.3-20221207.122022-srg.jar%23162!/:?] {re:classloading,pl:accesstransformer:B,xf:OptiFine:default}     at net.minecraft.client.resources.model.ModelManager.m_245476_(ModelManager.java:166) ~[client-1.19.3-20221207.122022-srg.jar%23162!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.resources.model.ModelManager.m_246937_(ModelManager.java:89) ~[client-1.19.3-20221207.122022-srg.jar%23162!/:?] {re:classloading,pl:runtimedistcleaner:A}     at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646) ~[?:?] {}     at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483) ~[?:?] {}     at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}     at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {re:computing_frames}     at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {re:computing_frames}     at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {} Caused by: java.lang.ClassNotFoundException: net.minecraftforge.common.extensions.IForgeModelBaker     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.6.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     ... 28 more A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {}     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:119) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.6.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.6.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {} -- Overlay render details -- Details:     Overlay name: net.minecraft.client.gui.screens.LoadingOverlay Stacktrace:     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:1337) ~[client-1.19.3-20221207.122022-srg.jar%23162!/:?] {re:classloading,pl:accesstransformer:B,xf:OptiFine:default}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1135) ~[client-1.19.3-20221207.122022-srg.jar%23162!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:713) ~[client-1.19.3-20221207.122022-srg.jar%23162!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.m_239872_(Main.java:212) ~[1.19.3.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:51) ~[1.19.3.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:27) ~[fmlloader-1.19.3-44.1.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {} -- Last reload -- Details:     Reload number: 1     Reload reason: initial     Finished: No     Packs: vanilla  
  • Topics

×
×
  • Create New...

Important Information

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