Jump to content

[1.8.9] Some help on understanding networking


JimiIT92

Recommended Posts

So i'm trying to add some extended player properties and makes so no unnecessary packets are sends through client/server. But since i've never worked with packets i did not really understand when i should send a packet to the client and when i should send it to the server. By now i send a packet only when something change (for example: the mana value has changed), but if i do this in a tick handler the mod crashes, giving a ClassCastException

java.lang.ClassCastException: net.minecraft.client.entity.EntityPlayerSP cannot be cast to net.minecraft.entity.player.EntityPlayerMP
at com.rpg.player.PlayerProperties.sendToClient(PlayerProperties.java:194)
at com.rpg.player.PlayerProperties.setMana(PlayerProperties.java:113)
at com.rpg.player.PlayerProperties.removeMana(PlayerProperties.java:121)
at com.rpg.player.PlayerProperties.tick(PlayerProperties.java:217)
at com.rpg.events.PlayerTick.onTick(PlayerTick.java:14)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_12_PlayerTick_onTick_PlayerTickEvent.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:49)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:140)
at net.minecraftforge.fml.common.FMLCommonHandler.onPlayerPostTick(FMLCommonHandler.java:357)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:402)
at net.minecraft.client.entity.EntityPlayerSP.onUpdate(EntityPlayerSP.java:163)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2011)
at net.minecraft.world.World.updateEntity(World.java:1976)
at net.minecraft.world.World.updateEntities(World.java:1805)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2176)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1080)
at net.minecraft.client.Minecraft.run(Minecraft.java:380)
at net.minecraft.client.main.Main.main(Main.java:116)
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 net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
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 net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)

 

And this are all the classes involved:

 

PlayerProperties

package com.rpg.player;

import com.rpg.RPG;
import com.rpg.messages.EnergyRegenTimer;
import com.rpg.messages.EnergyValue;
import com.rpg.messages.GoldValue;
import com.rpg.messages.ManaRegenTimer;
import com.rpg.messages.ManaValue;
import com.rpg.messages.MaxEnergyValue;
import com.rpg.messages.MaxManaValue;
import com.rpg.messages.PlayerClass;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

public class PlayerProperties implements IExtendedEntityProperties {

public final static String PLAYER_PROPERTIES = "PlayerProperties";
private EntityPlayer player;

private int mana;
private int maxMana;
private int energy;
private int maxEnergy;
private int gold;
private String playerClass;
private boolean firstJoin;
private int manaRegenTimer;
private int energyRegenTimer;

private int ticks = 0;

public PlayerProperties(EntityPlayer player) {
	this.player = player;
	this.mana = this.maxMana = 100;
	this.energy = this.maxEnergy = 100;
	this.firstJoin = true;
	this.playerClass = "";
	this.manaRegenTimer = 10;
	this.energyRegenTimer = 10;
	this.gold = 0;
}

public static final void register(EntityPlayer player) {
	player.registerExtendedProperties(PLAYER_PROPERTIES, new PlayerProperties(player));
}

public static final PlayerProperties get(EntityPlayer player) {
	return (PlayerProperties) player.getExtendedProperties(PLAYER_PROPERTIES);
}

@Override
public void saveNBTData(NBTTagCompound compound) {
	NBTTagCompound nbt = new NBTTagCompound();

	nbt.setInteger("mana", this.mana);
	nbt.setInteger("maxMana", this.maxMana);
	nbt.setInteger("energy", this.energy);
	nbt.setInteger("maxEnergy", this.maxEnergy);
	nbt.setInteger("gold", this.gold);
	nbt.setString("playerClass", this.playerClass);
	nbt.setBoolean("firstJoin", this.firstJoin);
	nbt.setInteger("manaRegenTimer", this.manaRegenTimer);
	nbt.setInteger("energyRegenTimer", this.energyRegenTimer);

	compound.setTag(PLAYER_PROPERTIES, nbt);
}

@Override
public void loadNBTData(NBTTagCompound compound) {
	NBTTagCompound nbt = (NBTTagCompound) compound.getTag(PLAYER_PROPERTIES);

	this.mana = nbt.getInteger("mana");
	this.maxMana = nbt.getInteger("maxMana");
	this.energy = nbt.getInteger("energy");
	this.maxEnergy = nbt.getInteger("maxEnergy");
	this.gold = nbt.getInteger("gold");
	this.playerClass = nbt.getString("playerClass");
	this.firstJoin = nbt.getBoolean("firstJoin");
	this.manaRegenTimer = nbt.getInteger("manaRegenTimer");
	this.energyRegenTimer = nbt.getInteger("energyRegenTimer");
}

@Override
public void init(Entity entity, World world) {
}

public boolean isFirstJoin() {
	return this.firstJoin;
}

public void setJoined() {
	this.firstJoin = false;
}

public int getMana() {
	return this.mana;
}

public void setMana(int amount) {
	this.mana = amount;
	if (this.mana > this.maxMana)
		this.mana = this.maxMana;
	if (this.mana < 0)
		this.mana = 0;
	this.sendToClient(new ManaValue(this.mana));
}

public void addMana(int amount) {
	this.setMana(this.mana + amount);
}

public void removeMana(int amount) {
	this.setMana(this.mana - amount);
}

public int getMaxMana() {
	return this.maxMana;
}

public void setMaxMana(int amount) {
	this.maxMana = amount;
	this.sendToClient(new MaxManaValue(this.maxMana));
}

public int getEnergy() {
	return this.energy;
}

public void setEnergy(int amount) {
	this.energy = amount;
	if (this.energy > this.maxEnergy)
		this.energy = this.maxEnergy;
	if (this.energy < 0)
		this.energy = 0;
	this.sendToClient(new EnergyValue(this.energy));
}

public int getMaxEnergy() {
	return this.maxEnergy;
}

public void setMaxEnergy(int amount) {
	this.maxEnergy = amount;
	this.sendToClient(new MaxEnergyValue(this.maxEnergy));
}

public int getGold() {
	return this.gold;
}

public void setGold(int amount) {
	this.gold = amount;
	if (this.gold < 0)
		this.gold = 0;
	this.sendToClient(new GoldValue(this.gold));
}

public String getPlayerClass() {
	return this.playerClass;
}

public void setPlayerClass(String playerClass) {
	this.playerClass = playerClass;
	this.sendToClient(new PlayerClass(this.playerClass.charAt(0)));
}

public int getManaRegenTimer() {
	return 20 * this.manaRegenTimer;
}

public void setManaRegenTimer(int amount) {
	this.manaRegenTimer = amount;
	this.sendToClient(new ManaRegenTimer(this.manaRegenTimer));
}

public int getEnergyRegenTimer() {
	return 20 * this.energyRegenTimer;
}

public void setEnergyRegenTimer(int amount) {
	this.energyRegenTimer = amount;
	this.sendToClient(new EnergyRegenTimer(this.energyRegenTimer));
}

private void sendToClient(IMessage message) {
	RPG.network.sendTo(message, (EntityPlayerMP) this.player);
}

private void sendToServer(IMessage message) {
	RPG.network.sendToServer(message);
}

public void copy(PlayerProperties props) {
	this.mana = props.getMana();
	this.maxMana = props.getMaxMana();
	this.energy = props.getEnergy();
	this.maxEnergy = props.getMaxEnergy();
	this.gold = props.getGold();
	this.playerClass = props.getPlayerClass();
	this.firstJoin = props.isFirstJoin();
	this.manaRegenTimer = props.getManaRegenTimer();
	this.energyRegenTimer = props.getEnergyRegenTimer();
}

public void tick() {
	this.ticks++;
	if (this.ticks == this.getManaRegenTimer() && this.mana < this.maxMana) {
		this.ticks = 0;
		this.addMana(5);
	}
}

}

 

ManaValue

package com.rpg.messages;

import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

public class ManaValue implements IMessage{

private int value;

public ManaValue() {
	this.value = 0;
}

public ManaValue(int amount) {
	this.value = amount;
}

@Override
public void fromBytes(ByteBuf buf) {
	this.value = buf.readInt();
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(this.value);
}

public void setValue(int amount) {
	this.value = amount;
}

public int getValue() {
	return this.value;
}

}

 

ManaHandler

package com.rpg.handler;

import com.rpg.RPG;
import com.rpg.messages.ManaValue;
import com.rpg.player.PlayerProperties;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IThreadListener;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class ManaHandler implements IMessageHandler<ManaValue, IMessage>{

public ManaHandler() {

}

@Override
public IMessage onMessage(final ManaValue message, MessageContext ctx) {

	IThreadListener thread = RPG.proxy.getListener(ctx);
	EntityPlayer player = RPG.proxy.getPlayer(ctx);
	if(player != null) {
		final PlayerProperties props = PlayerProperties.get(player);
		if(props != null) {
			thread.addScheduledTask(new Runnable() {
				@Override
				public void run() {
					props.setMana(message.getValue());
				}
			});
		}
	}
	return null;
}

}

 

TickHandler

package com.rpg.events;

import com.rpg.player.PlayerProperties;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;

public class PlayerTick {

@SubscribeEvent
public void onTick(PlayerTickEvent event) {
	PlayerProperties props = PlayerProperties.get(event.player);
	if(props != null && event.player.worldObj.isRemote)
		props.tick();
}
}

 

ClientProxy

package com.rpg.proxy;

import com.rpg.RPG;
import com.rpg.events.DimensionChange;
import com.rpg.events.EntityCreation;
import com.rpg.events.PlayerClone;
import com.rpg.events.PlayerJoin;
import com.rpg.events.PlayerRespawn;
import com.rpg.events.PlayerTick;
import com.rpg.gui.GuiOverlay;
import com.rpg.handler.EnergyHandler;
import com.rpg.handler.EnergyRegenHandler;
import com.rpg.handler.GoldHandler;
import com.rpg.handler.ManaHandler;
import com.rpg.handler.ManaRegenHandler;
import com.rpg.handler.MaxEnergyHandler;
import com.rpg.handler.MaxManaHandler;
import com.rpg.handler.PlayerClassHandler;
import com.rpg.messages.EnergyRegenTimer;
import com.rpg.messages.EnergyValue;
import com.rpg.messages.GoldValue;
import com.rpg.messages.ManaRegenTimer;
import com.rpg.messages.ManaValue;
import com.rpg.messages.MaxEnergyValue;
import com.rpg.messages.MaxManaValue;
import com.rpg.messages.PlayerClass;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IThreadListener;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;

public class ClientProxy extends CommonProxy{

public void preInit() {
	RPG.network = NetworkRegistry.INSTANCE.newSimpleChannel(RPG.MODID);
	RPG.network.registerMessage(ManaHandler.class, ManaValue.class, 0, Side.CLIENT);
}

public void init() {
	MinecraftForge.EVENT_BUS.register(new GuiOverlay(Minecraft.getMinecraft()));
}

public IThreadListener getListener(MessageContext ctx) {
	return Minecraft.getMinecraft();
}

public EntityPlayer getPlayer(MessageContext ctx) {
	return Minecraft.getMinecraft().thePlayer;
}

public void registerEvents() {
	MinecraftForge.EVENT_BUS.register(new PlayerTick());
}
}

 

CommonProxy

package com.rpg.proxy;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IThreadListener;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class CommonProxy {

public void preInit() {}
public void init() {}

public IThreadListener getListener(MessageContext ctx) {
	return (WorldServer) ctx.getServerHandler().playerEntity.worldObj;
}

public EntityPlayer getPlayer(MessageContext ctx) {
	return ctx.getServerHandler().playerEntity;
}

public void registerEvents() {}
}

 

Main Mod File

package com.rpg;

import com.rpg.proxy.CommonProxy;

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.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;

@Mod(modid = RPG.MODID, version = RPG.VERSION, name = RPG.NAME)
public class RPG
{
@SidedProxy(clientSide = "com.rpg.proxy.ClientProxy", serverSide = "com.rpg.proxy.CommonProxy")
public static CommonProxy proxy;
@Instance("rpg")
public static RPG instance;
public static final String NAME = "RPG Mod";
    public static final String MODID = "rpg";
    public static final String VERSION = "1.0";
    
    public static SimpleNetworkWrapper network;
    
    @EventHandler
public void preInit(FMLPreInitializationEvent event) {
    	proxy.preInit();
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
    	proxy.init();
    	proxy.registerEvents();
    }
}

 

Let me know if other classes are needed

So i want to understand how can this work? When i should send a packet to the server and when to the client?

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

Link to comment
Share on other sites

You're only calling

PlayerProperties#tick

on the client side (when

World#isRemote

is

true

). You need to call it on the server instead (when

World#isRemote

is

false

).

 

The server should control all data and send packets to the relevant clients when they need the data for rendering purposes. The client should receive player input (clicks and key presses) and send packets to the server when these should trigger some action.

 

You should convert your

IExtendedEntityProperties

to a capability,

IEEP

has been removed in 1.9+.

 

You should also annotate override methods with

@Override

so you get a compilation error if they don't actually override a super method.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I've changed the check in the tick handler, but now this happens: the server sets the value to 100 and the bar in game goes to 100, but this error is fired as soon as it does

[11:56:22] [Client thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.ClassCastException: net.minecraft.client.entity.EntityPlayerSP cannot be cast to net.minecraft.entity.player.EntityPlayerMP
at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_92]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_92]
at net.minecraft.util.Util.runTask(Util.java:23) [util.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1070) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:380) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:116) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: java.lang.ClassCastException: net.minecraft.client.entity.EntityPlayerSP cannot be cast to net.minecraft.entity.player.EntityPlayerMP
at com.rpg.player.PlayerProperties.sendToClient(PlayerProperties.java:208) ~[PlayerProperties.class:?]
at com.rpg.player.PlayerProperties.setMana(PlayerProperties.java:118) ~[PlayerProperties.class:?]
at com.rpg.handler.ManaHandler$1.run(ManaHandler.java:30) ~[ManaHandler$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_92]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_92]
at net.minecraft.util.Util.runTask(Util.java:22) ~[util.class:?]
... 15 more

 

and also when relogging the bar is resetted :/

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

Link to comment
Share on other sites

ManaHandler

calls

PlayerProperties#setMana

, which calls

sendToClient

regardless of which side it was called from. Only call

sendToClient

on the server.

 

Your

ClientProxy#getPlayer

and

getListener

methods are incorrect because they don't account for the logical side (client thread or server thread) that they're being called from and only return the client player and listener. The

MessageContext#side

field tells you which logical side the message was received on.

 

This page explains sides in more detail.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Ok, so i've changed the proxy methods to this

public IThreadListener getListener(MessageContext ctx) {
	return ctx.side == Side.CLIENT ? Minecraft.getMinecraft() : super.getListener(ctx);
}

public EntityPlayer getPlayer(MessageContext ctx) {
	return ctx.side == Side.CLIENT ? Minecraft.getMinecraft().thePlayer : super.getPlayer(ctx);
}

 

but i did not udnerstand where i should call the sendToClient method. I think that this is incorrect and it will loop, so where should i call that method?

package com.rpg.handler;

import com.rpg.RPG;
import com.rpg.messages.ManaValue;
import com.rpg.player.PlayerProperties;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IThreadListener;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class ManaHandler implements IMessageHandler<ManaValue, IMessage>{

public ManaHandler() {

}

@Override
public IMessage onMessage(final ManaValue message, MessageContext ctx) {

	IThreadListener thread = RPG.proxy.getListener(ctx);
	EntityPlayer player = RPG.proxy.getPlayer(ctx);
	if(player != null) {
		final PlayerProperties props = PlayerProperties.get(player);
		if(props != null) {
			thread.addScheduledTask(new Runnable() {
				@Override
				public void run() {
					props.setMana(message.getValue());
					props.sendToClient(new ManaValue(props.getMana()));
				}
			});
		}
	}
	return null;
}

}

 

EDIT: i've change the addMana function to this

public void addMana(int amount) {
	this.setMana(this.mana + amount);
	this.sendToClient(new ManaValue(this.getMana()));
}

 

now the bar actually updates but it still reset once the player log out

 

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

Link to comment
Share on other sites

ManaHandler

is called when the client receives a

ManaValue

message from the server.

PlayerProperties#sendToClient

sends a

ManaValue

message from the server to the client.

 

PlayerProperties#sendToClient

must be called from

PlayerProperties#setMana

, but only on the server side (when

World#isRemote

is

false

).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I've done the class to sendToClient in the tick method (since this is called only from the tickHandler when world.isRemote is false).

public void tick() {
	this.ticks++;
	if (this.ticks == this.getManaRegenTimer() && this.mana < this.maxMana) {
		this.ticks = 0;
		this.addMana(5);
		this.sendToClient(new ManaValue(this.getMana()));
	}
}

 

In game the bar updates correctly but still when logs out and then re-login the bar goes to default value (95/100)

 

EDIT: in the PlayerJoinEvent i've printed the mana value and it is 100, while the bar displays 95

 

@SubscribeEvent
public void onPlayerJoin(PlayerLoggedInEvent event) {
	PlayerProperties props = PlayerProperties.get(event.player);
	if(props != null) {
		System.out.println(props.getMana());
		if(props.isFirstJoin()) {
			props.setJoined();
		}
	}
}

 

This event is registered as well

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

Link to comment
Share on other sites

PlayerLoggedInEvent

is only fired on the server.

 

The client doesn't save any data, so you need to send the player's current mana value to their client when they log in.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Tried doing this

package com.rpg.events;

import com.rpg.messages.ManaValue;
import com.rpg.player.PlayerProperties;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;

public class PlayerJoin {

@SubscribeEvent
public void onPlayerJoin(PlayerLoggedInEvent event) {
	PlayerProperties props = PlayerProperties.get(event.player);
	if(props != null) {
		System.out.println(props.getMana());
		props.sendToClient(new ManaValue(props.getMana()));
		if(props.isFirstJoin()) {
			props.setJoined();
		}
	}
}
}

 

The print return 100 but the bar is still at 95

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

Link to comment
Share on other sites

Set a breakpoint in

ManaHandler

, does the client player exist when message sent from the

PlayerLoggedInEvent

handler is received?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Yes, the player exist in ManaHandler (i put a breakpoint at the start of the onMessage method. If the player does not exist then the null check will be true and nothing will happen). So the onMessage method is running but looking at the properties that this method will get i see that the mana value is 95 (while in the event is printed as 100). So i guess that client and server handles different values, wich is not good. How can i sync them?

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

Link to comment
Share on other sites

The function to change the mana value is called only in the ManaHandler. What i do is this

public int getMana() {
	return this.mana;
}

public void setMana(int amount) {
	this.mana = amount;
	if (this.mana > this.maxMana)
		this.mana = this.maxMana;
	if (this.mana < 0)
		this.mana = 0;
}

public void addMana(int amount) {
	this.sendToServer(new ManaValue(this.mana + amount));
}

public void removeMana(int amount) {
	this.sendToServer(new ManaValue(this.mana - amount));
}

 

Every time i want to change the value (by adding or subtracting something) i send a packet on the server with the new amount of mana, then in the ManaHandler the setMana function is called to actually set the new value. What i miss is from server to client what should i send, because if i send the same message i think it will always call the setMana function (as it will return constantly in the handler) :/

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

Link to comment
Share on other sites

No, that's completely backwards. NEVER send values to the server - the server is the one that should be sending values to the client. Why are you controlling mana values from the client?

 

Also, it'd be simpler to send the packet from #setMana which I assume is the centralized method for actually modifying mana values.

 

Finally, your #addMana and #removeMana methods are very weird - you don't actually modify the mana value, you just send a packet?

Link to comment
Share on other sites

Yes, i send only a packet holding the new value, than in the handler the setMana function is called, setting the mana to the new value by doing this

props.setMana(message.getValue());

 

But i assume this is wrong due to you response. So i should only send in the message the amount of mana to add/subtract, then in the handler calcualte the new mana amount (with controls and stuff) and only then call the setMana function to set the mana to the new value and send a packet to the client? Basically should i do this in the PlayerProperties

public void setMana(int amount) {
	this.mana = amount;
}

public void addMana(int amount) {
	this.sendToServer(new ManaValue(amount));
}

public void removeMana(int amount) {
	this.sendToServer(new ManaValue(-1 * amount));
}

 

and this in the handler?

@Override
public IMessage onMessage(final ManaValue message, final MessageContext ctx) {

	IThreadListener thread = RPG.proxy.getListener(ctx);
	EntityPlayer player = RPG.proxy.getPlayer(ctx);
	if(player != null) {
		final PlayerProperties props = PlayerProperties.get(player);
		if(props != null) {
			thread.addScheduledTask(new Runnable() {
				@Override
				public void run() {
					int mana = props.getMana() + message.getValue();
					if (mana > props.getMaxMana())
						mana = props.getMaxMana();
					if (mana < 0)
						mana = 0;
					props.setMana(mana);
					//packet
				}
			});
		}
	}
	return null;
}

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

Link to comment
Share on other sites

No, you shouldn't be sending ANY data at all to the server... the server should already know about needing to add or subtract mana as the server is the only place that should ever happen.

 

Basically all the client should ever do is display the current value of the mana. If you have a key press responsible for activating magic spells or whatever, the answer is not to have the client change the mana value but to send a packet to the server saying 'hey player A wants to activate magic spell B, is that okay?' and the server goes through all the logic of determining if the player can do that, which involves checking and then modifying the current mana value and ultimately sending a packet back to the client with the new current mana value.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Exception in thread "main" java.lang.IllegalStateException: Current Java is 1.8.0_271 but we require at least 17         at net.minecraftforge.bootstrap.shim.Main.main(Main.java:32) Never have successfully gotten a minecraft server up and running so I thought i'd try again. Instant unfixable issue.  
    • the block is engineer's workbench and crash when I put a blue print on it, now I dont have access to my world  
    • ---- Minecraft Crash Report ---- // Don't do that. Time: 25/4/24 12:53 Description: Rendering Block Entity java.lang.IllegalStateException: Not filled all elements of the vertex     at com.mojang.blaze3d.vertex.BufferBuilder.m_5752_(BufferBuilder.java:435) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:computing_frames,xf:OptiFine:default,re:mixin,xf:OptiFine:default,re:classloading,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BufferBuilderMixin,pl:mixin:A}     at blusunrize.immersiveengineering.client.utils.TransformingVertexBuilder.m_5752_(TransformingVertexBuilder.java:135) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at blusunrize.immersiveengineering.client.render.tile.BlueprintRenderer.lambda$makeQuadLinePainter$0(BlueprintRenderer.java:210) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at blusunrize.immersiveengineering.client.render.tile.BlueprintRenderer$BlueprintLines.draw(BlueprintRenderer.java:256) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at blusunrize.immersiveengineering.client.render.tile.ModWorkbenchRenderer.lambda$buildVBO$0(ModWorkbenchRenderer.java:159) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at blusunrize.immersiveengineering.client.utils.VertexBufferHolder.renderToBuilder(VertexBufferHolder.java:130) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:mixin,re:classloading}     at blusunrize.immersiveengineering.client.utils.VertexBufferHolder.render(VertexBufferHolder.java:116) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:mixin,re:classloading}     at blusunrize.immersiveengineering.api.client.IVertexBufferHolder.render(IVertexBufferHolder.java:58) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:mixin,re:classloading}     at blusunrize.immersiveengineering.client.render.tile.ModWorkbenchRenderer.render(ModWorkbenchRenderer.java:61) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at blusunrize.immersiveengineering.client.render.tile.ModWorkbenchRenderer.m_6922_(ModWorkbenchRenderer.java:31) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher.m_112284_(BlockEntityRenderDispatcher.java:107) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BlockEntityRenderDispatcherAccessor,pl:mixin:A}     at net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher.lambda$renderTileEntity$0(BlockEntityRenderDispatcher.java:79) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BlockEntityRenderDispatcherAccessor,pl:mixin:A}     at net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher.m_112278_(BlockEntityRenderDispatcher.java:154) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BlockEntityRenderDispatcherAccessor,pl:mixin:A}     at net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher.m_112267_(BlockEntityRenderDispatcher.java:77) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BlockEntityRenderDispatcherAccessor,pl:mixin:A}     at net.minecraft.client.renderer.LevelRenderer.m_109599_(LevelRenderer.java:1930) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:immersiveengineering.mixins.json:accessors.client.WorldRendererAccess,pl:mixin:APP:immersiveengineering.mixins.json:coremods.client.LevelRendererMixin,pl:mixin:APP:flywheel.mixins.json:LevelRendererAccessor,pl:mixin:APP:flywheel.mixins.json:fix.FixFabulousDepthMixin,pl:mixin:APP:flywheel.mixins.json:instancemanage.InstanceUpdateMixin,pl:mixin:APP:citadel.mixins.json:client.WorldRendererMixin,pl:mixin:APP:create.mixins.json:client.LevelRendererMixin,pl:mixin:APP:flywheel.mixins.json:LevelRendererMixin,pl:mixin:A}     at net.minecraft.client.renderer.GameRenderer.m_109089_(GameRenderer.java:1569) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:create.mixins.json:accessor.GameRendererAccessor,pl:mixin:APP:create.mixins.json:client.GameRendererMixin,pl:mixin:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:1185) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:create.mixins.json:accessor.GameRendererAccessor,pl:mixin:APP:create.mixins.json:client.GameRendererMixin,pl:mixin:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1046) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:immersiveengineering.mixins.json:accessors.client.MinecraftAccess,pl:mixin:APP:flywheel.mixins.json:PausedPartialTickAccessor,pl:mixin:APP:create.mixins.json:client.WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:665) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:immersiveengineering.mixins.json:accessors.client.MinecraftAccess,pl:mixin:APP:flywheel.mixins.json:PausedPartialTickAccessor,pl:mixin:APP:create.mixins.json:client.WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:205) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:classloading,re:mixin,pl:runtimedistcleaner:A,pl:mixin:A,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:31) ~[fmlloader-1.18.2-40.2.18.jar%2318!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at com.mojang.blaze3d.vertex.BufferBuilder.m_5752_(BufferBuilder.java:435) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:computing_frames,xf:OptiFine:default,re:mixin,xf:OptiFine:default,re:classloading,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BufferBuilderMixin,pl:mixin:A}     at blusunrize.immersiveengineering.client.utils.TransformingVertexBuilder.m_5752_(TransformingVertexBuilder.java:135) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at blusunrize.immersiveengineering.client.render.tile.BlueprintRenderer.lambda$makeQuadLinePainter$0(BlueprintRenderer.java:210) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at blusunrize.immersiveengineering.client.render.tile.BlueprintRenderer$BlueprintLines.draw(BlueprintRenderer.java:256) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at blusunrize.immersiveengineering.client.render.tile.ModWorkbenchRenderer.lambda$buildVBO$0(ModWorkbenchRenderer.java:159) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at blusunrize.immersiveengineering.client.utils.VertexBufferHolder.renderToBuilder(VertexBufferHolder.java:130) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:mixin,re:classloading}     at blusunrize.immersiveengineering.client.utils.VertexBufferHolder.render(VertexBufferHolder.java:116) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:mixin,re:classloading}     at blusunrize.immersiveengineering.api.client.IVertexBufferHolder.render(IVertexBufferHolder.java:58) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:mixin,re:classloading}     at blusunrize.immersiveengineering.client.render.tile.ModWorkbenchRenderer.render(ModWorkbenchRenderer.java:61) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at blusunrize.immersiveengineering.client.render.tile.ModWorkbenchRenderer.m_6922_(ModWorkbenchRenderer.java:31) ~[ImmersiveEngineering-1.18.2-8.4.0-161.jar%2364!/:?] {re:classloading}     at net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher.m_112284_(BlockEntityRenderDispatcher.java:107) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BlockEntityRenderDispatcherAccessor,pl:mixin:A}     at net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher.lambda$renderTileEntity$0(BlockEntityRenderDispatcher.java:79) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BlockEntityRenderDispatcherAccessor,pl:mixin:A}     at net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher.m_112278_(BlockEntityRenderDispatcher.java:154) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BlockEntityRenderDispatcherAccessor,pl:mixin:A}     at net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher.m_112267_(BlockEntityRenderDispatcher.java:77) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BlockEntityRenderDispatcherAccessor,pl:mixin:A}     at net.minecraft.client.renderer.LevelRenderer.m_109599_(LevelRenderer.java:1930) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:immersiveengineering.mixins.json:accessors.client.WorldRendererAccess,pl:mixin:APP:immersiveengineering.mixins.json:coremods.client.LevelRendererMixin,pl:mixin:APP:flywheel.mixins.json:LevelRendererAccessor,pl:mixin:APP:flywheel.mixins.json:fix.FixFabulousDepthMixin,pl:mixin:APP:flywheel.mixins.json:instancemanage.InstanceUpdateMixin,pl:mixin:APP:citadel.mixins.json:client.WorldRendererMixin,pl:mixin:APP:create.mixins.json:client.LevelRendererMixin,pl:mixin:APP:flywheel.mixins.json:LevelRendererMixin,pl:mixin:A}     at net.minecraft.client.renderer.GameRenderer.m_109089_(GameRenderer.java:1569) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:create.mixins.json:accessor.GameRendererAccessor,pl:mixin:APP:create.mixins.json:client.GameRendererMixin,pl:mixin:A} -- Block Entity Details -- Details:     Name: immersiveengineering:modworkbench // blusunrize.immersiveengineering.common.blocks.wooden.ModWorkbenchBlockEntity     Block: Block{immersiveengineering:workbench}[facing=south,multiblockslave=false,waterlogged=false]     Block location: World: (-2,-60,-7), Section: (at 14,4,9 in -1,-4,-1; chunk contains blocks -16,-64,-16 to -1,319,-1), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,-64,-512 to -1,319,-1)     Block: Block{immersiveengineering:workbench}[facing=south,multiblockslave=false,waterlogged=false]     Block location: World: (-2,-60,-7), Section: (at 14,4,9 in -1,-4,-1; chunk contains blocks -16,-64,-16 to -1,319,-1), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,-64,-512 to -1,319,-1) Stacktrace:     at net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher.m_112278_(BlockEntityRenderDispatcher.java:154) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BlockEntityRenderDispatcherAccessor,pl:mixin:A}     at net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher.m_112267_(BlockEntityRenderDispatcher.java:77) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:BlockEntityRenderDispatcherAccessor,pl:mixin:A}     at net.minecraft.client.renderer.LevelRenderer.m_109599_(LevelRenderer.java:1930) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:immersiveengineering.mixins.json:accessors.client.WorldRendererAccess,pl:mixin:APP:immersiveengineering.mixins.json:coremods.client.LevelRendererMixin,pl:mixin:APP:flywheel.mixins.json:LevelRendererAccessor,pl:mixin:APP:flywheel.mixins.json:fix.FixFabulousDepthMixin,pl:mixin:APP:flywheel.mixins.json:instancemanage.InstanceUpdateMixin,pl:mixin:APP:citadel.mixins.json:client.WorldRendererMixin,pl:mixin:APP:create.mixins.json:client.LevelRendererMixin,pl:mixin:APP:flywheel.mixins.json:LevelRendererMixin,pl:mixin:A}     at net.minecraft.client.renderer.GameRenderer.m_109089_(GameRenderer.java:1569) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:create.mixins.json:accessor.GameRendererAccessor,pl:mixin:APP:create.mixins.json:client.GameRendererMixin,pl:mixin:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:1185) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:create.mixins.json:accessor.GameRendererAccessor,pl:mixin:APP:create.mixins.json:client.GameRendererMixin,pl:mixin:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1046) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:immersiveengineering.mixins.json:accessors.client.MinecraftAccess,pl:mixin:APP:flywheel.mixins.json:PausedPartialTickAccessor,pl:mixin:APP:create.mixins.json:client.WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:665) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:immersiveengineering.mixins.json:accessors.client.MinecraftAccess,pl:mixin:APP:flywheel.mixins.json:PausedPartialTickAccessor,pl:mixin:APP:create.mixins.json:client.WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:205) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:classloading,re:mixin,pl:runtimedistcleaner:A,pl:mixin:A,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:31) ~[fmlloader-1.18.2-40.2.18.jar%2318!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?] {} -- Affected level -- Details:     All players: 1 total; [LocalPlayer['Kxzer'/102, l='ClientLevel', x=-2.77, y=-60.00, z=-8.63]]     Chunk stats: 4489, 2843     Level dimension: minecraft:overworld     Level spawn location: World: (0,-60,0), Section: (at 0,4,0 in 0,-4,0; chunk contains blocks 0,-64,0 to 15,319,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,-64,0 to 511,319,511)     Level time: 33719 game time, 33719 day time     Server brand: forge     Server type: Integrated singleplayer server Stacktrace:     at net.minecraft.client.multiplayer.ClientLevel.m_6026_(ClientLevel.java:522) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,xf:OptiFine:default,re:classloading,xf:OptiFine:default,pl:mixin:APP:flywheel.mixins.json:ClientLevelMixin,pl:mixin:A}     at net.minecraft.client.Minecraft.m_91354_(Minecraft.java:2264) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:immersiveengineering.mixins.json:accessors.client.MinecraftAccess,pl:mixin:APP:flywheel.mixins.json:PausedPartialTickAccessor,pl:mixin:APP:create.mixins.json:client.WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:682) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:immersiveengineering.mixins.json:accessors.client.MinecraftAccess,pl:mixin:APP:flywheel.mixins.json:PausedPartialTickAccessor,pl:mixin:APP:create.mixins.json:client.WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:205) ~[client-1.18.2-20220404.173914-srg.jar%2373!/:?] {re:classloading,re:mixin,pl:runtimedistcleaner:A,pl:mixin:A,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:31) ~[fmlloader-1.18.2-40.2.18.jar%2318!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.3.jar%235!/:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?] {} -- Last reload -- Details:     Reload number: 2     Reload reason: manual     Finished: Yes     Packs: Mod Resources, Default, Kxzer-Totem-pv9.zip, Create Legacy Copper -- System Details -- Details:     Minecraft Version: 1.18.2     Minecraft Version ID: 1.18.2     Operating System: Windows 10 (amd64) version 10.0     Java Version: 17.0.1, Microsoft     Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Microsoft     Memory: 137598464 bytes (131 MiB) / 2147483648 bytes (2048 MiB) up to 2147483648 bytes (2048 MiB)     CPUs: 8     Processor Vendor: AuthenticAMD     Processor Name: AMD Ryzen 5 3550H with Radeon Vega Mobile Gfx       Identifier: AuthenticAMD Family 23 Model 24 Stepping 1     Microarchitecture: Zen / Zen+     Frequency (GHz): 2,10     Number of physical packages: 1     Number of physical CPUs: 4     Number of logical CPUs: 8     Graphics card #0 name: AMD Radeon(TM) Vega 8 Graphics     Graphics card #0 vendor: Advanced Micro Devices, Inc. (0x1002)     Graphics card #0 VRAM (MB): 2048,00     Graphics card #0 deviceId: 0x15d8     Graphics card #0 versionInfo: DriverVersion=31.0.14043.7000     Graphics card #1 name: Radeon RX 5500M     Graphics card #1 vendor: Advanced Micro Devices, Inc. (0x1002)     Graphics card #1 VRAM (MB): 4080,00     Graphics card #1 deviceId: 0x7340     Graphics card #1 versionInfo: DriverVersion=31.0.14043.7000     Memory slot #0 capacity (MB): 8192,00     Memory slot #0 clockSpeed (GHz): 2,67     Memory slot #0 type: DDR4     Memory slot #1 capacity (MB): 8192,00     Memory slot #1 clockSpeed (GHz): 2,67     Memory slot #1 type: DDR4     Virtual memory max (MB): 18605,84     Virtual memory used (MB): 14061,94     Swap memory total (MB): 4352,00     Swap memory used (MB): 445,66     JVM Flags: 8 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M     Launched Version: 1.18.2-forge-40.2.18     Backend library: LWJGL version 3.2.2 SNAPSHOT     Backend API: AMD Radeon(TM) Vega 8 Graphics  GL version 3.2.0 Core Profile Context 23.4.1.230326, ATI Technologies Inc.     Window size: 1920x1080     GL Caps: Using framebuffer using OpenGL 3.2     GL debug messages:      Using VBOs: Yes     Is Modded: Definitely; Client brand changed to 'forge'; Server brand changed to 'forge'     Type: Integrated Server (map_client.txt)     Graphics mode: fabulous     Resource Packs: mod_resources, vanilla, file/Kxzer-Totem-pv9.zip (incompatible), create:legacy_copper     Current Language: English (US)     CPU: 8x AMD Ryzen 5 3550H with Radeon Vega Mobile Gfx      Server Running: true     Player Count: 1 / 8; [ServerPlayer['Kxzer'/102, l='ServerLevel[Mundo nuevo]', x=-2.77, y=-60.00, z=-8.63]]     Data Packs: vanilla, mod:tconstruct (incompatible), mod:farmersdelight, mod:dungeoncrawl, mod:immersivepetroleum (incompatible), mod:immersiveengineering, mod:forge, mod:expandability (incompatible), mod:curios (incompatible), mod:flywheel (incompatible), mod:mantle (incompatible), mod:create, mod:refinedstorage, mod:jei (incompatible), mod:citadel (incompatible), mod:cataclysm (incompatible), mod:storagedrawers (incompatible), mod:artifacts, mod:journeymap, mod:ctm (incompatible), mod:chipped (incompatible)     World Generation: Experimental     OptiFine Version: OptiFine_1.18.2_HD_U_H9     OptiFine Build: 20230626-134040     Render Distance Chunks: 30     Mipmaps: 4     Anisotropic Filtering: 1     Antialiasing: 0     Multitexture: false     Shaders: null     OpenGlVersion: 3.2.0 Core Profile Context 23.4.1.230326     OpenGlRenderer: AMD Radeon(TM) Vega 8 Graphics      OpenGlVendor: ATI Technologies Inc.     CpuCount: 8     ModLauncher: 9.1.3+9.1.3+main.9b69c82a     ModLauncher launch target: forgeclient     ModLauncher naming: srg     ModLauncher services:           mixin PLUGINSERVICE           eventbus PLUGINSERVICE           slf4jfixer PLUGINSERVICE           object_holder_definalize PLUGINSERVICE           runtime_enum_extender PLUGINSERVICE           capability_token_subclass PLUGINSERVICE           accesstransformer PLUGINSERVICE           runtimedistcleaner PLUGINSERVICE           mixin TRANSFORMATIONSERVICE           OptiFine TRANSFORMATIONSERVICE           fml TRANSFORMATIONSERVICE      FML Language Providers:          [email protected]         lowcodefml@null         javafml@null     Mod List:          client-1.18.2-20220404.173914-srg.jar             |Minecraft                     |minecraft                     |1.18.2              |DONE      |Manifest: a1:d4:5e:04:4f:d3:d6:e0:7b:37:97:cf:77:b0:de:ad:4a:47:ce:8c:96:49:5f:0a:cf:8c:ae:b2:6d:4b:8a:3f         TConstruct-1.18.2-3.7.1.155.jar                   |Tinkers' Construct            |tconstruct                    |3.7.1.155           |DONE      |Manifest: NOSIGNATURE         FarmersDelight-1.18.2-1.2.3.jar                   |Farmer's Delight              |farmersdelight                |1.18.2-1.2.3        |DONE      |Manifest: NOSIGNATURE         DungeonCrawl-1.18.2-2.3.14.jar                    |Dungeon Crawl                 |dungeoncrawl                  |2.3.14              |DONE      |Manifest: NOSIGNATURE         ImmersivePetroleum-1.18.2-4.2.0-25.jar            |Immersive Petroleum           |immersivepetroleum            |4.2.0-25            |DONE      |Manifest: NOSIGNATURE         ImmersiveEngineering-1.18.2-8.4.0-161.jar         |Immersive Engineering         |immersiveengineering          |1.18.2-8.4.0-161    |DONE      |Manifest: 44:39:94:cf:1d:8c:be:3c:7f:a9:ee:f4:1e:63:a5:ac:61:f9:c2:87:d5:5b:d9:d6:8c:b5:3e:96:5d:8e:3f:b7         forge-1.18.2-40.2.18-universal.jar                |Forge                         |forge                         |40.2.18             |DONE      |Manifest: 84:ce:76:e8:45:35:e4:0e:63:86:df:47:59:80:0f:67:6c:c1:5f:6e:5f:4d:b3:54:47:1a:9f:7f:ed:5e:f2:90         expandability-6.0.0.jar                           |ExpandAbility                 |expandability                 |6.0.0               |DONE      |Manifest: NOSIGNATURE         curios-forge-1.18.2-5.0.9.2.jar                   |Curios API                    |curios                        |1.18.2-5.0.9.2      |DONE      |Manifest: NOSIGNATURE         flywheel-forge-1.18.2-0.6.10-105.jar              |Flywheel                      |flywheel                      |0.6.10-105          |DONE      |Manifest: NOSIGNATURE         Mantle-1.18.2-1.9.50.jar                          |Mantle                        |mantle                        |1.9.50              |DONE      |Manifest: NOSIGNATURE         create-1.18.2-0.5.1.f.jar                         |Create                        |create                        |0.5.1.f             |DONE      |Manifest: NOSIGNATURE         refinedstorage-1.10.6.jar                         |Refined Storage               |refinedstorage                |1.10.6              |DONE      |Manifest: NOSIGNATURE         jei-1.18.2-forge-10.2.1.1006.jar                  |Just Enough Items             |jei                           |10.2.1.1006         |DONE      |Manifest: NOSIGNATURE         journeymap-1.18.2-5.9.8-forge.jar                 |Journeymap                    |journeymap                    |5.9.8               |DONE      |Manifest: NOSIGNATURE         CTM-1.18.2-1.1.5+5.jar                            |ConnectedTexturesMod          |ctm                           |1.18.2-1.1.5+5      |DONE      |Manifest: NOSIGNATURE         citadel-1.11.3-1.18.2.jar                         |Citadel                       |citadel                       |1.11.3              |DONE      |Manifest: NOSIGNATURE         L_Enders Cataclysm-0.51-changed Them -1.18.2.jar  |Cataclysm Mod                 |cataclysm                     |1.0                 |DONE      |Manifest: NOSIGNATURE         chipped-forge-1.18.2-2.0.1.jar                    |Chipped                       |chipped                       |2.0.1               |DONE      |Manifest: NOSIGNATURE         StorageDrawers-1.18.2-10.2.1.jar                  |Storage Drawers               |storagedrawers                |10.2.1              |DONE      |Manifest: NOSIGNATURE         artifacts-1.18.2-4.2.3.jar                        |Artifacts                     |artifacts                     |1.18.2-4.2.3        |DONE      |Manifest: NOSIGNATURE     Flywheel Backend: GL33 Instanced Arrays     Crash Report UUID: 50c1a276-b251-4bf8-b9f4-a76260acd047     FML: 40.2     Forge: net.minecraftforge:40.2.18
    • What MC version? What's the IP? Are any mods needed to be able to join?
    • Thank you for your answer ! Unfortunatly i have the same problem when i use setPos() public static int movingfunction(CommandContext<CommandSourceStack> context){ CommandSourceStack source = context.getSource(); if (!(source.getEntity() instanceof ServerPlayer)) { return 0; } ServerPlayer player = (ServerPlayer ) source.getEntity(); double moveSpeed = 0.5; for (int i =0; i<10000;i++) { LOGGER.info("running for the {} time", i); double x = player.getX() + player.getViewVector(1.0f).x * moveSpeed; double y = player.getY(); double z = player.getZ() + player.getViewVector(1.0f).z * moveSpeed ; Vec3 movementVec = new Vec3(x, y, z); LOGGER.info("x ={} y ={} z ={}", x, y, z); player.setPos( movementVec); } return 1; } With the logs i can see that x and z are increasing but once again my player is not moving. is there a function to use to sync the server and the client ? I also tried to use LocalPlayer instead of ServerPlayer but my code would stop when i got the object. Also i will change a bit the main topic but is there a way to similate key press ? i found KeyBinding.setKeyBindState on others post but it look like there is no more KeyBinding in 1.20   I found this code : KeyMapping.click(Minecraft.getInstance().options.keyUp.getKey()); But it doesn't seems to work   And i found this one : Minecraft.getInstance().options.keyUp.setDown(true); wich works but doesn't exactly do what i want , it doesn't release the key so for exemple i can't make him run. Minecraft.getInstance().options.keyUp.setDown(true); Minecraft.getInstance().options.keyUp.setDown(false); Minecraft.getInstance().options.keyUp.setDown(true); doesn't make him run
  • Topics

×
×
  • Create New...

Important Information

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