Jump to content

Recommended Posts

Posted

Hey, I'm trying to the health and damage attributes switch values whenever a certain condition for the entity is met. I tried switching where the method is called but nothing changes. Here is my code

 

	@Override
public void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896);
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.wildHealth());
	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(this.wildDamage());
	this.updateEntityAttributes();
}

public void updateEntityAttributes() {
	if (this.isTamed()) {
		if (!this.isChild() && !this.hasEvolved()) {
			this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.tamedHealth() + this.effectiveLevel());
			this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(this.tamedDamage());
		}
		else if (!this.isChild() && this.hasEvolved()) {
			this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.evoHealth());
		}
		else {
			this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.babyHealth());
			this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(this.babyDamage());
		}
	}
	else {
		if (this.isChild()) {
			this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.babyHealth());
			this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(this.babyDamage());
		}
	}
}

public double tamedHealth() { // TODO
	if (this instanceof EntityZertum || this instanceof EntityRedZertum) {
		return 35;
	}
	else if (this instanceof EntityMetalZertum || this instanceof EntityIceZertum || this instanceof EntityForisZertum || this instanceof EntityDestroZertum || this instanceof EntityDarkZertum) {
		return 40;
	}
	return 0;
}

public double tamedDamage() {
	if (this instanceof EntityZertum || this instanceof EntityRedZertum || this instanceof EntityMetalZertum || this instanceof EntityIceZertum || this instanceof EntityForisZertum) {
		return 8;
	}
	else if (this instanceof EntityDestroZertum) {
		return 10;
	}
	else if (this instanceof EntityDarkZertum) {
		return 12;
	}
	return 0;
}

public double evoHealth() {
	if (this instanceof EntityZertum || this instanceof EntityRedZertum || this instanceof EntityIceZertum) {
		return 45;
	}
	else if (this instanceof EntityMetalZertum || this instanceof EntityForisZertum || this instanceof EntityDestroZertum) {
		return 50;
	}
	else if (this instanceof EntityDarkZertum) {
		return 60;
	}
	return 0;
}

public double wildHealth() {
	if (this instanceof EntityZertum || this instanceof EntityRedZertum || this instanceof EntityForisZertum) {
		return 25;
	}
	else if (this instanceof EntityMetalZertum || this instanceof EntityDestroZertum || this instanceof EntityDarkZertum) {
		return 30;
	}
	else if (this instanceof EntityIceZertum) {
		return 35;
	}
	return 0;
}

public double wildDamage() {
	if (this instanceof EntityZertum || this instanceof EntityRedZertum || this instanceof EntityMetalZertum || this instanceof EntityIceZertum || this instanceof EntityForisZertum) {
		return 6;
	}
	else if (this instanceof EntityDestroZertum) {
		return 8;
	}
	else if (this instanceof EntityDarkZertum) {
		return 10;
	}
	return 0;
}

public double babyHealth() {
	return 10;
}

public double babyDamage() {
	if (this instanceof EntityZertum || this instanceof EntityRedZertum || this instanceof EntityMetalZertum) {
		return 2;
	}
	else if (this instanceof EntityIceZertum || this instanceof EntityForisZertum || this instanceof EntityDarkZertum) {
		return 4;
	}
	else if (this instanceof EntityDestroZertum) {
		return 3;
	}
	return 0;
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

  • Replies 98
  • Created
  • Last Reply

Top Posters In This Topic

Posted

applyEntityAttributes is called when the entity is first constructed (i.e. before NBT is read), so your entity does not yet know if it is a child or evolved or anything else.

 

You will need to update the attributes somewhere else, such as readFromNBT, onSpawnWithEgg, or better, when you set 'hasEvolved' or any other field that influences them.

 

The shared monster attributes are all saved, so if you set them once (such as from setEvolved() or whatever), they will retain the values you set when you reload the game.

Posted

I noticed that and now I got it to work, I did the same thing that in the EntityWolf did: it overrided the default setTame method and added the attribute switches. Also I put these switches in my commands that switches the birth stage of the creatures.  I have another little issue though, the creature's stats are displayed in a GUI, the health and other stats are being updated but the damage and speed isn't changing when setting the creature to a baby (works when taming and evolving it, which ONLY changes the damage; but I have talents that changes the speed and damage). My code is on my Github: https://github.com/NovaViper/ZeroQuest/tree/master/src/main/java/common/zeroquest

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

Without searching through your entire code base for unnamed classes, the issue seems to simply be that damage / speed attributes are not automatically sent to the client, whereas health and others are. Are you using attribute modifiers for damage and speed also?

 

If you are not using attribute modifiers for the talent bonuses, then that is your solution. If you are, then the solution is either to send a packet to update the client whenever a talent changes or, if the code happens to run on both sides, just apply the talent on both sides. You'll probably still want to send a packet at some point to validate that the value is correct on the client.

 

Show me your 'talent' code that affects damage and speed, as well as where you apply them.

Posted

Not exactly, the methods i'm using to get the values of the attributes are these

 

	@Override
public float getAIMoveSpeed() {
	double speed = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue();

	speed += TalentHelper.addToMoveSpeed(this);

	if ((!(this.getAttackTarget() instanceof EntityZertumEntity) && !(this.getAttackTarget() instanceof EntityPlayer)) || this.riddenByEntity instanceof EntityPlayer) {
		if (this.levels.getLevel() == Constants.maxLevel && this.hasEvolved()) {
			speed += 1.0D;
		}
		else if (this.hasEvolved() && this.levels.getLevel() != Constants.maxLevel) {
			speed += 1.0D;
		}
	}

	if (this.riddenByEntity instanceof EntityPlayer) {
		speed /= 4;
	}

	return (float) speed;
}

public float getAIAttackDamage() { // TODO
	double damage = this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
	damage += TalentHelper.addToAttackDamage(this);

	if ((!(this.getAttackTarget() instanceof EntityZertumEntity) && !(this.getAttackTarget() instanceof EntityPlayer))) {
		if (this.levels.getLevel() == Constants.maxLevel && this.hasEvolved()) {
			damage += 2.0D;
		}
		else if (this.hasEvolved() && this.levels.getLevel() != Constants.maxLevel) {
			damage += 2.0D;
		}
	}

	return (float) damage;
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

Instead of TalentHelper and manually adding adjustments for being evolved, why not add speed modifier as part of the talent / when the entity evolves? Then the entity's speed will be adjusted automatically. Otherwise, you will need to send all of your talents and evolved statuses to the client for it to display the bonuses properly.

Posted

The TalentHelper is for the talents, it adds onto the attribute when the level of the talent is increased. I have this method in the Dasher talent (which adds to the speed of the entity)

 

	@Override
public double addToMoveSpeed(EntityZertumEntity dog) {
	double speed = 0.0D;
	int level = dog.talents.getLevel(this);

	if ((!(dog.getAttackTarget() instanceof EntityZertumEntity) && !(dog.getAttackTarget() instanceof EntityPlayer)) || dog.riddenByEntity instanceof EntityPlayer) {
		if (level == 5) {
			speed += 0.04D;
		}
	}
	speed += 0.03D * level;
	return speed;
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

I realize what your TalentHelper is for, my point is why use it to directly modify the returned speed value when you could instead add an attribute modifier to speed each time your talent changes? This way, you don't have to do ANY calculations at all when returning speed - it is all handled automatically by the SharedMonsterAttribute / AttributeModifiers, which should also automatically be known by the client so you can display the appropriate speed value.

Posted

Hey I fixed it, I added dog.updateEntityAttributes in the TalentHelper methods like so and got it working

 

	public static double addToMoveSpeed(EntityZertumEntity dog) {
	double total = 0;
	for (ITalent talent : TalentRegistry.getTalents()) {
		total += talent.addToMoveSpeed(dog);
		dog.updateEntityAttributes();
	}
	return total;
}

public static double addToAttackDamage(EntityZertumEntity dog) {
	double total = 0;
	for (ITalent talent : TalentRegistry.getTalents()) {
		total += talent.addToAttackDamage(dog);
		dog.updateEntityAttributes();
	}
	return total;
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

Oh hey, I have another issue relating to the GUI, the client keeps on crashing whenever I right click on an entity when I am logged in as a different user.

Crash Log

[21:26:53] [server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2589ms behind, skipping 51 tick(s)
[21:31:16] [server thread/INFO]: Stopping server
[21:31:16] [server thread/INFO]: Saving players
[21:31:16] [server thread/INFO]: Saving worlds
[21:31:16] [server thread/INFO]: Saving chunks for level 'New World'/Overworld
[21:31:16] [server thread/INFO]: Saving chunks for level 'New World'/Nether
[21:31:16] [server thread/INFO]: Saving chunks for level 'New World'/The End
[21:31:16] [server thread/INFO]: Saving chunks for level 'New World'/Darkax
[21:31:16] [server thread/INFO]: Saving chunks for level 'New World'/Nillax
[21:31:17] [server thread/INFO] [FML]: Unloading dimension 0
[21:31:17] [server thread/INFO] [FML]: Unloading dimension -1
[21:31:17] [server thread/INFO] [FML]: Unloading dimension 1
[21:31:17] [server thread/INFO] [FML]: Unloading dimension 3
[21:31:17] [server thread/INFO] [FML]: Unloading dimension 2
[21:31:17] [server thread/INFO] [FML]: Applying holder lookups
[21:31:17] [server thread/INFO] [FML]: Holder lookups applied
[21:31:19] [Client thread/FATAL]: Reported exception thrown!
net.minecraft.util.ReportedException: Rendering screen
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1164) ~[EntityRenderer.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1107) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]
Caused by: java.lang.NullPointerException
at common.zeroquest.client.gui.GuiDogInfo.drawScreen(GuiDogInfo.java:141) ~[GuiDogInfo.class:?]
at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:462) ~[ForgeHooksClient.class:?]
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1134) ~[EntityRenderer.class:?]
... 11 more
[21:31:19] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:660]: ---- Minecraft Crash Report ----
// I feel sad now 

Time: 5/4/15 9:31 PM
Description: Rendering screen

java.lang.NullPointerException: Rendering screen
at common.zeroquest.client.gui.GuiDogInfo.drawScreen(GuiDogInfo.java:141)
at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:462)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1134)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1107)
at net.minecraft.client.Minecraft.run(Minecraft.java:376)
at net.minecraft.client.main.Main.main(Main.java:117)
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 net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)


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

-- Head --
Stacktrace:
at common.zeroquest.client.gui.GuiDogInfo.drawScreen(GuiDogInfo.java:141)
at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:462)

-- Screen render details --
Details:
Screen name: common.zeroquest.client.gui.GuiDogInfo
Mouse location: Scaled: (341, 176). Absolute: (683, 353)
Screen size: Scaled: (683, 353). Absolute: (1366, 706). Scale factor of 2

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityPlayerSP['Player785'/181, l='MpServer', x=-196.16, y=4.00, z=1167.38]]
Chunk stats: MultiplayerChunkCache: 440, 440
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: -138.00,4.00,1142.00 - World: (-138,4,1142), Chunk: (at 6,0,6 in -9,71; contains blocks -144,0,1136 to -129,255,1151), Region: (-1,2; contains chunks -32,64 to -1,95, blocks -512,0,1024 to -1,255,1535)
Level time: 40930 game time, 27144 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 104 total; [EntityVillager['Villager'/17, l='MpServer', x=-273.44, y=5.00, z=1147.09], EntityVillager['Villager'/18, l='MpServer', x=-276.69, y=4.00, z=1145.91], EntityVillager['Villager'/19, l='MpServer', x=-273.09, y=6.00, z=1163.56], EntitySlime['Slime'/26, l='MpServer', x=-270.75, y=4.00, z=1240.66], EntitySlime['Slime'/29, l='MpServer', x=-262.50, y=4.00, z=1141.00], EntityVillager['Villager'/30, l='MpServer', x=-267.72, y=4.00, z=1142.53], EntityBat['Bat'/31, l='MpServer', x=-269.81, y=6.10, z=1148.38], EntityBat['Bat'/32, l='MpServer', x=-271.88, y=6.10, z=1157.19], EntityVillager['Villager'/33, l='MpServer', x=-269.81, y=4.00, z=1166.50], EntityVillager['Villager'/34, l='MpServer', x=-271.09, y=5.00, z=1160.94], EntitySlime['Slime'/35, l='MpServer', x=-258.19, y=5.16, z=1164.16], EntityVillager['Villager'/36, l='MpServer', x=-269.09, y=5.00, z=1163.50], EntitySlime['Slime'/37, l='MpServer', x=-261.50, y=4.00, z=1171.88], EntityVillager['Villager'/38, l='MpServer', x=-278.25, y=5.00, z=1159.50], EntityVillager['Villager'/39, l='MpServer', x=-256.22, y=5.00, z=1174.47], EntitySlime['Slime'/40, l='MpServer', x=-264.34, y=4.00, z=1227.03], EntityPig['Pig'/44, l='MpServer', x=-244.31, y=4.00, z=1093.09], EntityPig['Pig'/45, l='MpServer', x=-239.94, y=4.00, z=1103.09], EntityBat['Bat'/46, l='MpServer', x=-251.25, y=7.10, z=1166.31], EntitySlime['Slime'/47, l='MpServer', x=-251.91, y=4.00, z=1158.13], EntityItem['item.item.rottenFlesh'/48, l='MpServer', x=-240.75, y=4.00, z=1162.41], EntitySlime['Slime'/49, l='MpServer', x=-250.22, y=5.00, z=1155.22], EntityBat['Bat'/50, l='MpServer', x=-252.25, y=8.10, z=1164.25], EntityVillager['Villager'/51, l='MpServer', x=-236.84, y=5.00, z=1155.72], EntitySlime['Slime'/52, l='MpServer', x=-240.09, y=5.00, z=1153.63], EntityCreeper['Creeper'/53, l='MpServer', x=-257.03, y=5.00, z=1172.47], EntityItem['item.item.egg'/54, l='MpServer', x=-242.38, y=4.00, z=1168.91], EntityVillager['Villager'/55, l='MpServer', x=-251.66, y=5.00, z=1164.78], EntityVillager['Villager'/56, l='MpServer', x=-243.78, y=5.00, z=1180.31], EntityVillager['Villager'/57, l='MpServer', x=-247.56, y=6.00, z=1181.22], EntityVillager['Villager'/58, l='MpServer', x=-254.50, y=4.00, z=1186.28], EntitySlime['Slime'/59, l='MpServer', x=-248.19, y=4.00, z=1228.19], EntitySlime['Slime'/60, l='MpServer', x=-252.13, y=4.00, z=1235.25], EntityPig['Pig'/67, l='MpServer', x=-232.09, y=4.00, z=1096.97], EntityItem['item.item.wheat'/68, l='MpServer', x=-232.75, y=5.00, z=1158.88], EntityItem['item.item.seeds'/69, l='MpServer', x=-231.50, y=5.00, z=1158.97], EntityChicken['Chicken'/70, l='MpServer', x=-227.66, y=4.00, z=1182.34], EntitySlime['Slime'/71, l='MpServer', x=-233.53, y=4.00, z=1178.63], EntitySlime['Slime'/72, l='MpServer', x=-221.06, y=4.00, z=1220.75], EntityPig['Pig'/74, l='MpServer', x=-212.31, y=4.00, z=1093.56], EntityChicken['Chicken'/75, l='MpServer', x=-210.47, y=4.00, z=1106.13], EntityChicken['Chicken'/76, l='MpServer', x=-222.47, y=4.00, z=1113.31], EntityItem['item.item.bone'/77, l='MpServer', x=-216.16, y=4.00, z=1134.56], EntitySlime['Slime'/78, l='MpServer', x=-207.34, y=4.00, z=1123.38], EntityItem['item.item.arrow'/79, l='MpServer', x=-220.44, y=4.00, z=1125.66], EntityItem['item.item.bone'/80, l='MpServer', x=-219.94, y=4.00, z=1125.06], EntityItem['item.item.arrow'/81, l='MpServer', x=-216.28, y=4.00, z=1134.41], EntityChicken['Chicken'/82, l='MpServer', x=-212.34, y=4.00, z=1154.41], EntityItem['item.item.arrow'/83, l='MpServer', x=-217.78, y=4.00, z=1203.97], EntityItem['item.item.bone'/84, l='MpServer', x=-217.06, y=4.00, z=1203.53], EntityItem['item.item.arrow'/85, l='MpServer', x=-208.13, y=4.00, z=1210.44], EntityItem['item.item.arrow'/86, l='MpServer', x=-212.53, y=4.00, z=1202.25], EntitySlime['Slime'/87, l='MpServer', x=-209.34, y=4.75, z=1220.75], EntitySlime['Slime'/88, l='MpServer', x=-212.75, y=4.78, z=1243.69], EntitySlime['Slime'/90, l='MpServer', x=-220.34, y=4.00, z=1241.44], EntitySlime['Slime'/91, l='MpServer', x=-219.16, y=4.00, z=1247.97], EntitySlime['Slime'/97, l='MpServer', x=-210.09, y=4.47, z=1092.06], EntityChicken['Chicken'/99, l='MpServer', x=-200.41, y=4.00, z=1111.03], EntitySlime['Slime'/100, l='MpServer', x=-210.38, y=4.00, z=1108.03], EntityItem['item.item.egg'/101, l='MpServer', x=-205.97, y=4.00, z=1107.56], EntityChicken['Chicken'/102, l='MpServer', x=-198.44, y=4.00, z=1123.38], EntityCreeper['Creeper'/103, l='MpServer', x=-196.19, y=4.00, z=1128.59], EntitySlime['Slime'/104, l='MpServer', x=-202.22, y=5.16, z=1148.94], EntitySpider['Spider'/105, l='MpServer', x=-194.28, y=4.00, z=1155.66], EntitySlime['Slime'/106, l='MpServer', x=-202.59, y=4.02, z=1147.91], EntityItem['item.item.egg'/107, l='MpServer', x=-196.75, y=4.00, z=1159.19], EntityMetalZertum['Blast Max'/108, l='MpServer', x=-195.81, y=4.00, z=1170.22], EntityMetalZertum[''/109, l='MpServer', x=-192.66, y=4.00, z=1179.34], EntitySlime['Slime'/110, l='MpServer', x=-197.44, y=5.22, z=1165.75], EntityItem['item.item.bone'/111, l='MpServer', x=-207.81, y=4.00, z=1211.16], EntitySlime['Slime'/112, l='MpServer', x=-198.16, y=4.00, z=1229.84], EntitySpider['Spider'/113, l='MpServer', x=-207.00, y=4.00, z=1216.63], EntitySlime['Slime'/116, l='MpServer', x=-179.72, y=4.00, z=1158.66], EntityItem['item.item.bone'/117, l='MpServer', x=-183.38, y=4.00, z=1192.78], EntityPig['Pig'/118, l='MpServer', x=-190.84, y=4.00, z=1191.44], EntitySlime['Slime'/119, l='MpServer', x=-184.34, y=4.00, z=1236.69], EntityCow['Cow'/122, l='MpServer', x=-158.78, y=4.00, z=1088.88], EntityPig['Pig'/123, l='MpServer', x=-166.03, y=4.00, z=1142.97], EntityChicken['Chicken'/124, l='MpServer', x=-164.50, y=4.00, z=1165.03], EntitySlime['Slime'/125, l='MpServer', x=-158.50, y=4.00, z=1176.25], EntitySlime['Slime'/126, l='MpServer', x=-166.25, y=4.00, z=1177.78], EntitySlime['Slime'/127, l='MpServer', x=-162.84, y=4.00, z=1182.50], EntityItem['item.item.rottenFlesh'/128, l='MpServer', x=-160.78, y=4.00, z=1190.44], EntityItem['item.item.arrow'/129, l='MpServer', x=-166.56, y=4.00, z=1215.88], EntityCow['Cow'/133, l='MpServer', x=-158.00, y=4.00, z=1090.47], EntitySlime['Slime'/134, l='MpServer', x=-148.69, y=4.00, z=1169.56], EntitySlime['Slime'/135, l='MpServer', x=-150.94, y=4.00, z=1187.91], EntitySlime['Slime'/136, l='MpServer', x=-151.97, y=4.42, z=1191.66], EntitySlime['Slime'/137, l='MpServer', x=-151.00, y=5.00, z=1191.81], EntitySlime['Slime'/138, l='MpServer', x=-154.03, y=5.00, z=1187.69], EntityItem['item.item.rottenFlesh'/139, l='MpServer', x=-159.03, y=4.00, z=1202.56], EntityPig['Pig'/140, l='MpServer', x=-149.13, y=4.00, z=1201.31], EntitySlime['Slime'/145, l='MpServer', x=-146.84, y=4.47, z=1186.75], EntitySlime['Slime'/146, l='MpServer', x=-138.88, y=4.00, z=1198.03], EntitySlime['Slime'/147, l='MpServer', x=-139.66, y=4.00, z=1188.97], EntitySlime['Slime'/148, l='MpServer', x=-140.66, y=4.02, z=1193.66], EntitySlime['Slime'/149, l='MpServer', x=-130.66, y=4.75, z=1201.03], EntityPig['Pig'/150, l='MpServer', x=-143.13, y=4.00, z=1203.94], EntitySpider['Spider'/151, l='MpServer', x=-131.41, y=4.00, z=1236.84], EntitySlime['Slime'/154, l='MpServer', x=-128.22, y=4.42, z=1096.41], EntitySlime['Slime'/156, l='MpServer', x=-123.22, y=4.00, z=1180.28], EntitySlime['Slime'/158, l='MpServer', x=-117.16, y=5.16, z=1210.75], EntitySlime['Slime'/159, l='MpServer', x=-125.47, y=4.00, z=1218.63], EntityPlayerSP['Player785'/181, l='MpServer', x=-196.16, y=4.00, z=1167.38]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:392)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2606)
at net.minecraft.client.Minecraft.run(Minecraft.java:398)
at net.minecraft.client.main.Main.main(Main.java:117)
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 net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

 

 

GUI code

package common.zeroquest.client.gui;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;

import org.apache.commons.lang3.StringUtils;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import common.zeroquest.api.interfaces.ITalent;
import common.zeroquest.api.registry.TalentRegistry;
import common.zeroquest.entity.util.ModeUtil.EnumMode;
import common.zeroquest.entity.zertum.EntityZertumEntity;
import common.zeroquest.lib.Constants;
import common.zeroquest.network.PacketHandler;
import common.zeroquest.network.imessage.ZertumMode;
import common.zeroquest.network.imessage.ZertumName;
import common.zeroquest.network.imessage.ZertumObey;
import common.zeroquest.network.imessage.ZertumTalents;

/**
* @author ProPercivalalb
*/
public class GuiDogInfo extends GuiScreen {

public EntityZertumEntity dog;
public EntityPlayer player;
private ScaledResolution resolution;
private final List<GuiTextField> textfieldList = new ArrayList<GuiTextField>();
private GuiTextField nameTextField;
private int currentPage = 0;
private int maxPages = 1;
public int btnPerPages = 0;
private final DecimalFormat dfShort = new DecimalFormat("0.00");

public GuiDogInfo(EntityZertumEntity dog, EntityPlayer player) {
	this.dog = dog;
	this.player = player;
}

@Override
public void initGui() {
	super.initGui();
	this.buttonList.clear();
	this.labelList.clear();
	this.textfieldList.clear();
	this.resolution = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
	Keyboard.enableRepeatEvents(true);
	int topX = this.width / 2;
	int topY = this.height / 2;
	GuiTextField nameTextField = new GuiTextField(0, this.fontRendererObj, topX - 100, topY + 50, 200, 20) {
		@Override
		public boolean textboxKeyTyped(char character, int keyId) {
			boolean typed = super.textboxKeyTyped(character, keyId);
			if (typed) {
				PacketHandler.sendToServer(new ZertumName(dog.getEntityId(), this.getText()));
			}
			return typed;
		}
	};
	nameTextField.setFocused(false);
	nameTextField.setMaxStringLength(32);
	nameTextField.setText(this.dog.getZertumName());
	this.nameTextField = nameTextField;

	this.textfieldList.add(nameTextField);

	int size = TalentRegistry.getTalents().size();

	int temp = 0;
	while ((temp + 2) * 21 + 10 < this.resolution.getScaledHeight()) {
		temp += 1;
	}

	this.btnPerPages = temp;

	if (temp < size) {
		this.buttonList.add(new GuiButton(-1, 25, temp * 21 + 10, 20, 20, "<"));
		this.buttonList.add(new GuiButton(-2, 48, temp * 21 + 10, 20, 20, ">"));
	}

	if (this.btnPerPages < 1) {
		this.btnPerPages = 1;
	}

	this.maxPages = (int) Math.ceil((double) TalentRegistry.getTalents().size() / (double) this.btnPerPages);

	if (this.currentPage >= this.maxPages) {
		this.currentPage = 0;
	}

	for (int i = 0; i < this.btnPerPages; ++i) {
		if ((this.currentPage * this.btnPerPages + i) >= TalentRegistry.getTalents().size()) {
			continue;
		}
		this.buttonList.add(new GuiButton(1 + this.currentPage * this.btnPerPages + i, 25, 10 + i * 21, 20, 20, "+"));
	}
	if (this.dog.isOwner(this.player)) {
		this.buttonList.add(new GuiButton(-5, this.width - 64, topY + 65, 42, 20, String.valueOf(this.dog.willObeyOthers())));
	}

	this.buttonList.add(new GuiButton(-6, topX + 40, topY + 25, 60, 20, this.dog.mode.getMode().modeName()));
}

@Override
public void drawScreen(int xMouse, int yMouse, float partialTickTime) {
	this.drawDefaultBackground();
	// Background
	int topX = this.width / 2;
	int topY = this.height / 2;
	String health = dfShort.format(this.dog.getHealth());
	String healthMax = dfShort.format(this.dog.getMaxHealth());
	String healthRel = dfShort.format(this.dog.getHealthRelative() * 100);
	String healthState = health + "/" + healthMax + "(" + healthRel + "%)";
	String damageValue = dfShort.format(this.dog.getAIAttackDamage());
	String damageState = damageValue;
	String speedValue = dfShort.format(this.dog.getAIMoveSpeed());
	String speedState = speedValue;

	String tamedString = null;
	if (this.dog.isTamed()) {
		Entity player = this.dog.getOwner();
		if (player != null) {
			tamedString = "Yes (You)";
		}
		else {
			tamedString = "Yes (" + StringUtils.abbreviate(this.dog.getOwner().getName(), 22) + ")";
		}
	}

	String evoString = null;
	if (!this.dog.hasEvolved() && !this.dog.isChild() && this.dog.levels.getLevel() < Constants.maxLevel) {
		evoString = "Not at Alpha Level!";
	}
	else if (!this.dog.hasEvolved() && this.dog.isChild() && this.dog.levels.getLevel() < Constants.maxLevel) {
		evoString = "Too Young!";
	}
	else if (!this.dog.hasEvolved() && !this.dog.isChild() && this.dog.levels.getLevel() >= Constants.maxLevel) {
		evoString = "Ready!";
	}
	else if (this.dog.hasEvolved() && !this.dog.isChild()) {
		evoString = "Already Evolved!";
	}

	this.fontRendererObj.drawString("New name:", topX - 100, topY + 38, 4210752);
	this.fontRendererObj.drawString("Level: " + this.dog.levels.getLevel(), topX - 75, topY + 75, 0xFF10F9);
	this.fontRendererObj.drawString("Points Left: " + this.dog.spendablePoints(), topX, topY + 75, 0xFFFFFF);
	this.fontRendererObj.drawString("Health: " + healthState, topX + 190, topY - 170, 0xFFFFFF);
	this.fontRendererObj.drawString("Damage: " + damageState, topX + 190, topY - 160, 0xFFFFFF);
	this.fontRendererObj.drawString("Speed: " + speedState, topX + 190, topY - 150, 0xFFFFFF);
	this.fontRendererObj.drawString("Tamed: " + tamedString, topX + 190, topY - 140, 0xFFFFFF);
	this.fontRendererObj.drawString("State: " + evoString, topX + 190, topY - 130, 0xFFFFFF);
	if (this.dog.isOwner(this.player)) {
		this.fontRendererObj.drawString("Obey Others?", this.width - 76, topY + 55, 0xFFFFFF);
	}

	for (int i = 0; i < this.btnPerPages; ++i) {
		if ((this.currentPage * this.btnPerPages + i) >= TalentRegistry.getTalents().size()) {
			continue;
		}
		this.fontRendererObj.drawString(TalentRegistry.getTalent(this.currentPage * this.btnPerPages + i).getLocalisedName(), 50, 17 + i * 21, 0xFFFFFF);
	}

	for (GuiTextField field : this.textfieldList) {
		field.drawTextBox();
	}
	GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	RenderHelper.disableStandardItemLighting();
	GL11.glDisable(GL11.GL_LIGHTING);
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	super.drawScreen(xMouse, yMouse, partialTickTime);
	RenderHelper.enableGUIStandardItemLighting();

	// Foreground

	GL11.glPushMatrix();
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	for (int k = 0; k < this.buttonList.size(); ++k) {
		GuiButton button = (GuiButton) this.buttonList.get(k);
		if (button.mousePressed(this.mc, xMouse, yMouse)) {
			List list = new ArrayList();
			if (button.id >= 1 && button.id <= TalentRegistry.getTalents().size()) {
				ITalent talent = TalentRegistry.getTalent(button.id - 1);

				list.add(EnumChatFormatting.GREEN + talent.getLocalisedName());
				list.add("Level: " + this.dog.talents.getLevel(talent));
				list.add(EnumChatFormatting.GRAY + "--------------------------------");
				list.addAll(this.splitInto(talent.getLocalisedInfo(), 200, this.mc.fontRendererObj));
			}
			else if (button.id == -1) {
				list.add(EnumChatFormatting.ITALIC + "Previous Page");
			}
			else if (button.id == -2) {
				list.add(EnumChatFormatting.ITALIC + "Next Page");
			}
			else if (button.id == -6) {
				String str = StatCollector.translateToLocal("modeinfo." + button.displayString.toLowerCase());
				list.addAll(splitInto(str, 150, this.mc.fontRendererObj));
			}

			this.drawHoveringText(list, xMouse, yMouse, this.mc.fontRendererObj);
		}
	}
	GL11.glPopMatrix();
}

@Override
protected void actionPerformed(GuiButton button) {

	if (button.id >= 1 && button.id <= TalentRegistry.getTalents().size()) {
		ITalent talent = TalentRegistry.getTalent(button.id - 1);
		int level = this.dog.talents.getLevel(talent);

		if (level < talent.getHighestLevel(this.dog) && this.dog.spendablePoints() >= talent.getCost(this.dog, level + 1)) {
			PacketHandler.sendToServer(new ZertumTalents(this.dog.getEntityId(), TalentRegistry.getTalent(button.id - 1).getKey()));
		}

	}
	else if (button.id == -1) {
		if (this.currentPage > 0) {
			this.currentPage -= 1;
			this.initGui();
		}
	}
	else if (button.id == -2) {
		if (this.currentPage + 1 < this.maxPages) {
			this.currentPage += 1;
			this.initGui();
		}
	}
	if (button.id == -5) {
		if (!this.dog.willObeyOthers()) {
			button.displayString = "true";
			PacketHandler.sendToServer(new ZertumObey(this.dog.getEntityId(), true));

		}
		else {
			button.displayString = "false";
			PacketHandler.sendToServer(new ZertumObey(this.dog.getEntityId(), false));
		}
	}

	if (button.id == -6) {
		int newMode = (dog.mode.getMode().ordinal() + 1) % EnumMode.values().length;
		EnumMode mode = EnumMode.values()[newMode];
		button.displayString = mode.modeName();
		PacketHandler.sendToServer(new ZertumMode(this.dog.getEntityId(), newMode));
	}
}

@Override
public void updateScreen() {
	for (GuiTextField field : this.textfieldList) {
		field.updateCursorCounter();
	}
}

@Override
public void mouseClicked(int xMouse, int yMouse, int mouseButton) throws IOException {
	super.mouseClicked(xMouse, yMouse, mouseButton);
	for (GuiTextField field : this.textfieldList) {
		field.mouseClicked(xMouse, yMouse, mouseButton);
	}
}

@Override
public void keyTyped(char character, int keyId) {
	for (GuiTextField field : this.textfieldList) {
		field.textboxKeyTyped(character, keyId);
	}

	if (keyId == Keyboard.KEY_ESCAPE) {
		this.mc.thePlayer.closeScreen();
	}
}

@Override
public void onGuiClosed() {
	Keyboard.enableRepeatEvents(false);
}

@Override
public boolean doesGuiPauseGame() {
	return false;
}

public List splitInto(String text, int maxLength, FontRenderer font) {
	List list = new ArrayList();

	String temp = "";
	String[] split = text.split(" ");

	for (int i = 0; i < split.length; ++i) {
		String str = split[i];
		int length = font.getStringWidth(temp + str);

		if (length > maxLength) {
			list.add(temp);
			temp = "";
		}

		temp += str + " ";

		if (i == split.length - 1) {
			list.add(temp);
		}
	}

	return list;
}
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

When the dog entity is not tamed, tamedString remains null and makes crash.

You should initialize it to something other like "Not Tamed" instead of null.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Here

 this.fontRendererObj.drawString("Tamed: " + tamedString, topX + 190, topY - 140, 0xFFFFFF);

 

But its something associated with this

 String tamedString = null;
	if (this.dog.isTamed()) {
		Entity player = this.dog.getOwner();
		if (player != null) {
			tamedString = "Yes (You)";
		}
		else {
			tamedString = "Yes (" + StringUtils.abbreviate(this.dog.getOwner().getName(), 22) + ")";
		}
	}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

No. The tamedString is null.

I already said:

When the dog entity is not tamed, tamedString remains null and makes crash.

You should initialize it to something other like "Not Tamed" instead of null.

 

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

It is null when the dog is not tamed. See the code, all substitutions to tamedString is in if(this.dog.isTamed())

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

What I want it to do is say the entity's owner name when another player that does not know thr entity opens the Gui and say 'You' when the owner opens the GUI

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

First: we don't have all the code.

Second: We have no clear answer on which line the error actually occurs.

But it is clear that the line

this.fontRendererObj.drawString("Tamed: " + tamedString, topX + 190, topY - 140, 0xFFFFFF);

can throw the NPE with tamedString. See the code in GuiDogInfo#drawScreen(int xMouse, int yMouse, float partialTickTime).

tamedString is local variable in the method, it is initialized as null,

and it is only substituted with valid value only if the dog is tamed. So it throws NPE otherwise.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

What I want it to do is say the entity's owner name when another player that does not know thr entity opens the Gui and say 'You' when the owner opens the GUI

There is nothing wrong with your logic, you should only take care of exceptions. You should initialize tamedString to valid String, not null. (Show it as 'Not Tamed', etc.)

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

But it is clear that the line

this.fontRendererObj.drawString("Tamed: " + tamedString, topX + 190, topY - 140, 0xFFFFFF);

can throw the NPE with tamedString.

This is wrong.

System.out.println("hello" + null); // prints "hellonull"

So it was not clear; I'm blind. Sorry for that.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

=/ =;

@NovaViper

So did you check if the dog's owner is not null?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Not yet. Atm I'm not near my computer unfortunately. Later on after my classes, i'll check it

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

=/ =;

@NovaViper

So did you check if the dog's owner is not null?

 

Somehow, it is null. But I'm trying to make it that if the player isn't in the world, the entity displays that name.

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

Somehow, it is null. But I'm trying to make it that if the player isn't in the world, the entity displays that name.

Then save the player's nickname and UUID, and loads the owner instance when he logs in. (Or in readNBT alongside)

(Or it can also be Entity, since entities have UUID and displayname too)

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

How exactly do I save it?

Seems like you're having the same issue as Thornack, and the solution will be the same: when you have a valid owner entity, store the display name in another one of your entity's DataWatcher slots (assuming you need it on the client); then be sure to save that value to your entity's NBT tag when it saves, and load it back when it loads.

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

    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • 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.