Jump to content

Recommended Posts

Posted

Hello community,

 

the other day i had request about some problems i had with texturing a block, it was recommended to me to have a look into packet handling and client server communications. The first thing i did was to figure out whether it was the server or the client having the problem by doing this:

 

	public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);
	this.direction = nbt.getString("DIRECTION");
	Side side = FMLCommonHandler.instance().getEffectiveSide();
	if(side != null && side == Side.SERVER){System.out.println("Server read");}
	if(side != null && side == Side.CLIENT){System.out.println("Client read");}
}

public void writeToNBT(NBTTagCompound nbt){
    super.writeToNBT(nbt);
	//System.out.println(this.direction);
	nbt.setString("DIRECTION", this.direction);
	Side side = FMLCommonHandler.instance().getEffectiveSide();
	if(side != null && side == Side.SERVER){System.out.println("Server wrote");}
	if(side != null && side == Side.CLIENT){System.out.println("Client wrote");}
}

 

It turned out the server is working perfectly fine and that, much to my surprise, it is the client not working properly.

It does neither save to or read from NBT.

 

Thus my first question is: Is this a normal behaviour?

And the second: Do i have to somehow force the client to write and read on its own or can this only be solved by using packets? If so, are there any tutorials other than "http://www.minecraftforge.net/wiki/How_to_use_NBT_Tag_Compound" about how to do this you guys know about?

(Google wasn't much of help)

I *assume* i will need to use packets in order to have other clients see the same thing as the one who set the block does.

I was surprised to see that EE3 (looked it up on github) appears not be using any sort of client server communications for its nbt tags.

 

Well, i hope someone can advice me on this

 

// update:

Some testing with the furnace showed me that it is a normal thing that the client does not read/write to nbt.

Yet i'm not really sure where, when und how to send/receive packages i hope that further studying of opensource mods will help me with this. Help on this however would still be appreciated.

Posted

Thanks diesieben07,

 

at first i was still somewhat unsure on how to implement those functions properly so i had a look at the ironchests mod's code and eventually got my code to work. I will put all the functions etc. necessary in this post so as that

a) you (or anyone else for that matter) can tell me whether there is something that could be done in a more efficient way b) anyone who has the same a or a related problem might look the solution up in this thread.

 

Tile Entity:

@Override
public Packet getDescriptionPacket(){
        NBTTagCompound nbt = new NBTTagCompound();
        nbt.setString("DIRECTION", this.direction);
        return new Packet132TileEntityData(xCoord,yCoord,zCoord,1,nbt);
}

public void setDirection(String newDirection){
	this.direction = newDirection;
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}

@Override
    public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
    {
    	this.direction = pkt.customParam1.getString("DIRECTION");
    }

public String getDirection(){
	return this.direction;
}

//Aditionally here's my function to determine a blocks direction relative to the player placing it:

public String direction = "NotSetYet";

public void setDirection(double playerHeight, float playerAngle){
	Side side = FMLCommonHandler.instance().getEffectiveSide();
	playerAngle = Math.abs(playerAngle) % 360;
	if(side == Side.CLIENT) playerHeight -= 1.62;
	if(playerHeight % 1 >= 0.5)playerHeight = (int)playerHeight+1; else playerHeight = (int)playerHeight;

	if(this.direction.equals("NotSetYet")){
		if(playerHeight+1 < yCoord){
			if(playerAngle>=  0 && playerAngle< 45){this.direction ="USE";}
			if(playerAngle>= 45 && playerAngle< 90){this.direction ="UES";}
			if(playerAngle>= 90 && playerAngle<135){this.direction ="UEN";}
			if(playerAngle>=135 && playerAngle<180){this.direction ="UNE";}
			if(playerAngle>=180 && playerAngle<225){this.direction ="UNW";}
			if(playerAngle>=225 && playerAngle<270){this.direction ="UWN";}
			if(playerAngle>=270 && playerAngle<315){this.direction ="UWS";}
			if(playerAngle>=315 && playerAngle<360){this.direction ="USW";}
		}else{
			if(playerAngle>=  0 && playerAngle< 45){this.direction ="DSE";}
			if(playerAngle>= 45 && playerAngle< 90){this.direction ="DES";}
			if(playerAngle>= 90 && playerAngle<135){this.direction ="DEN";}
			if(playerAngle>=135 && playerAngle<180){this.direction ="DNE";}
			if(playerAngle>=180 && playerAngle<225){this.direction ="DNW";}
			if(playerAngle>=225 && playerAngle<270){this.direction ="DWN";}
			if(playerAngle>=270 && playerAngle<315){this.direction ="DWS";}
			if(playerAngle>=315 && playerAngle<360){this.direction ="DSW";}
		}
	}
}

Posted

a) you (or anyone else for that matter) can tell me whether there is something that could be done in a more efficient way b) anyone who has the same a or a related problem might look the solution up in this thread.

that's nice of you to share your working code, me (and probably other noobies) appreciate this behaviour :)

 

i would suggest reconsidering data representation of direction - string operations are not fastest, also this representation wastes memory and network resources (bigger packets).

"USE" ~ 3bytes ~ 256^3 = 16 777 216: it can represent 16 777 216 values (not counting size information of a string instance). but you only uses 16+1 values for directions, you could easily store it in 1 byte (e.g. using enum) ;)

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

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

    • Yep I did upgrade just because it showed me a new version available.  I'll redownload the mod list and make sure anything works.  Thanks!
    • The latest log was taken down by pastebin for some reason. Did you try removing the mods you added? The mods you updated, was there a specific reason you updated, or just because? It's possible the updates introduced incompatibilitie, or even need a newer build of forge. If you didn't need the updates for a specific reason, you could also try downgrading those mods.
    • Please read the FAQ, and post logs as described there. https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/
    • I am using forge 1.20.1 (version 47.3.0). My pc has an RTX 4080 super and an i9 14900 KF, I am on the latest Nvidia graphics driver, latest windows 10 software, I have java 23, forge 1.12.2 works and so does all vanilla versions but for some reason no version of forge 1.20.1 works and instead the game just crashes with the error code "-1." I have no mods in my mods fodler, I have deleted my options.txt and forge.cfg files in case my settings were causing a crash and have tried removing my forge version from the installations folder and reinstalling but no matter what I still crash with the same code and my log doesn't tell me anything: 18:34:53.924 game 2025-02-06 18:34:53,914 main WARN Advanced terminal features are not available in this environment 18:34:54.023 game [18:34:54] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, mrmirchi, --version, 1.20.1-forge-47.3.0, --gameDir, C:\Users\aryam\AppData\Roaming\.minecraft, --assetsDir, C:\Users\aryam\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 2db00ea8d678420a8956109a85d90e9d, --accessToken, ????????, --clientId, ZWI3NThkNzMtNmNlZS00MGI5LTgyZTgtYmZkNzcwMTM5MGMx, --xuid, 2535436222989555, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\aryam\AppData\Roaming\.minecraft\quickPlay\java\1738838092785.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.3.0, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] 18:34:54.027 game [18:34:54] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 18:34:54.132 game [18:34:54] [main/INFO] [ne.mi.fm.lo.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow 18:34:54.191 game [18:34:54] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6 18:34:54.303 game [18:34:54] [main/INFO] [EARLYDISPLAY/]: Requested GL version 4.6 got version 4.6 18:34:54.367 monitor Process Monitor Process crashed with exit code -1     screenshot of log: https://drive.google.com/file/d/1WdkH88H865XErvmIqAKjlg7yrmj8EYy7/view?usp=sharing
    • I am currently working on a big mod, but I'm having trouble with my tabs, I want to find a way to add tabs inside tabs, like how in mrcrayfishes furniture mod, his furniture tab has multiple other sub tabs to them, so i know it is possible but i just don't know how it is possible, any help would be appreciated, thanks
  • Topics

×
×
  • Create New...

Important Information

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