Jump to content

Recommended Posts

Posted

Hi mates!

I´m a newby at coding forge and now I have a problem with my mobentity "Beetle". It works fine on client side but when i gradlew and use it on my server it crashes. I recognize, that there is a problem with registring the entity render but I can`t figure out what the correct syntax should be, to add to the ClientProxy.I didn`t add the clientproxy here, because I tried around, searching the foren, but could not find any relevant results....  :-\

Pls would anyone so kind and give me an example how to write this...

 

Thanks for your help in advance,

Norzeteus

 

Servercrashlog:

 

---- Minecraft Crash Report ----

// Oops.

 

Time: 01.10.16 16:45

Description: Exception in server tick loop

 

net.minecraftforge.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraft/client/renderer/entity/Render

at net.minecraftforge.fml.common.LoadController.transition(LoadController.java:186)

at net.minecraftforge.fml.common.Loader.loadMods(Loader.java:562)

at net.minecraftforge.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:97)

at net.minecraftforge.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:328)

at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:121)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:431)

at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/renderer/entity/Render

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at net.minecraftforge.fml.common.FMLModContainer.constructMod(FMLModContainer.java:481)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

at com.google.common.eventbus.EventBus.post(EventBus.java:275)

at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:235)

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:213)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

at com.google.common.eventbus.EventBus.post(EventBus.java:275)

at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:142)

at net.minecraftforge.fml.common.Loader.loadMods(Loader.java:531)

... 5 more

Caused by: java.lang.ClassNotFoundException: net.minecraft.client.renderer.entity.Render

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

... 30 more

Caused by: java.lang.NullPointerException

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:182)

... 32 more

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- System Details --

Details:

Minecraft Version: 1.10

Operating System: Windows 10 (amd64) version 10.0

Java Version: 1.8.0_102, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 155478872 bytes (148 MB) / 265113600 bytes (252 MB) up to 8502706176 bytes (8108 MB)

JVM Flags: 2 total; -Xincgc -Xmx8G

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP 9.32 Powered by Forge 12.18.0.2000 5 mods loaded, 5 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UC mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)

UC FML{8.0.99.99} [Forge Mod Loader] (forge-1.10-12.18.0.2000-1.10.0-universal.jar)

UC Forge{12.18.0.2000} [Minecraft Forge] (forge-1.10-12.18.0.2000-1.10.0-universal.jar)

UE spaceextended{MCvers.1.10  beta 0.1} [§5Space Pack Extending§r] (modid-1.0.jar)

UC worldedit{6.1.3} [WorldEdit] (worldedit-forge-mc1.9.4-6.1.3-dist.jar)

Loaded coremods (and transformers):

Profiler Position: N/A (disabled)

Is Modded: Definitely; Server brand changed to 'fml,forge'

Type: Dedicated Server (map_server.txt)

 

 

Mainclass:

 

package com.space.extended;

 

import com.space.extended.basicblocks.BasicBlocks;

import com.space.extended.basicstairs.BasicStairs;

import com.space.extended.biomes.BasicBiomes;

import com.space.extended.biomes.SpaceBiome;

import com.space.extended.biomes.SpaceBiome1;

import com.space.extended.biomes.SpaceBiome2;

import com.space.extended.entity.render.RenderBeetle;

import com.space.extended.items.BasicItems;

import com.space.extended.mob.EntityBeetle;

import com.space.extended.mob.EntityMobBeetle;

import com.space.extended.proxy.CommonProxy;

import com.space.extended.spaceTab.SpaceTab;

import com.space.extended.tileentity.TileEntityTresor;

import com.space.extended.world.BasicWorldgenerater;

 

import net.minecraft.client.renderer.entity.Render;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraftforge.common.BiomeManager;

import net.minecraftforge.common.BiomeManager.BiomeEntry;

import net.minecraftforge.common.MinecraftForge;

import net.minecraftforge.fml.client.registry.IRenderFactory;

import net.minecraftforge.fml.client.registry.RenderingRegistry;

import net.minecraftforge.fml.common.Mod;

import net.minecraftforge.fml.common.Mod.EventHandler;

import net.minecraftforge.fml.common.Mod.Instance;

import net.minecraftforge.fml.common.SidedProxy;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import net.minecraftforge.fml.common.network.NetworkRegistry;

import net.minecraftforge.fml.common.registry.GameRegistry;

 

@Mod(modid = SpaceExtendedMain.MODID, version = SpaceExtendedMain.VERSION)

public class SpaceExtendedMain {

 

public static final String MODID = "spaceextended";

public static final String VERSION = "MCvers.1.10  beta 0.1";

public static final String Name = "SpaceExtended";

 

public static final int RESERVESGUIID = 1;

public static final int TRESORGUIID = 2;

 

@Instance(MODID)

public static SpaceExtendedMain INSTANCE = new SpaceExtendedMain();

 

@SidedProxy(serverSide = "com.space.extended.proxy.CommonProxy", clientSide = "com.space.extended.proxy.ClientProxy", modId = MODID)

public static CommonProxy PROXY = new CommonProxy();

 

public static CreativeTabs tab;

public static CreativeTabs tab1;

public static CreativeTabs tab2;

 

private SpaceextendedEntity entity;

 

private BasicBlocks blocks;

private BasicItems items;

private BasicStairs stairs;

 

public static SpaceBiome spaceBiome;

public static SpaceBiome1 spaceBiome1;

public static SpaceBiome2 spaceBiome2;

 

public static final Schematic OUTPOSTS_SCHEMATIC = new Schematic("outposts.schematic");

public static final Schematic SPACETREE_SCHEMATIC = new Schematic("spacetree.schematic");

 

@EventHandler

public void preInit(FMLPreInitializationEvent event) {

 

 

tab = new SpaceTab();

tab1 = new StairsTab();

tab2 = new ArmorTab();

blocks = new BasicBlocks();

items = new BasicItems();

stairs = new BasicStairs();

 

PROXY.registerRenderer();

 

RenderingRegistry.registerEntityRenderingHandler(EntityMobBeetle.class, new IRenderFactory<EntityMobBeetle>() {

 

@Override

public Render<? super EntityMobBeetle> createRenderFor(RenderManager manager) {

 

return new RenderBeetle(manager);

}

});

 

EntityBeetle.createEntity(EntityMobBeetle.class, new RenderBeetle(null), "Beetle");

 

}

 

@EventHandler

public void init(FMLInitializationEvent event) {

 

NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler());

 

GameRegistry.registerTileEntity(TileEntityTresor.class, "TileEntityTresor");

 

entity = new SpaceextendedEntity();

 

new BasicSmelting();

new BasicCrafting();

 

GameRegistry.registerWorldGenerator(new BasicWorldgenerater(), 0);

 

MinecraftForge.EVENT_BUS.register(new Events());

 

spaceBiome = new SpaceBiome();

registerBiome(spaceBiome, true);

spaceBiome1 = new SpaceBiome1();

registerBiome(spaceBiome1, true);

spaceBiome2 = new SpaceBiome2();

registerBiome(spaceBiome2, true);

 

GameRegistry.registerWorldGenerator(new SchematicGenerator(OUTPOSTS_SCHEMATIC), 0);

GameRegistry.registerWorldGenerator(new SchematicGenerator1(SPACETREE_SCHEMATIC), 1);

 

}

 

@EventHandler

public void postInit(FMLPostInitializationEvent event) {

 

PROXY.registerModels();

 

}

 

public static void registerBiome(BasicBiomes biome, boolean isSpawnBiome) {

GameRegistry.register(biome);

BiomeManager.addBiome(biome.getBiomeType(), new BiomeEntry(biome, 1000));

if (isSpawnBiome) {

BiomeManager.addSpawnBiome(biome);

}

 

}

 

}

 

 

Renderclass:

 

package com.space.extended.entity.render;

 

import com.space.extended.model.ModelBeetle;

import net.minecraft.client.Minecraft;

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.renderer.entity.RenderLiving;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.entity.Entity;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

 

 

public class RenderBeetle extends RenderLiving{

 

public RenderBeetle(RenderManager renderManagerIn) {

 

super(renderManagerIn,new ModelBeetle(), 0);

 

}

 

@Override

protected ResourceLocation getEntityTexture(Entity entity) {

 

return new ResourceLocation("spaceextended", "textures/entity/Beetle.png");

}

 

 

 

}

 

 

Mobentity:

 

package com.space.extended.mob;

 

import com.space.extended.items.BasicItems;

 

import net.minecraft.block.Block;

import net.minecraft.entity.SharedMonsterAttributes;

import net.minecraft.entity.ai.EntityAIAttackMelee;

import net.minecraft.entity.ai.EntityAIHurtByTarget;

import net.minecraft.entity.ai.EntityAILeapAtTarget;

import net.minecraft.entity.ai.EntityAILookIdle;

import net.minecraft.entity.ai.EntityAINearestAttackableTarget;

import net.minecraft.entity.ai.EntityAISwimming;

import net.minecraft.entity.ai.EntityAIWander;

import net.minecraft.entity.ai.EntityAIWatchClosest;

import net.minecraft.entity.monster.EntityGuardian;

import net.minecraft.entity.monster.EntityMob;

import net.minecraft.entity.monster.EntitySkeleton;

import net.minecraft.entity.monster.EntitySpider;

import net.minecraft.entity.monster.EntityZombie;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.SoundEvents;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.math.BlockPos;

import net.minecraft.world.World;

 

 

 

public class EntityMobBeetle extends EntityMob{

 

public EntityMobBeetle(World world) {

super(world);

 

 

 

this.isImmuneToFire = true;

this.tasks.addTask(1, new EntityAISwimming(this));

        this.tasks.addTask(2, new EntityAILeapAtTarget(this, 0.4F));

        this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));

        this.tasks.addTask(4, new EntityAIWander(this, 0.6D));

        this.tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));

        this.tasks.addTask(6, new EntityAILookIdle(this));

        this.targetTasks.addTask(7, new EntityAIHurtByTarget(this, false));

        this.tasks.addTask(8, new EntityAIAttackMelee(this, 1.0D, false));

        this.targetTasks.addTask(9, new EntityAINearestAttackableTarget(this, EntityGuardian.class, true));

        this.targetTasks.addTask(10, new EntityAINearestAttackableTarget(this, EntityZombie.class, true));

        this.targetTasks.addTask(11, new EntityAINearestAttackableTarget(this, EntitySpider.class, true));

        this.targetTasks.addTask(12, new EntityAINearestAttackableTarget(this, EntitySkeleton.class, true));

     

       

       

       

       

}

protected void applyEntityAttributes()

    {

        super.applyEntityAttributes();

        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0D);

        this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.5f);

        this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(6.0D);

       

    }

 

@Override

protected Item getDropItem() {

return new ItemStack(BasicItems.cyberit_beetle).getItem();

 

}

protected void playStepSound(BlockPos pos, Block blockIn)

    {

        this.playSound(SoundEvents.ENTITY_SPIDER_STEP, 0.15F, 1.0F);

    }

 

}

 

 

EntityBeetleclass:

 

package com.space.extended.mob;

 

import com.space.extended.SpaceExtendedMain;

 

import net.minecraft.client.renderer.entity.Render;

import net.minecraft.entity.EnumCreatureType;

import net.minecraft.init.Biomes;

import net.minecraftforge.common.DungeonHooks;

import net.minecraftforge.fml.common.registry.EntityRegistry;

 

 

 

public class EntityBeetle {

 

public static void createEntity(Class entityClass, Render render, String entityName) {

 

EntityRegistry.registerModEntity(entityClass, entityName, 0, SpaceExtendedMain.INSTANCE, 64, 1, true,

(255 << 16) + (102 << 8) + 102, (204 << 16) + (255 << 8) + 102);

 

EntityRegistry.addSpawn(entityClass, 15, 2, 5, EnumCreatureType.MONSTER, Biomes.DESERT, Biomes.JUNGLE,

Biomes.HELL);

DungeonHooks.addDungeonMob("Beetle", 120);

 

}

 

}

 

 

 

 

Don't blame me if i always ask for your help. I just want to learn to be better....

Posted

The problem is that you register the render methods also on the Server, but the Server has nothing to do with rendering.

Register your render code on Client Side only (for example put it in the ClientProxy) and add to your class RenderBeetle the sideonly stuff, so that

it looks like this:

@SideOnly(Side.CLIENT)
public class RenderBeetle extends RenderLiving{

 

That should do it.

Developer of Primeval Forest.

Posted

@Bektor

 

Hello!

I´ve done what you told me, but my servercrash shows the same error as before...

I removed the render method from the mainclass and added it to the ClientProxy and added sideOnly to the class RenderBeetle.... :(

(an other question: how can I highlight my code as you did for easier reading?)

 

Thanks for your support

 

crashlog:

 

---- Minecraft Crash Report ----

// Daisy, daisy...

 

Time: 02.10.16 00:29

Description: Exception in server tick loop

 

net.minecraftforge.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraft/client/renderer/entity/Render

at net.minecraftforge.fml.common.LoadController.transition(LoadController.java:186)

at net.minecraftforge.fml.common.Loader.loadMods(Loader.java:562)

at net.minecraftforge.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:97)

at net.minecraftforge.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:328)

at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:121)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:431)

at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/renderer/entity/Render

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at net.minecraftforge.fml.common.FMLModContainer.constructMod(FMLModContainer.java:481)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

at com.google.common.eventbus.EventBus.post(EventBus.java:275)

at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:235)

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:213)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

at com.google.common.eventbus.EventBus.post(EventBus.java:275)

at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:142)

at net.minecraftforge.fml.common.Loader.loadMods(Loader.java:531)

... 5 more

Caused by: java.lang.ClassNotFoundException: net.minecraft.client.renderer.entity.Render

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

... 30 more

Caused by: java.lang.NullPointerException

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:182)

... 32 more

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- System Details --

Details:

Minecraft Version: 1.10

Operating System: Windows 10 (amd64) version 10.0

Java Version: 1.8.0_102, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 150288472 bytes (143 MB) / 263720960 bytes (251 MB) up to 8502706176 bytes (8108 MB)

JVM Flags: 2 total; -Xincgc -Xmx8G

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP 9.32 Powered by Forge 12.18.0.2000 5 mods loaded, 5 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UC mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)

UC FML{8.0.99.99} [Forge Mod Loader] (forge-1.10-12.18.0.2000-1.10.0-universal.jar)

UC Forge{12.18.0.2000} [Minecraft Forge] (forge-1.10-12.18.0.2000-1.10.0-universal.jar)

UE spaceextended{MCvers.1.10  beta 0.1} [§5Space Pack Extending§r] (modid-1.0.jar)

UC worldedit{6.1.3} [WorldEdit] (worldedit-forge-mc1.9.4-6.1.3-dist.jar)

Loaded coremods (and transformers):

Profiler Position: N/A (disabled)

Is Modded: Definitely; Server brand changed to 'fml,forge'

Type: Dedicated Server (map_server.txt)

 

 

Mainclass:

 

package com.space.extended;

 

import com.space.extended.basicblocks.BasicBlocks;

import com.space.extended.basicstairs.BasicStairs;

import com.space.extended.biomes.BasicBiomes;

import com.space.extended.biomes.SpaceBiome;

import com.space.extended.biomes.SpaceBiome1;

import com.space.extended.biomes.SpaceBiome2;

import com.space.extended.entity.render.RenderBeetle;

import com.space.extended.items.BasicItems;

import com.space.extended.mob.EntityBeetle;

import com.space.extended.mob.EntityMobBeetle;

import com.space.extended.proxy.CommonProxy;

import com.space.extended.spaceTab.SpaceTab;

import com.space.extended.tileentity.TileEntityTresor;

import com.space.extended.world.BasicWorldgenerater;

 

import net.minecraft.client.renderer.entity.Render;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraftforge.common.BiomeManager;

import net.minecraftforge.common.BiomeManager.BiomeEntry;

import net.minecraftforge.common.MinecraftForge;

import net.minecraftforge.fml.client.registry.IRenderFactory;

import net.minecraftforge.fml.client.registry.RenderingRegistry;

import net.minecraftforge.fml.common.Mod;

import net.minecraftforge.fml.common.Mod.EventHandler;

import net.minecraftforge.fml.common.Mod.Instance;

import net.minecraftforge.fml.common.SidedProxy;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import net.minecraftforge.fml.common.network.NetworkRegistry;

import net.minecraftforge.fml.common.registry.GameRegistry;

 

@Mod(modid = SpaceExtendedMain.MODID, version = SpaceExtendedMain.VERSION)

public class SpaceExtendedMain {

 

public static final String MODID = "spaceextended";

public static final String VERSION = "MCvers.1.10  beta 0.1";

public static final String Name = "SpaceExtended";

 

public static final int RESERVESGUIID = 1;

public static final int TRESORGUIID = 2;

 

@Instance(MODID)

public static SpaceExtendedMain INSTANCE = new SpaceExtendedMain();

 

@SidedProxy(serverSide = "com.space.extended.proxy.CommonProxy", clientSide = "com.space.extended.proxy.ClientProxy", modId = MODID)

public static CommonProxy PROXY = new CommonProxy();

 

public static CreativeTabs tab;

public static CreativeTabs tab1;

public static CreativeTabs tab2;

 

private SpaceextendedEntity entity;

 

private BasicBlocks blocks;

private BasicItems items;

private BasicStairs stairs;

 

public static SpaceBiome spaceBiome;

public static SpaceBiome1 spaceBiome1;

public static SpaceBiome2 spaceBiome2;

 

public static final Schematic OUTPOSTS_SCHEMATIC = new Schematic("outposts.schematic");

public static final Schematic SPACETREE_SCHEMATIC = new Schematic("spacetree.schematic");

 

@EventHandler

public void preInit(FMLPreInitializationEvent event) {

 

 

tab = new SpaceTab();

tab1 = new StairsTab();

tab2 = new ArmorTab();

blocks = new BasicBlocks();

items = new BasicItems();

stairs = new BasicStairs();

 

PROXY.registerRenderer();

 

 

 

EntityBeetle.createEntity(EntityMobBeetle.class, new RenderBeetle(null), "Beetle");

 

}

 

@EventHandler

public void init(FMLInitializationEvent event) {

 

NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler());

 

GameRegistry.registerTileEntity(TileEntityTresor.class, "TileEntityTresor");

 

entity = new SpaceextendedEntity();

 

new BasicSmelting();

new BasicCrafting();

 

GameRegistry.registerWorldGenerator(new BasicWorldgenerater(), 0);

 

MinecraftForge.EVENT_BUS.register(new Events());

 

spaceBiome = new SpaceBiome();

registerBiome(spaceBiome, true);

spaceBiome1 = new SpaceBiome1();

registerBiome(spaceBiome1, true);

spaceBiome2 = new SpaceBiome2();

registerBiome(spaceBiome2, true);

 

GameRegistry.registerWorldGenerator(new SchematicGenerator(OUTPOSTS_SCHEMATIC), 0);

GameRegistry.registerWorldGenerator(new SchematicGenerator1(SPACETREE_SCHEMATIC), 1);

 

}

 

@EventHandler

public void postInit(FMLPostInitializationEvent event) {

 

PROXY.registerModels();

 

}

 

public static void registerBiome(BasicBiomes biome, boolean isSpawnBiome) {

GameRegistry.register(biome);

BiomeManager.addBiome(biome.getBiomeType(), new BiomeEntry(biome, 1000));

if (isSpawnBiome) {

BiomeManager.addSpawnBiome(biome);

}

 

}

 

}

 

 

Renderclass:

 

package com.space.extended.entity.render;

 

import com.space.extended.model.ModelBeetle;

import net.minecraft.client.Minecraft;

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.renderer.entity.RenderLiving;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.entity.Entity;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

 

@SideOnly(Side.CLIENT)

 

public class RenderBeetle extends RenderLiving{

 

public RenderBeetle(RenderManager renderManagerIn) {

 

super(renderManagerIn,new ModelBeetle(), 0);

 

}

 

@Override

protected ResourceLocation getEntityTexture(Entity entity) {

 

return new ResourceLocation("spaceextended", "textures/entity/Beetle.png");

}

 

 

 

}

 

 

ClientProxy:

 

package com.space.extended.proxy;

 

import com.space.extended.SpaceExtendedMain;

import com.space.extended.basicblocks.BasicBlocks;

import com.space.extended.basicstairs.BasicStairs;

import com.space.extended.entity.EntityGrenade;

import com.space.extended.entity.render.RenderBeetle;

import com.space.extended.items.BasicItems;

import com.space.extended.mob.EntityMobBeetle;

 

import net.minecraft.block.Block;

import net.minecraft.block.BlockStairs;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;

import net.minecraft.client.renderer.entity.Render;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.client.renderer.entity.RenderSnowball;

import net.minecraft.item.Item;

import net.minecraftforge.fml.client.registry.IRenderFactory;

import net.minecraftforge.fml.client.registry.RenderingRegistry;

import net.minecraftforge.fml.common.SidedProxy;

 

 

 

public class ClientProxy extends CommonProxy {

 

public void registerModels() {

 

// Blocks

registerModel(BasicBlocks.vitallium, 0);

registerModel(BasicBlocks.vitalliumOre, 0);

registerModel(BasicBlocks.metalframeblock, 0);

registerModel(BasicBlocks.klingonium, 0);

registerModel(BasicBlocks.klingonit, 0);

registerModel(BasicBlocks.klingodur, 0);

registerModel(BasicBlocks.klingonium_screw, 0);

registerModel(BasicBlocks.klingonium0, 0);

registerModel(BasicBlocks.klingonium1, 0);

registerModel(BasicBlocks.klingonium2, 0);

registerModel(BasicBlocks.klingonium3, 0);

registerModel(BasicBlocks.klingoniumOre, 0);

registerModel(BasicBlocks.constructor1, 0);

registerModel(BasicBlocks.constructor2, 0);

registerModel(BasicBlocks.constructor3, 0);

registerModel(BasicBlocks.constructor4, 0);

registerModel(BasicBlocks.constructor5, 0);

registerModel(BasicBlocks.strontenium, 0);

registerModel(BasicBlocks.strontenium0, 0);

registerModel(BasicBlocks.strontenium1, 0);

registerModel(BasicBlocks.strontenium2, 0);

registerModel(BasicBlocks.stronteniumOre, 0);

registerModel(BasicBlocks.klingonium_wall0, 0);

registerModel(BasicBlocks.klingonium_wall1, 0);

registerModel(BasicBlocks.klingonium_wall2, 0);

registerModel(BasicBlocks.klingonium_wall3, 0);

registerModel(BasicBlocks.klingonium_wall4, 0);

registerModel(BasicBlocks.klingonium_wall5, 0);

registerModel(BasicBlocks.klingonium_wall6, 0);

registerModel(BasicBlocks.klingonium_wall7, 0);

registerModel(BasicBlocks.klingonium_wall8, 0);

registerModel(BasicBlocks.perolit, 0);

registerModel(BasicBlocks.perolitOre, 0);

registerModel(BasicBlocks.pipes_connector, 0);

registerModel(BasicBlocks.strontenita, 0);

registerModel(BasicBlocks.strontenitb, 0);

registerModel(BasicBlocks.strontenitc, 0);

registerModel(BasicBlocks.strontenitd, 0);

registerModel(BasicBlocks.strontenal, 0);

registerModel(BasicBlocks.oxygen, 0);

registerModel(BasicBlocks.perola, 0);

registerModel(BasicBlocks.perolb, 0);

registerModel(BasicBlocks.perolc, 0);

registerModel(BasicBlocks.perold, 0);

registerModel(BasicBlocks.table, 0);

registerModel(BasicBlocks.strontopal, 0);

registerModel(BasicBlocks.strontopala, 0);

registerModel(BasicBlocks.strontopalb, 0);

registerModel(BasicBlocks.lux, 0);

registerModel(BasicBlocks.ceiling_lamp, 0);

registerModel(BasicBlocks.speedway, 0);

registerModel(BasicBlocks.klingopar, 0);

registerModel(BasicBlocks.tresor, 0);

registerModel(BasicBlocks.strontecore, 0);

registerModel(BasicBlocks.cyberit, 0);

registerModel(BasicBlocks.cyberit_fire, 0);

registerModel(BasicBlocks.cyberit_Ore, 0);

registerModel(BasicBlocks.vitallium_glass, 0);

registerModel(BasicBlocks.vitallium_glass_pane, 0);

registerModel(BasicBlocks.analyser, 0);

registerModel(BasicBlocks.virtual_screen, 0);

registerModel(BasicBlocks.ferrolit, 0);

 

// Items

registerModel(BasicItems.vitalliumIngot, 0);

registerModel(BasicItems.klingoniumShard, 0);

registerModel(BasicItems.stronteniumIngot, 0);

registerModel(BasicItems.perolit_sphere, 0);

registerModel(BasicItems.kit1, 0);

registerModel(BasicItems.kit2, 0);

registerModel(BasicItems.kit3, 0);

registerModel(BasicItems.kit4, 0);

registerModel(BasicItems.kit5, 0);

registerModel(BasicItems.reserves, 0);

registerModel(BasicItems.cyberit_gem, 0);

registerModel(BasicItems.cyberit_beetle, 0);

 

registerModel(BasicItems.grenade, 0);

registerModel(BasicItems.flamethrower, 0);

 

registerModel(BasicItems.vitallium_helmet, 0);

registerModel(BasicItems.vitallium_chestplate, 0);

registerModel(BasicItems.vitallium_leggings, 0);

registerModel(BasicItems.vitallium_boots, 0);

 

// Stairs

registerModel(BasicStairs.chairmonitorstairs, 0);

registerModel(BasicStairs.drillmonitor, 0);

registerModel(BasicStairs.pcdeskammo, 0);

registerModel(BasicStairs.vitalliumstairs, 0);

registerModel(BasicStairs.metalframestairs, 0);

registerModel(BasicStairs.lamp_stairs, 0);

registerModel(BasicStairs.strontenium_stairs, 0);

registerModel(BasicStairs.strontenium_stairs1, 0);

registerModel(BasicStairs.metal1_stairs, 0);

registerModel(BasicStairs.officechair_stairs, 0);

registerModel(BasicStairs.klingonium_stairs, 0);

registerModel(BasicStairs.roof_stairs, 0);

registerModel(BasicStairs.klingonium_pipes_stairs, 0);

registerModel(BasicStairs.consoles_stairs, 0);

registerModel(BasicStairs.pipes_stairs, 0);

registerModel(BasicStairs.pipesa_stairs, 0);

registerModel(BasicStairs.pipesc_stairs, 0);

registerModel(BasicStairs.pipesb_stairs, 0);

registerModel(BasicStairs.spaceship_control, 0);

registerModel(BasicStairs.spaceman_seat, 0);

registerModel(BasicStairs.laboratory_bench, 0);

registerModel(BasicStairs.microscope, 0);

 

}

 

public void registerRenderer() {

 

RenderingRegistry.registerEntityRenderingHandler(EntityGrenade.class, new IRenderFactory() {

@Override

public Render createRenderFor(RenderManager manager) {

return new RenderSnowball<EntityGrenade>(manager, BasicItems.grenade,

Minecraft.getMinecraft().getRenderItem());

 

}

});

 

 

RenderingRegistry.registerEntityRenderingHandler(EntityMobBeetle.class, new IRenderFactory<EntityMobBeetle>() {

@Override

public Render<? super EntityMobBeetle> createRenderFor(RenderManager manager) {

 

return new RenderBeetle(manager);

}

});

}

 

 

 

private void registerModel(Object obj, int meta) {

 

Item item;

if (obj instanceof Item) {

item = (Item) obj;

} else if (obj instanceof Block) {

item = Item.getItemFromBlock((Block) obj);

} else if (obj instanceof BlockStairs) {

item = Item.getItemFromBlock((BlockStairs) obj);

} else {

throw new IllegalArgumentException();

}

 

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, meta, new ModelResourceLocation(

SpaceExtendedMain.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));

}

 

}

 

Don't blame me if i always ask for your help. I just want to learn to be better....

Posted

Hi

 

Any classes that get loaded on the dedicated server must not contain any mention of client-side classes at all.  It doesn't matter if that code is never executed on the server.

 

So for example

    EntityBeetle.createEntity(EntityMobBeetle.class, new RenderBeetle(null), "Beetle");

must not be in your Mainclass.

Put it into a server-side-only proxy instead.

 

See here for more background info.

http://greyminecraftcoder.blogspot.com.au/2013/11/how-forge-starts-up-your-code.html

 

-TGG

Posted

Hi mates!

At first, I`m a little confused about your different opinions...

The next , I want let you to know, that I'm over 60 years old and I started to learn java about 2 months ago and you can imagine, that my brain i`snt so

"elastic" to understand these new things and I'm a little overwhelmed with this stuff at the moment....

Would anyone be so kind and explain me exactly what and how to do next to get my mob working on servers...?(example)

I read the instructions from GreyGhost but I don`t understand how I should put my mobclasses to a server-side-only proxy(?) and they should not be in the main class...

Thanks  for your understanding and thanks for your help in advance,  ;)

Norzeteus

Don't blame me if i always ask for your help. I just want to learn to be better....

Posted

You don't need to put the mob-related classes in the server proxy, but instead, they do have to be in the main classes or called from there.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Hi mates!

At first, I`m a little confused about your different opinions...

The next , I want let you to know, that I'm over 60 years old and I started to learn java about 2 months ago and you can imagine, that my brain i`snt so

"elastic" to understand these new things and I'm a little overwhelmed with this stuff at the moment....

Would anyone be so kind and explain me exactly what and how to do next to get my mob working on servers...?(example)

I read the instructions from GreyGhost but I don`t understand how I should put my mobclasses to a server-side-only proxy(?) and they should not be in the main class...

Thanks  for your understanding and thanks for your help in advance,  ;)

Norzeteus

With the

[.code]your code in here[./code]
tags can you highlight your code. Just remove the dots "." I put in there, so I can write it without having it "converted" into the highlighted stuff.

 

Your crash log shows you in this line

net.minecraftforge.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraft/client/renderer/entity/Render

that it couldn't find the Render class. This happens because the Server has nothing to do with rendering, so the server has only the logic part and all classes while the client has the Render class because the Client has to handle the Rendering for you.

 

Just a small information: NullPointerException means that something is null when it should not be null and NoClassDefFoundError means that a class could not be found while ArrayOutOfBoundsException means that someone wants for example the number of the 10th position of the array, but the array is only 9 positions long. This are the exceptions/errors which happens in my opinion most. If you want to read more about it: https://docs.oracle.com/javase/tutorial/essential/exceptions/

http://www.tutorialspoint.com/java/java_exceptions.htm

 

To fix this you just have to change a bit of your code:

 

package com.space.extended;

[...]

@Mod(modid = SpaceExtendedMain.MODID, version = SpaceExtendedMain.VERSION)
public class SpaceExtendedMain {

[...]

   @EventHandler
   public void preInit(FMLPreInitializationEvent event) {

[...]

      EntityBeetle.createEntity(EntityMobBeetle.class, new RenderBeetle(null), "Beetle"); // this line has to be changed, here it is called on Client and Server,
     EntityBeetle.createEntity(EntityMobBeetle.class, "Beetle"); // this should work because the RenderBeetle class is only known on the Client and not the Server, don't forget to remove unused imports if any 
   }
[...]
}

 

 

Then this has to be changed:

 

package com.space.extended.mob;

import com.space.extended.SpaceExtendedMain;

import net.minecraft.client.renderer.entity.Render; // here you can see that the Render class is in a client package, which is only known on the Client, the Server doesn't have such a thing
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Biomes;
import net.minecraftforge.common.DungeonHooks;
import net.minecraftforge.fml.common.registry.EntityRegistry;



public class EntityBeetle {

   public static void createEntity(Class entityClass, Render render, String entityName) { // the Render class isn't needed here, because it's client-only and you never use it here
      EntityRegistry.registerModEntity(entityClass, entityName, 0, SpaceExtendedMain.INSTANCE, 64, 1, true, (255 << 16) + (102 <<  + 102, (204 << 16) + (255 <<  + 102);

      EntityRegistry.addSpawn(entityClass, 15, 2, 5, EnumCreatureType.MONSTER, Biomes.DESERT, Biomes.JUNGLE, Biomes.HELL);
      DungeonHooks.addDungeonMob("Beetle", 120);
   }
}

After the change:

package com.space.extended.mob;

import com.space.extended.SpaceExtendedMain;

import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Biomes;
import net.minecraftforge.common.DungeonHooks;
import net.minecraftforge.fml.common.registry.EntityRegistry;



public class EntityBeetle {

   public static void createEntity(Class entityClass, String entityName) { // the Render class isn't needed here, so I removed it here      EntityRegistry.registerModEntity(entityClass, entityName, 0, SpaceExtendedMain.INSTANCE, 64, 1, true, (255 << 16) + (102 <<  + 102, (204 << 16) + (255 <<  + 102);

      EntityRegistry.addSpawn(entityClass, 15, 2, 5, EnumCreatureType.MONSTER, Biomes.DESERT, Biomes.JUNGLE, Biomes.HELL);
      DungeonHooks.addDungeonMob("Beetle", 120);
   }
}

 

 

 

And here is the render class, I've changed here nothing.

 

package com.space.extended.entity.render;

import com.space.extended.model.ModelBeetle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT) // good 
public class RenderBeetle extends RenderLiving{

   public RenderBeetle(RenderManager renderManagerIn) {
      
      super(renderManagerIn,new ModelBeetle(), 0);
      
   }

   @Override
   protected ResourceLocation getEntityTexture(Entity entity) {
      
      return new ResourceLocation("spaceextended", "textures/entity/Beetle.png");
   }
}

 

 

The

@SideOnly(Side.CLIENT)

could eventually be removed there, I'm not quite sure. I just always put them in there since I got once a crash on a Server because I didn't put it over the Render class. :P

If you want you can test what happens when you remove this, but the safest way is just to have it there. ;)

 

I hope this helps.

Bektor

Developer of Primeval Forest.

Posted

@Bektor

 

Hello again!

After correcting my classes as you told me and changing the boundingbox of my mob( I think it was too small), it works now fine!  :)

Thanks alot, I´m so glad after several days unsuccsessful searching for solutions, that this problem got solved.....

 

Norzeteus

 

Don't blame me if i always ask for your help. I just want to learn to be better....

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

    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
  • Topics

×
×
  • Create New...

Important Information

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