Jump to content

[1.16.3] Dedicated Server Crash on Start


jstN0body

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



×
×
  • Create New...

Important Information

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