Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.3] Dedicated Server Crash on Start


jstN0body
 Share

Recommended Posts

I can't run my mod on a dedicated server because of this? Is there any way to fix this?

java.lang.RuntimeException: Attempted to load class net/minecraft/client/renderer/entity/PlayerRenderer for invalid dist DEDICATED_SERVER
        at net.minecraftforge.fml.loading.RuntimeDistCleaner.processClassWithFlags(RuntimeDistCleaner.java:71) ~[forge.jar:34.1] {}
        at cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:85) ~[modlauncher-7.0.1.jar:?] {}
        at cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:119) ~[modlauncher-7.0.1.jar:?] {}
        at cpw.mods.modlauncher.TransformingClassLoader$DelegatedClassLoader.findClass(TransformingClassLoader.java:256) ~[modlauncher-7.0.1.jar:?] {}
        at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:135) ~[modlauncher-7.0.1.jar:?] {re:classloading}
        at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:97) ~[modlauncher-7.0.1.jar:?] {re:classloading}
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_271] {}
        at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:1.8.0_271] {}
        at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) ~[?:1.8.0_271] {}
        at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.8.0_271] {}
        at java.lang.Class.getConstructor(Unknown Source) ~[?:1.8.0_271] {}
        at net.minecraftforge.eventbus.api.EventListenerHelper.computeListenerList(EventListenerHelper.java:96) ~[eventbus-3.0.3-service.jar:?] {}
        at net.minecraftforge.eventbus.api.EventListenerHelper.getListenerListInternal(EventListenerHelper.java:63) ~[eventbus-3.0.3-service.jar:?] {}
        at net.minecraftforge.eventbus.api.EventListenerHelper.getListenerList(EventListenerHelper.java:48) ~[eventbus-3.0.3-service.jar:?] {}
        at net.minecraftforge.eventbus.EventBus.addToListeners(EventBus.java:263) ~[eventbus-3.0.3-service.jar:?] {}
        at net.minecraftforge.eventbus.EventBus.register(EventBus.java:256) ~[eventbus-3.0.3-service.jar:?] {}
        at net.minecraftforge.eventbus.EventBus.registerListener(EventBus.java:150) ~[eventbus-3.0.3-service.jar:?] {}
        at net.minecraftforge.eventbus.EventBus.lambda$null$6(EventBus.java:98) ~[eventbus-3.0.3-service.jar:?] {}
        at java.util.Optional.ifPresent(Unknown Source) ~[?:1.8.0_271] {}
        at net.minecraftforge.eventbus.EventBus.lambda$registerObject$7(EventBus.java:98) ~[eventbus-3.0.3-service.jar:?] {}
        at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source) ~[?:1.8.0_271] {}
        at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source) ~[?:1.8.0_271] {}
        at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source) ~[?:1.8.0_271] {}
        at java.util.stream.AbstractPipeline.copyInto(Unknown Source) ~[?:1.8.0_271] {}
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) ~[?:1.8.0_271] {}
        at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source) ~[?:1.8.0_271] {}
        at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source) ~[?:1.8.0_271] {}
        at java.util.stream.AbstractPipeline.evaluate(Unknown Source) ~[?:1.8.0_271] {}
        at java.util.stream.ReferencePipeline.forEach(Unknown Source) ~[?:1.8.0_271] {}
        at net.minecraftforge.eventbus.EventBus.registerObject(EventBus.java:94) ~[eventbus-3.0.3-service.jar:?] {}
        at net.minecraftforge.eventbus.EventBus.register(EventBus.java:120) ~[eventbus-3.0.3-service.jar:?] {}
        at com.github.jstN0body.shrinkmod.SizeMod.<init>(SizeMod.java:58) ~[?:1.0] {re:classloading}
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_271] {}
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_271] {}
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_271] {}
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_271] {}
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_271] {}
        at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:81) ~[?:34.1] {re:classloading}
        at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$5(ModContainer.java:111) ~[?:?] {re:classloading}
        at java.util.concurrent.CompletableFuture$AsyncRun.run(Unknown Source) [?:1.8.0_271] {}
        at java.util.concurrent.CompletableFuture$AsyncRun.exec(Unknown Source) [?:1.8.0_271] {}
        at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) [?:1.8.0_271] {}
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source) [?:1.8.0_271] {}
        at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) [?:1.8.0_271] {}
        at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) [?:1.8.0_271] {}
[m[1;31m[19:05:24] [main/FATAL] [ne.mi.fm.ModLoader/LOADING]: Failed to complete lifecycle event CONSTRUCT, 1 errors found
[m[32m[19:05:24] [main/INFO] [STDOUT/]: [net.minecraft.crash.CrashReport:func_85057_a:196]: Negative index in crash report handler (16/18)
[m[1;31m[19:05:24] [main/FATAL] [ne.mi.fm.se.ServerModLoader/]: Crash report saved to .\crash-reports\crash-2020-11-09_19.05.24-fml.txt
[m---- Minecraft Crash Report ----
// This doesn't make any sense!

Time: 11/9/20 7:05 PM
Description: Mod loading error has occurred

java.lang.Exception: Mod Loading has failed
        at net.minecraftforge.fml.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:85) ~[?:?] {re:classloading}
        at net.minecraftforge.fml.server.ServerModLoader.load(ServerModLoader.java:51) ~[?:?] {re:classloading}
        at net.minecraft.server.Main.main(Main.java:96) ~[?:?] {re:classloading}
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_271] {}
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_271] {}
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_271] {}
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_271] {}
        at net.minecraftforge.fml.loading.FMLServerLaunchProvider.lambda$launchService$0(FMLServerLaunchProvider.java:51) ~[forge.jar:34.1] {}
        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.server.ServerMain$Runner.runLauncher(ServerMain.java:63) [forge.jar:?] {}
        at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) [forge.jar:?] {}
        at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) [forge.jar:?] {}

 

Link to comment
Share on other sites

8 minutes ago, poopoodice said:

Attempted to load class net/minecraft/client/renderer/entity/PlayerRenderer for invalid dist DEDICATED_SERVER

https://mcforge.readthedocs.io/en/latest/concepts/sides/

You should also post all your code

Currently reading the docs, here's the code of the class where I'm getting the error just in case:

@Mod(SizeMod.MODID)
public class SizeMod {
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();

    public static final String MODID = "sizemod";
    public static final String VERSION = "1.0.0";

    public static float sizePercentage = 1.0f;


    public SizeMod() {


        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);


        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event)
    {
        // some preinit code

    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        // do something that can only be done on the client

    }

    private void enqueueIMC(final InterModEnqueueEvent event)
    {
        // some example code to dispatch IMC to another mod

    }

    private void processIMC(final InterModProcessEvent event)
    {
        // some example code to receive and process InterModComms from other mods

    }

    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        ModCommands.register(event.getServer().getCommandManager().getDispatcher());
    }

    @SubscribeEvent
    public void onSizeChange(PlayerEvent.Size event) {

        if (event.getEntity() instanceof PlayerEntity) {
            EntitySize newSize;
            switch (event.getPose()) {
                case CROUCHING:
                    newSize = EntitySize.fixed(0.6f * sizePercentage, 1.5f * sizePercentage);
                    break;

                case SWIMMING:
                case FALL_FLYING:
                    newSize = EntitySize.fixed(0.6f * sizePercentage, 0.6f * sizePercentage);
                    break;

                case SLEEPING:
                    newSize = EntitySize.fixed(0.2f * sizePercentage, 0.2f * sizePercentage);
                    break;

                default:
                    newSize = EntitySize.fixed(0.6f * sizePercentage, 1.8f * sizePercentage);
            }
            event.setNewSize(newSize);
            event.setNewEyeHeight(newSize.height * 0.9f);
        }
    }

    @SubscribeEvent
    public void preRenderPlayer(RenderPlayerEvent.Pre event) {
        event.getMatrixStack().push();
        event.getMatrixStack().scale(sizePercentage, sizePercentage, sizePercentage);
    }

    @SubscribeEvent
    public void postRenderPlayer(RenderPlayerEvent.Post event) {
        event.getMatrixStack().pop();
    }

    @SubscribeEvent
    public void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
        if (!(event.getEntity() instanceof PlayerEntity)) return;

        SizeMod.sizePercentage -= 0.01;
        for (ServerPlayerEntity player : event.getPlayer().getServer().getPlayerList().getPlayers()) {
            player.setBoundingBox(AxisAlignedBB.func_241550_g_(0.6, 1.8, 0.6));
            player.sendStatusMessage(new TranslationTextComponent("Your size is now: " +
                    new DecimalFormat("0.00").format(SizeMod.sizePercentage*100) + "%"), true);
        }
    }

    int hunger;
    float saturation;
    @SubscribeEvent
    public void startPlayerEat(LivingEntityUseItemEvent.Start event) {
        if (event.getItem().isFood() && event.getEntity() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getEntity();
            FoodStats foodStats = player.getFoodStats();
            hunger = foodStats.getFoodLevel();
            saturation = foodStats.getSaturationLevel();
        }
    }

    @SubscribeEvent
    public void finishPlayerEat(LivingEntityUseItemEvent.Finish event) {
        if (event.getItem().isFood() && event.getEntity() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getEntity();
            FoodStats foodStats = player.getFoodStats();
            hunger = foodStats.getFoodLevel() - hunger;
            saturation = foodStats.getSaturationLevel() - saturation;
            hunger *= (1 - sizePercentage);
            saturation *= (1 - sizePercentage);
            foodStats.addStats(Math.round(hunger), saturation);
        }
    }

    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            // register a new block here

        }
    }
}

 

Link to comment
Share on other sites

@Mod(SizeMod.MODID)
public class SizeMod {
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();

    public static final String MODID = "sizemod";
    public static final String VERSION = "1.1.2";

    public static float sizePercentage = 1.0f;


    public SizeMod() {

        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true));

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event)
    {
        // some preinit code
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        // do something that can only be done on the client

    }

    private void enqueueIMC(final InterModEnqueueEvent event)
    {
        // some example code to dispatch IMC to another mod
    }

    private void processIMC(final InterModProcessEvent event)
    {
        // some example code to receive and process InterModComms from other mods
    }


    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        ModCommands.register(event.getServer().getCommandManager().getDispatcher());
    }


    @SubscribeEvent
    public void onSizeChange(PlayerEvent.Size event) {

        if (event.getEntity() instanceof PlayerEntity) {
            EntitySize newSize;
            switch (event.getPose()) {
                case CROUCHING:
                    newSize = EntitySize.fixed(0.6f * sizePercentage, 1.5f * sizePercentage);
                    break;

                case SWIMMING:
                case FALL_FLYING:
                    newSize = EntitySize.fixed(0.6f * sizePercentage, 0.6f * sizePercentage);
                    break;

                case SLEEPING:
                    newSize = EntitySize.fixed(0.2f * sizePercentage, 0.2f * sizePercentage);
                    break;

                default:
                    newSize = EntitySize.fixed(0.6f * sizePercentage, 1.8f * sizePercentage);
            }
            event.setNewSize(newSize);
            event.setNewEyeHeight(newSize.height * 0.9f);
        }
    }

    @OnlyIn(Dist.CLIENT)
    @SubscribeEvent
    public void preRenderPlayer(RenderPlayerEvent.Pre event) {
        event.getMatrixStack().push();
        event.getMatrixStack().scale(sizePercentage, sizePercentage, sizePercentage);
    }

    @OnlyIn(Dist.CLIENT)
    @SubscribeEvent
    public void postRenderPlayer(RenderPlayerEvent.Post event) {
        event.getMatrixStack().pop();
    }


    @SubscribeEvent
    public void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
        if (!(event.getEntity() instanceof PlayerEntity)) return;

        SizeMod.sizePercentage -= 0.01;
        for (ServerPlayerEntity player : event.getPlayer().getServer().getPlayerList().getPlayers()) {
            player.setBoundingBox(AxisAlignedBB.func_241550_g_(0.6, 1.8, 0.6));
            player.sendStatusMessage(new TranslationTextComponent("Your size is now: " +
                    new DecimalFormat("0.00").format(SizeMod.sizePercentage*100) + "%"), true);
        }
    }

    int hunger;
    float saturation;
    @SubscribeEvent
    public void startPlayerEat(LivingEntityUseItemEvent.Start event) {
        if (event.getItem().isFood() && event.getEntity() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getEntity();
            FoodStats foodStats = player.getFoodStats();
            hunger = foodStats.getFoodLevel();
            saturation = foodStats.getSaturationLevel();
        }
    }

    @SubscribeEvent
    public void finishPlayerEat(LivingEntityUseItemEvent.Finish event) {
        if (event.getItem().isFood() && event.getEntity() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getEntity();
            FoodStats foodStats = player.getFoodStats();
            hunger = foodStats.getFoodLevel() - hunger;
            saturation = foodStats.getSaturationLevel() - saturation;
            hunger *= (1 - sizePercentage);
            saturation *= (1 - sizePercentage);
            foodStats.addStats(Math.round(hunger), saturation);
        }
    }

    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            // register a new block here

        }
    }
}

 

Link to comment
Share on other sites

By the way:

This:

On 11/9/2020 at 6:36 PM, jstN0body said:

        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

And this:

Quote

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);

Do the exact same thing, just in a different way. @EventBusSubscriber also does this. Th only difference is that there are two different busses (the mod bus and the forge bus) and one of them is for FML events ("life cycle events" which are on the mod event bus) and the rest are for game events (the forge event bus). You should use two different classes for the two different types of events, separating out all the client stuff to another third (and possibly fourth) class.

 

And personally I'd use the @EventBusSubscriber annotation, because then it's very easy to tell what bus a given set of events is for.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Howdy

 

You might get some inspiration from this class, it shows the method I've used to make the example mod work with Dedicated Server:

https://github.com/TheGreyGhost/MinecraftByExample/blob/master/src/main/java/minecraftbyexample/MinecraftByExample.java

 

The key bits are:

 

    
@Mod(MinecraftByExample.MODID)
public class MinecraftByExample {

  public MinecraftByExample() {
	// We need to split the registration of events into:
    // 1) "Common" events that are executed on a dedicated server and also on an integrated client + server installation
    // 2) "Client only" events that are not executed on a dedicated server.
    // If you aren't careful to split these into two parts, your mod will crash when installed on a dedicated server
    // It doesn't matter if your client-only code is never actually called; simply referencing the class is often enough to
    //   cause a crash.

    registerCommonEvents();
    DistExecutor.runWhenOn(Dist.CLIENT, () -> MinecraftByExample::registerClientOnlyEvents);
  }
}
  public static void registerCommonEvents() {
    MOD_EVENT_BUS.register(minecraftbyexample.mbe01_block_simple.StartupCommon.class);
  }

  public static void registerClientOnlyEvents() {
    MOD_EVENT_BUS.register(minecraftbyexample.mbe01_block_simple.StartupClientOnly.class);
  }


public class StartupCommon
{
  public static BlockSimple blockSimple;  // this holds the unique instance of your block
  public static BlockItem itemBlockSimple;  // this holds the unique instance of the ItemBlock corresponding to your block

  @SubscribeEvent
  public static void onBlocksRegistration(final RegistryEvent.Register<Block> blockRegisterEvent) {
    blockSimple = (BlockSimple)(new BlockSimple().setRegistryName("minecraftbyexample", "mbe01_block_simple_registry_name"));
    blockRegisterEvent.getRegistry().register(blockSimple);
  }
}
    
public class StartupClientOnly
{
  /**
   * Tell the renderer this is a solid block
   * @param event
   */
  @SubscribeEvent
  public static void onClientSetupEvent(FMLClientSetupEvent event) {
    RenderTypeLookup.setRenderLayer(StartupCommon.blockSimple, RenderType.getSolid());
  }
}

 

Link to comment
Share on other sites

Ok, I moved the render events to a class called Render, but I still have the same problem where I shrink for a split second and go back to normal. It works fine singleplayer, just not on a server. I can however, change my size in singleplayer and then connect to the server and remain that same size. Any ideas on what's happening?

@Mod(SizeMod.MODID)
public class SizeMod {
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();

    public static final String MODID = "sizemod";
    public static final String VERSION = "1.1.2";

    public static float sizePercentage = 1.0f;


    public SizeMod() {

        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true));

        DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> Render::new);

        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event)
    {
        // some preinit code
    }

    private void doClientStuff(final FMLClientSetupEvent event) {

    }

    private void enqueueIMC(final InterModEnqueueEvent event)
    {
        // some example code to dispatch IMC to another mod
    }

    private void processIMC(final InterModProcessEvent event)
    {
        // some example code to receive and process InterModComms from other mods
    }


    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        ModCommands.register(event.getServer().getCommandManager().getDispatcher());
    }

    @SubscribeEvent
    public void onSizeChange(PlayerEvent.Size event) {

        if (event.getEntity() instanceof PlayerEntity) {
            EntitySize newSize;
            switch (event.getPose()) {
                case CROUCHING:
                    newSize = EntitySize.fixed(0.6f * sizePercentage, 1.5f * sizePercentage);
                    break;

                case SWIMMING:
                case FALL_FLYING:
                    newSize = EntitySize.fixed(0.6f * sizePercentage, 0.6f * sizePercentage);
                    break;

                case SLEEPING:
                    newSize = EntitySize.fixed(0.2f * sizePercentage, 0.2f * sizePercentage);
                    break;

                default:
                    newSize = EntitySize.fixed(0.6f * sizePercentage, 1.8f * sizePercentage);
            }
            event.setNewSize(newSize);
            event.setNewEyeHeight(newSize.height * 0.9f);
        }
    }


    @SubscribeEvent
    public void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
        if (!(event.getEntity() instanceof PlayerEntity)) return;

        SizeMod.sizePercentage -= 0.01;
        for (ServerPlayerEntity player : event.getPlayer().getServer().getPlayerList().getPlayers()) {
            player.setBoundingBox(AxisAlignedBB.func_241550_g_(0.6, 1.8, 0.6));
            player.sendStatusMessage(new TranslationTextComponent("Your size is now: " +
                    new DecimalFormat("0.00").format(SizeMod.sizePercentage*100) + "%"), true);
        }
    }

    int hunger;
    float saturation;
    @SubscribeEvent
    public void startPlayerEat(LivingEntityUseItemEvent.Start event) {
        if (event.getItem().isFood() && event.getEntity() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getEntity();
            FoodStats foodStats = player.getFoodStats();
            hunger = foodStats.getFoodLevel();
            saturation = foodStats.getSaturationLevel();
        }
    }

    @SubscribeEvent
    public void finishPlayerEat(LivingEntityUseItemEvent.Finish event) {
        if (event.getItem().isFood() && event.getEntity() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getEntity();
            FoodStats foodStats = player.getFoodStats();
            hunger = foodStats.getFoodLevel() - hunger;
            saturation = foodStats.getSaturationLevel() - saturation;
            hunger *= (1 - sizePercentage);
            saturation *= (1 - sizePercentage);
            foodStats.addStats(Math.round(hunger), saturation);
        }
    }

    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            // register a new block here

        }
    }
}
public class Render {

    public Render() {
        MinecraftForge.EVENT_BUS.register(this);
    }

    @SubscribeEvent
    public void preRenderPlayer(RenderPlayerEvent.Pre event) {
        event.getMatrixStack().push();
        event.getMatrixStack().scale(SizeMod.sizePercentage, SizeMod.sizePercentage, SizeMod.sizePercentage);
    }

    @SubscribeEvent
    public void postRenderPlayer(RenderPlayerEvent.Post event) {
        event.getMatrixStack().pop();
    }
}

 

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

    • I wander how to use World.addParticle to add custom particle effect, or is there any other ways to add? Or is there anything wrong with my particle effect?
    • My friend plays in 1.16.5 and when he wants to start minecraft with forge but does not leave it, we already tried to update forge at that moment but we have not tried it for a long time, even though I think that will not fix it, can someone help me with this? please (I used a translator in case something was not understood well)
    • These are my particle effect classes, they are all copied from a tutorial.   public class Juan1ParticalType extends ParticleType { public Juan1ParticalType() { super(false, Juan1ParticalData.DESERIALIZER); } @Override public Codec<Juan1ParticalData> func_230522_e_() { return Codec.unit(new Juan1ParticalData(new Vector3d(0, 0, 0), new Color(0xF63900), 0)); } }   public class Juan1ParticalData implements IParticleData { private final Vector3d speed; private final Color color; private final float diameter; public static final IDeserializer<Juan1ParticalData> DESERIALIZER = new IDeserializer<Juan1ParticalData>() { @Override public Juan1ParticalData deserialize(ParticleType<Juan1ParticalData> particleTypeIn, StringReader reader) throws CommandSyntaxException { final int MIN_COLOUR = 0; final int MAX_COLOUR = 255;reader.expect(' '); double speedX = reader.readDouble(); reader.expect(' '); double speedY = reader.readDouble(); reader.expect(' '); double speedZ = reader.readDouble(); reader.expect(' '); int red = MathHelper.clamp(reader.readInt(), MIN_COLOUR, MAX_COLOUR); reader.expect(' '); int green = MathHelper.clamp(reader.readInt(), MIN_COLOUR, MAX_COLOUR); reader.expect(' '); int blue = MathHelper.clamp(reader.readInt(), MIN_COLOUR, MAX_COLOUR);reader.expect(' ');  int alpha = MathHelper.clamp(reader.readInt(), 1, MAX_COLOUR);reader.expect(' '); float diameter = reader.readFloat();  return new Juan1ParticalData(new Vector3d(speedX, speedY, speedZ), new Color(red, green, blue, alpha), diameter); } @Override public Juan1ParticalData read(ParticleType<Juan1ParticalData> particleTypeIn, PacketBuffer buffer) { final int MIN_COLOUR = 0; final int MAX_COLOUR = 255; double speedX = buffer.readDouble(); double speedY = buffer.readDouble(); double speedZ = buffer.readDouble(); int red = MathHelper.clamp(buffer.readInt(), MIN_COLOUR, MAX_COLOUR); int green = MathHelper.clamp(buffer.readInt(), MIN_COLOUR, MAX_COLOUR); int blue = MathHelper.clamp(buffer.readInt(), MIN_COLOUR, MAX_COLOUR); int alpha = MathHelper.clamp(buffer.readInt(), 1, MAX_COLOUR); float diameter = buffer.readFloat(); return new Juan1ParticalData(new Vector3d(speedX, speedY, speedZ), new Color(red, green, blue, alpha), diameter); } }; public Juan1ParticalData(Vector3d speed, Color color, float diameter) { this.speed = speed; this.color = color; this.diameter = diameter; } @Override public ParticleType<?> getType() { return Utils.ParticleRegistry.JUAN_1_PARTICLE.get(); } @Override public void write(PacketBuffer buffer) { buffer.writeDouble(this.speed.x); buffer.writeDouble(this.speed.y); buffer.writeDouble(this.speed.z); buffer.writeInt(this.color.getRed()); buffer.writeInt(this.color.getGreen()); buffer.writeInt(this.color.getBlue()); buffer.writeInt(this.color.getAlpha()); buffer.writeFloat(this.diameter); } @Override public String getParameters() { return String.format(Locale.ROOT, "%s %.2f %i %i %i %i %.2d %.2d %.2d", this.getType().getRegistryName(), diameter, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha(), speed.getX(), speed.getY(), speed.getZ()); } public Vector3d getSpeed() { return speed; } public Color getColor() { return color; } public float getDiameter() { return diameter; } }   public class Juan1Particle extends SpriteTexturedParticle { public Juan1Particle(ClientWorld world, double x, double y, double z, Vector3d speed, Color color, float diameter) { super(world, x, y, z, speed.x, speed.y, speed.z); maxAge = 100; setColor(color.getRed() / 255F,color.getGreen() / 255F,color.getBlue() / 255); this.setAlphaF(color.getAlpha()); final float PARTICLE_SCALE_FOR_ONE_METER = 0.1F; particleScale = PARTICLE_SCALE_FOR_ONE_METER * diameter; this.canCollide = true; } @Override public IParticleRenderType getRenderType(){ return IParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } }   public class Juan1ParticleFactory implements IParticleFactory<Juan1ParticalData> { private final IAnimatedSprite sprites; public Juan1ParticleFactory(IAnimatedSprite sprite) { this.sprites = sprite; } @Override public Particle makeParticle(Juan1ParticalData typeIn, ClientWorld worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { Juan1Particle particle = new Juan1Particle(worldIn, x, y, z, typeIn.getSpeed(), typeIn.getColor(), typeIn.getDiameter()); particle.selectSpriteWithAge(sprites); return particle; } }
    • This is where I want to call the addParticle() method, it is in the livingTick() in an entity. But it shows no particle effect. @Override public void livingTick() { double x = rand.nextGaussian() * 0.02D; double y = rand.nextGaussian() * 0.02D; double z = rand.nextGaussian() * 0.02D; double px = this.getPosX() + 4.0D * rand.nextDouble() - 2.0D; double py = this.getPosY() + rand.nextDouble() - 0.5D; double pz = this.getPosZ() + 4.0D * rand.nextDouble() - 2.0D; world.addParticle(new Juan1ParticalData(new Vector3d(x, y, z), new Color(0xae6be2), 0), px, py, pz, x, y, z);  } When I change "new Juan1ParticalData(new Vector3d(x, y, z), new Color(0xae6be2), 0)" to "ParticleTypes.DRAGON_BREATH" , the particle effects appeared.
    • can you get any useful info from your crash reports?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.