Jump to content

[1.11.2] [SOLVED!] How do I do Packets


GooberGunter

Recommended Posts

 

Hey, I have an event where an animation is triggered after the player attacks or right clicks the entity. When the entity is attacked or right clicked, it is supposed to trigger new AI (which I got working with ease) and set an animation to open the entity's eyes (which I'm struggling with). I accomplished the AI part with a pair of setters and getters for a boolean which returns true when the event happens. I also got a pair of setters and getters for the model class and set the boolean to equal the boolean in the entity class, as well as an if statement in the livinganimations to trigger the animation, which right now is just a simple edit to the model rotations.

 

Here is my model class

Spoiler

package com.ninja3659.explorationexpansion.client.model;

import java.awt.print.Book;

import com.ninja3659.explorationexpansion.client.entities.EntityBeelzebook;
import com.ninja3659.explorationexpansion.util.Utils;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLModIdMappingEvent.ModRemapping;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import scala.specialized;

public class ModelBeelzebook extends ModelBase{
	//EntityFlying

	public ModelRenderer book;
	public ModelRenderer BookTop;
	public ModelRenderer BookBottom;
	public ModelRenderer Eye1;
	public ModelRenderer Eye2;
	public ModelRenderer Eye3;
	public ModelRenderer Eye4;
	public ModelRenderer Spine;
	public ModelRenderer pagesT;
	public ModelRenderer pagesB;
	public ModelRenderer page1;
	public ModelRenderer page2;
	public ModelRenderer page3;
	public boolean awake;
	
	public ModelBeelzebook() {
		textureWidth = 128;
		textureHeight = 128;
		
		awake = false;
		book = new ModelRenderer(this, 0, 0);
		book.addBox(0, 0, 0, 0, 0, 0);
		book.setRotationPoint(0, 22, 0);
		
		BookTop = new ModelRenderer(this, 0, 0);
		BookTop.addBox(-10, -1.5f, -14, 20, 1, 14);
		BookTop.setRotationPoint(0, 0, 0);
		setRotation(BookTop, 0, 0, 0);
		book.addChild(BookTop);
		
		Eye1 = new ModelRenderer(this, 0, 32);
		Eye1.addBox(-1, -2, -2, 2, 2, 2);
		Eye1.setRotationPoint(-5, -1, -6);
		setRotation(Eye1, 81, 0, 0);
		BookTop.addChild(Eye1);
		
		Eye2 = new ModelRenderer(this, 0, 36);
		Eye2.addBox(-1, -2, -2, 2, 2, 2);
		Eye2.setRotationPoint(-2, -1, -8);
		setRotation(Eye2, 81, 0, 0);
		BookTop.addChild(Eye2);
		
		Eye3 = new ModelRenderer(this, 0, 40);
		Eye3.addBox(-1, -2, -2, 2, 2, 2);
		Eye3.setRotationPoint(4, 0, 0);
		Eye2.addChild(Eye3);
		
		Eye4 = new ModelRenderer(this, 0, 44);
		Eye4.addBox(-1, -2, -2, 2, 2, 2);
		Eye4.setRotationPoint(10, 0, 0);
		Eye1.addChild(Eye4);
		
		pagesT = new ModelRenderer(this, 0, 48);
		pagesT.addBox(-9, -.5f, -13, 18, 1, 13);
		pagesT.setRotationPoint(0, 0, 0);
		setRotation(pagesT, 0, 0, 0);
		BookTop.addChild(pagesT);
		
		BookBottom = new ModelRenderer(this, 0, 16);
		BookBottom.addBox(-10, .5f, -14, 20, 1, 14);
		BookBottom.setRotationPoint(0, 0, 0);
		book.addChild(BookBottom);
		
		pagesB = new ModelRenderer(this, 0, 48);
		pagesB.addBox(-9, -.5f, -13, 18, 1, 13);
		pagesB.setRotationPoint(0, 0, 0);
		BookBottom.addChild(pagesB);
		
		Spine = new ModelRenderer(this, 68, 13);
		Spine.addBox(-10, -1.5f, 0, 20, 3, 1);
		Spine.setRotationPoint(0, 0, 0);
		book.addChild(Spine);
		
		page1 = new ModelRenderer(this, 9, 32);
		page1.addBox(-1.5f, -19, 0, 3, 4, 0);
		page1.setRotationPoint(0, 0, 0);
		book.addChild(page1);
		
		page2 = new ModelRenderer(this, 9, 32);
		page2.addBox(-1.5f, -24, 0, 3, 4, 0);
		page2.setRotationPoint(0, 0, 0);
		book.addChild(page2);
		
		page3 = new ModelRenderer(this, 9, 32);
		page3.addBox(-1.5f, -29, 0, 3, 4, 0);
		page3.setRotationPoint(0, 0, 0);
		book.addChild(page3);
		
	}
	
	public void setAwake(boolean entityAwake) {
		this.awake = entityAwake;
	}
	
	public float deg2Rad(float d) {
		return d * ((float)Math.PI / 180);
	}
	
	public void setRotation(ModelRenderer model, float x, float y, float z) {
		model.rotateAngleX = deg2Rad(x);
		model.rotateAngleY = deg2Rad(y);
		model.rotateAngleZ  = deg2Rad(z);
	}
	

	@Override
	public void render(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
		renderBook((EntityBeelzebook) entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
		
	}
	
	public void renderBook(EntityBeelzebook entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
		book.render(scale);
		setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entity);
	}
	
	@Override
	public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw,
			float headPitch, float scaleFactor, Entity entityIn) {
		super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);
		BookTop.rotateAngleX = 0;
		BookBottom.rotateAngleX = MathHelper.cos(limbSwing * .666f) * .4F * limbSwingAmount + deg2Rad(20);
		
		if(awake) {
			AwakeAnimation((EntityBeelzebook) entityIn);
			Utils.getLogger().info("awake dude");
		}
		
//		if(entityIn.ticksExisted%60 == 0) {
//			book.rotateAngleX = headPitch * .666f;
//			book.rotateAngleY = netHeadYaw * .666f;
//		}
		deathAnim((EntityBeelzebook)entityIn, limbSwing, limbSwingAmount, ageInTicks);
	}
	
	public void deathAnim(EntityBeelzebook entity, float limbSwing, float limbSwingAmount, float ageInTicks) {
		if (entity.getdeathTime() != 0) {
			BookTop.rotateAngleX = deg2Rad(-(5 * MathHelper.cos(entity.ticksExisted * 2)) - 85);
			BookBottom.rotateAngleX = deg2Rad((5 * MathHelper.cos(entity.ticksExisted * 2)) +85);
		}		
	}	
	
	@Override
	public void setLivingAnimations(EntityLivingBase entitylivingbaseIn, float limbSwing, float limbSwingAmount,
			float partialTickTime) {
		if(awake) {
			AwakeAnimation((EntityBeelzebook) entitylivingbaseIn);
			Utils.getLogger().info("The model's good");
			
		}
		Utils.getLogger().info("hey its living animations");
	}
	
	public void AwakeAnimation(EntityBeelzebook entity) {
		setRotation(Eye1, 33, 0, 0);
		setRotation(Eye2, 33, 0, 0);
		Utils.getLogger().info("animation!");
	}

}

 

 

And here is the Entity class

Spoiler

package com.ninja3659.explorationexpansion.client.entities;

import com.ninja3659.explorationexpansion.client.ai.EntityAIWander3d;
import com.ninja3659.explorationexpansion.client.model.ModelBeelzebook;
import com.ninja3659.explorationexpansion.util.Utils;

import net.minecraft.enchantment.EnumEnchantmentType;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityFlying;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.EntityAIFindEntityNearestPlayer;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWanderAvoidWater;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.ai.EntityMoveHelper;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class EntityBeelzebook extends EntityFlying implements IMob {

	ModelBeelzebook bookmodel = new ModelBeelzebook();
	public boolean entityAwake;
	
	public EntityBeelzebook(World worldIn) {
		super(worldIn);
		this.experienceValue = 200;
		this.setSize(2, .5f);
		this.moveHelper = new BeelzebookMoveHelper(this);
		moveHelper.setMoveTo(0, 10, 0, 1D);
		this.entityAwake = false;
		
	}
	
	
	@Override
	protected void entityInit() {
		super.entityInit();
	}
	
	
	@Override
	public void onUpdate() {
		super.onUpdate();
		if(entityAwake) {
			//Utils.getLogger().info("AWAKENED");
		}
	}
	
	@Override
	protected void initEntityAI() {
		if(entityAwake) {
			applyAttackAI();
		}
	}
	
	public boolean getentityAwake() {
		return entityAwake;
	}
	
	public void setEntityAwake(boolean truth) {
		this.entityAwake = truth;
	}
	
	
	protected void applyAttackAI() {
		this.tasks.addTask(0, new EntityAIDeath(this, deathTime));
		this.targetTasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 32));
		this.targetTasks.addTask(0, new EntityAIFindEntityNearestPlayer(this));
		
	}
	
	@Override
	protected void onDeathUpdate() {

        ++this.deathTime;
        
        if (this.deathTime != 0) {
        }
        
        if (this.deathTime == 200)
        {
            if (!this.world.isRemote && (this.isPlayer() || this.recentlyHit > 0 && this.canDropLoot() && this.world.getGameRules().getBoolean("doMobLoot")))
            {
                int i = this.getExperiencePoints(this.attackingPlayer);
                i = net.minecraftforge.event.ForgeEventFactory.getExperienceDrop(this, this.attackingPlayer, i);
                while (i > 0)
                {
                    int j = EntityXPOrb.getXPSplit(i);
                    i -= j;
                    this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY, this.posZ, j));
                }
            }
            
            this.setDead();

            for (int k = 0; k < 20; ++k)
            {
                double d2 = this.rand.nextGaussian() * 0.02D;
                double d0 = this.rand.nextGaussian() * 0.02D;
                double d1 = this.rand.nextGaussian() * 0.02D;
                this.world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, d2, d0, d1, new int[0]);
            }
        }		
	}
	
	
	public int getdeathTime() {
		return this.deathTime;
	}
	
	
	
	@Override
	public void onLivingUpdate() {
		super.onLivingUpdate();
		if(entityAwake) {
			bookmodel.setAwake(entityAwake);
			Utils.getLogger().info("Living Update works");
		}
	}
	
	static class BeelzebookMoveHelper extends EntityMoveHelper {
		private final EntityBeelzebook parentEntity;
		private int courseCooldown;
		
		public BeelzebookMoveHelper(EntityBeelzebook book) {
			super(book);
			this.parentEntity = book;
		}
		
		public void onUpdateMoveHelper() {
			if (this.action == EntityMoveHelper.Action.MOVE_TO) {
				double dx = this.posX - this.parentEntity.posX;
				double dy = this.posY - this.parentEntity.posY;
				double dz = this.posZ - this.parentEntity.posZ;
				double df = dx * dx + dy * dy + dz * dz;
				
				if(this.courseCooldown-- <=0) {
					this.courseCooldown += this.parentEntity.getRNG().nextInt(5) + 2;
					df = (double)MathHelper.sqrt(df);
					
					if(this.isNotColliding(this.posX, this.posY, this.posZ, df)) {
						this.parentEntity.motionX += dx/df * .1D;
						this.parentEntity.motionY += dy/df * .1D;
						this.parentEntity.motionZ += dz/df * .1D;
					}
					else {
						this.action = EntityMoveHelper.Action.WAIT;
					}
				}
			}
		}
		
		private boolean isNotColliding(double x, double y, double z, double dividend) {
			double d0 = (x - this.parentEntity.posX) / dividend;
			double d1 = (y - this.parentEntity.posY) / dividend;
			double d2 = (z - this.parentEntity.posZ) / dividend;
			AxisAlignedBB ax = this.parentEntity.getEntityBoundingBox();
		
			for (int i =1; (double)i < dividend; ++i) {
				ax = ax.offset(d0, d1, d2);
				
				if(!this.parentEntity.world.getCollisionBoxes(this.parentEntity, ax).isEmpty()) {
					return false;
				}
			}
			
			return true;
		}
	}
}

class EntityAIDeath extends EntityAIBase{

	protected int death;
	protected EntityBeelzebook book;
	
	public EntityAIDeath(EntityBeelzebook entity, int deathT) {
		this.death = deathT;
		this.book = entity;
		setMutexBits(8);
	}
	
	@Override
	public boolean shouldExecute() {
		if (death != 0) {
			return true;
		}
		else {
			return false;
		}
	}
	
	@Override
	public boolean continueExecuting() {
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public void startExecuting() {
		this.book.getMoveHelper().setMoveTo(book.posX, book.posY + 10, book.posZ, 1D);
	}
	
}

 

 

Event class:

Spoiler

package com.ninja3659.explorationexpansion.events;

import com.ninja3659.explorationexpansion.client.entities.EntityBeelzebook;

import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class BeelzebookAwakeEvent {
			
		EntityBeelzebook book;
	
		@SubscribeEvent
		public void onEvent(LivingHurtEvent event) {
			if(event.getEntityLiving() instanceof EntityBeelzebook) {
				book = (EntityBeelzebook) event.getEntityLiving();
				book.setEntityAwake(true);
				
			}
		}
}

 

EDIT: So i got the boolean in the model class to set to true, the if statement in setLivingAnimation just isn't working

EDIT2: Yeah, the boolean is set to true and the AwakeAnimation IS being called, but for some reason, it isn't picking up the boolean as true

Edited by GooberGunter
Link to comment
Share on other sites

Update: So it looks like the boolean is set to true when the setter is called but doesn't remain true

Unfortunately, this is as far as I can figure out. I can't think of a solution for this and I haven't really worked with triggered animations before

Edited by GooberGunter
Link to comment
Share on other sites

You're setting awake on the server.

You're expecting the client to render something.

 

You need to tell the client that the data has changed.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

The magic of packets

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Alright I've Been looking around for a while and I can't find any good tutorials on packets. I mean I understand the whole making a class for the message that has methods to send info to and from bits, but I don't know how it all fits together. Why do I need a message handler? How do I set information to the packet? How do I get the information? The forge documentation didn't give me much insight

 

Edited by GooberGunter
Link to comment
Share on other sites

Link to comment
Share on other sites

So I followed cjminecraft's tutorial, only understanding what I'm doing here and there, and I got myself a promising error:

Spoiler

[23:16:36] [Client thread/ERROR]: Couldn't render entity
java.lang.NullPointerException
    at com.ninja3659.explorationexpansion.client.model.ModelBeelzebook.AwakeAnimation(ModelBeelzebook.java:193) ~[ModelBeelzebook.class:?]
    at com.ninja3659.explorationexpansion.client.model.ModelBeelzebook.setRotationAngles(ModelBeelzebook.java:172) ~[ModelBeelzebook.class:?]
    at com.ninja3659.explorationexpansion.client.model.ModelBeelzebook.renderBook(ModelBeelzebook.java:155) ~[ModelBeelzebook.class:?]
    at com.ninja3659.explorationexpansion.client.model.ModelBeelzebook.render(ModelBeelzebook.java:149) ~[ModelBeelzebook.class:?]
    at net.minecraft.client.renderer.entity.RenderLivingBase.renderModel(RenderLivingBase.java:259) ~[RenderLivingBase.class:?]
    at net.minecraft.client.renderer.entity.RenderLivingBase.doRender(RenderLivingBase.java:181) [RenderLivingBase.class:?]
    at net.minecraft.client.renderer.entity.RenderLiving.doRender(RenderLiving.java:51) [RenderLiving.class:?]
    at net.minecraft.client.renderer.entity.RenderLiving.doRender(RenderLiving.java:16) [RenderLiving.class:?]
    at net.minecraft.client.renderer.entity.RenderManager.doRenderEntity(RenderManager.java:389) [RenderManager.class:?]
    at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:373) [RenderManager.class:?]
    at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:653) [RenderGlobal.class:?]
    at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1389) [EntityRenderer.class:?]
    at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1303) [EntityRenderer.class:?]
    at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1106) [EntityRenderer.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1140) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:407) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
    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_131]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:26) [start/:?]

Model Code: Most of the important stuff is the AwakeAnimation

Spoiler

package com.ninja3659.explorationexpansion.client.model;

import java.awt.print.Book;

import com.ninja3659.explorationexpansion.client.entities.EntityBeelzebook;
import com.ninja3659.explorationexpansion.networking.NeemPacketHandler;
import com.ninja3659.explorationexpansion.networking.PacketGetAwaken;
import com.ninja3659.explorationexpansion.util.Utils;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.server.network.NetHandlerStatusServer;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLModIdMappingEvent.ModRemapping;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import scala.specialized;

public class ModelBeelzebook extends ModelBase{
	//EntityFlying

	public ModelRenderer book;
	public ModelRenderer BookTop;
	public ModelRenderer BookBottom;
	public ModelRenderer Eye1;
	public ModelRenderer Eye2;
	public ModelRenderer Eye3;
	public ModelRenderer Eye4;
	public ModelRenderer Spine;
	public ModelRenderer pagesT;
	public ModelRenderer pagesB;
	public ModelRenderer page1;
	public ModelRenderer page2;
	public ModelRenderer page3;
	public boolean awake = false;
	
	public static int sync = 0;
	
	public ModelBeelzebook() {
		textureWidth = 128;
		textureHeight = 128;
		
	
		book = new ModelRenderer(this, 0, 0);
		book.addBox(0, 0, 0, 0, 0, 0);
		book.setRotationPoint(0, 22, 0);
		
		BookTop = new ModelRenderer(this, 0, 0);
		BookTop.addBox(-10, -1.5f, -14, 20, 1, 14);
		BookTop.setRotationPoint(0, 0, 0);
		setRotation(BookTop, 0, 0, 0);
		book.addChild(BookTop);
		
		Eye1 = new ModelRenderer(this, 0, 32);
		Eye1.addBox(-1, -2, -2, 2, 2, 2);
		Eye1.setRotationPoint(-5, -1, -6);
		setRotation(Eye1, 81, 0, 0);
		BookTop.addChild(Eye1);
		
		Eye2 = new ModelRenderer(this, 0, 36);
		Eye2.addBox(-1, -2, -2, 2, 2, 2);
		Eye2.setRotationPoint(-2, -1, -8);
		setRotation(Eye2, 81, 0, 0);
		BookTop.addChild(Eye2);
		
		Eye3 = new ModelRenderer(this, 0, 40);
		Eye3.addBox(-1, -2, -2, 2, 2, 2);
		Eye3.setRotationPoint(4, 0, 0);
		Eye2.addChild(Eye3);
		
		Eye4 = new ModelRenderer(this, 0, 44);
		Eye4.addBox(-1, -2, -2, 2, 2, 2);
		Eye4.setRotationPoint(10, 0, 0);
		Eye1.addChild(Eye4);
		
		pagesT = new ModelRenderer(this, 0, 48);
		pagesT.addBox(-9, -.5f, -13, 18, 1, 13);
		pagesT.setRotationPoint(0, 0, 0);
		setRotation(pagesT, 0, 0, 0);
		BookTop.addChild(pagesT);
		
		BookBottom = new ModelRenderer(this, 0, 16);
		BookBottom.addBox(-10, .5f, -14, 20, 1, 14);
		BookBottom.setRotationPoint(0, 0, 0);
		book.addChild(BookBottom);
		
		pagesB = new ModelRenderer(this, 0, 48);
		pagesB.addBox(-9, -.5f, -13, 18, 1, 13);
		pagesB.setRotationPoint(0, 0, 0);
		BookBottom.addChild(pagesB);
		
		Spine = new ModelRenderer(this, 68, 13);
		Spine.addBox(-10, -1.5f, 0, 20, 3, 1);
		Spine.setRotationPoint(0, 0, 0);
		book.addChild(Spine);
		
		page1 = new ModelRenderer(this, 9, 32);
		page1.addBox(-1.5f, -19, 0, 3, 4, 0);
		page1.setRotationPoint(0, 0, 0);
		book.addChild(page1);
		
		page2 = new ModelRenderer(this, 9, 32);
		page2.addBox(-1.5f, -24, 0, 3, 4, 0);
		page2.setRotationPoint(0, 0, 0);
		book.addChild(page2);
		
		page3 = new ModelRenderer(this, 9, 32);
		page3.addBox(-1.5f, -29, 0, 3, 4, 0);
		page3.setRotationPoint(0, 0, 0);
		book.addChild(page3);
		
	}
	
	public void setAwake(boolean entityAwake) {
		awake = entityAwake;
		Utils.getLogger().info("Awake is now: " + awake);
	}//used to set the awake animation to true
	
	public boolean getAwake() {
		Utils.getLogger().info("FETCHED AWAKE IS: " + awake);
		return awake;
	
	}
	
	public float deg2Rad(float d) {
		return d * ((float)Math.PI / 180);
	}
	
	public void setRotation(ModelRenderer model, float x, float y, float z) {
		model.rotateAngleX = deg2Rad(x);
		model.rotateAngleY = deg2Rad(y);
		model.rotateAngleZ  = deg2Rad(z);
	}
	

	@Override
	public void render(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
		renderBook((EntityBeelzebook) entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
		
	}
	
	public void renderBook(EntityBeelzebook entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
		book.render(scale);
		setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entity);
	}
	
	@Override
	public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw,
			float headPitch, float scaleFactor, Entity entityIn) {
		super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);
		BookTop.rotateAngleX = 0;
		BookBottom.rotateAngleX = MathHelper.cos(limbSwing * .666f) * .4F * limbSwingAmount + deg2Rad(20);
		
		
		
//		if(entityIn.ticksExisted%60 == 0) {
//			book.rotateAngleX = headPitch * .666f;
//			book.rotateAngleY = netHeadYaw * .666f;
//		}
		
		AwakeAnimation((EntityBeelzebook) entityIn);
		deathAnim((EntityBeelzebook)entityIn, limbSwing, limbSwingAmount, ageInTicks);
	}
	
	public void deathAnim(EntityBeelzebook entity, float limbSwing, float limbSwingAmount, float ageInTicks) {
		if (entity.getdeathTime() != 0) {
			BookTop.rotateAngleX = deg2Rad(-(5 * MathHelper.cos(entity.ticksExisted * 2)) - 85);
			BookBottom.rotateAngleX = deg2Rad((5 * MathHelper.cos(entity.ticksExisted * 2)) +85);
		}		
	}	
	
	@Override
	public void setLivingAnimations(EntityLivingBase entitylivingbaseIn, float limbSwing, float limbSwingAmount,
			float partialTickTime) {
		
	}
	
	public void AwakeAnimation(EntityBeelzebook entity) {
		sync++;
		sync %= 10;
		if(sync == 0) {
			NeemPacketHandler.INSTANCE.sendToServer(new PacketGetAwaken(entity.getentityAwake(), "com.ninja3659.explorationexpansion.client.model.ModelBeelzebook", "awake", entity.getEntityId()));
		}
		
		if(this.getAwake()) {
			this.setRotation(Eye1, 33, 0, 0);
			this.setRotation(Eye2, 33, 0, 0);
			Utils.getLogger().info("animation!");
		}
	}//opens the book's eyes

}

 

Here's just the AwakeAnimation method:

Spoiler

public void AwakeAnimation(EntityBeelzebook entity) {
		sync++;
		sync %= 10;
		if(sync == 0) {
			NeemPacketHandler.INSTANCE.sendToServer(new PacketGetAwaken(entity.getentityAwake(), "com.ninja3659.explorationexpansion.client.model.ModelBeelzebook", "awake", entity.getEntityId()));
		}
		
		if(this.getAwake()) {
			this.setRotation(Eye1, 33, 0, 0);
			this.setRotation(Eye2, 33, 0, 0);
			Utils.getLogger().info("animation!");
		}

 

Packet Handler:

Spoiler

package com.ninja3659.explorationexpansion.networking;

import com.ninja3659.explorationexpansion.Reference;
import com.ninja3659.explorationexpansion.client.entities.EntityBeelzebook;

import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;

//Sweet baby Jesus help me

public class NeemPacketHandler {

	public static SimpleNetworkWrapper INSTANCE; 
	private static int id=0;
	public NeemPacketHandler() {
		
	}//TargetPoint
	
	public static int nextID() {
		return id++;
	}
	
	public static void registerMessages(String channelName) {
		INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(channelName);
		
		//server packets
		INSTANCE.registerMessage(PacketGetAwaken.Handler.class, PacketGetAwaken.class, nextID(), Side.SERVER);
	
		//client Packets
		INSTANCE.registerMessage(PacketReturnAwaken.Handler.class, PacketReturnAwaken.class, nextID(), Side.CLIENT);
	}
	
	

}

 

PacketGetAwaken:

Spoiler

package com.ninja3659.explorationexpansion.networking;

import com.google.common.base.Predicate;
import com.jcraft.jogg.Packet;
import com.ninja3659.explorationexpansion.client.entities.EntityBeelzebook;
import com.ninja3659.explorationexpansion.util.Utils;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;

public class PacketGetAwaken implements IMessage{
	
	private boolean messageValid;
	private boolean awaken;
	private int entityid;

	private String className;
	private String awakenFieldName;
	
	public PacketGetAwaken() {
		// TODO Auto-generated constructor stub
		this.messageValid = false;//sets the message validity to false
	}
	
	public PacketGetAwaken(boolean awaken, String className, String awakenFieldName, int entityid) {
		this.awaken = awaken;
		this.className = className;
		this.awakenFieldName = awakenFieldName;
		this.messageValid = true;
		this.entityid = entityid;
		
	}
	
	@Override
	public void fromBytes(ByteBuf buf) {
		try {
			this.awaken = buf.readBoolean();//reads it
			this.className = ByteBufUtils.readUTF8String(buf);
			this.awakenFieldName = ByteBufUtils.readUTF8String(buf);
			this.entityid = buf.readInt();
		}catch(IndexOutOfBoundsException ioe) {
			Utils.getLogger().catching(ioe);
			return;
		}
	}

	@Override
	public void toBytes(ByteBuf buf) {
		if(!this.messageValid) {
			return;//bounces back if message isn't valid
		}
		
		buf.writeBoolean(awaken);//writes the boolean
		buf.writeInt(entityid);
		ByteBufUtils.writeUTF8String(buf, this.className);
		ByteBufUtils.writeUTF8String(buf, this.awakenFieldName);
	}
	
	public static class Handler implements IMessageHandler<PacketGetAwaken, IMessage>{

		@Override
		public IMessage onMessage(PacketGetAwaken message, MessageContext ctx) {
			if(!message.messageValid && ctx.side != Side.SERVER)
				return null;
			FMLCommonHandler.instance().getWorldThread(ctx.netHandler).addScheduledTask(() -> processMessage(message, ctx));
			return null;
		}
		
		void processMessage(PacketGetAwaken message, MessageContext ctx) {
			EntityBeelzebook eb = (EntityBeelzebook) ctx.getServerHandler().playerEntity.getServerWorld().getEntityByID(message.entityid);	
			NeemPacketHandler.INSTANCE.sendToAllAround(new PacketReturnAwaken(eb.entityAwake, message.className, message.awakenFieldName), new TargetPoint(0, eb.getPosX(), eb.getPosY(), eb.getPosZ(), 100));
		}
	
	}
}

 

PacketReturnAwaken:

Spoiler

package com.ninja3659.explorationexpansion.networking;


import java.lang.reflect.Field;

import org.lwjgl.BufferUtils;

import com.ninja3659.explorationexpansion.util.Utils;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;

public class PacketReturnAwaken implements IMessage{

	private boolean messageValid;
	
	private boolean awake;
	
	private String className;
	private String awakenFieldName;
	
	public PacketReturnAwaken() {
		this.messageValid = false;
	}
	
	public PacketReturnAwaken(boolean awake, String className, String awakenFieldName) {
		this.awake = awake;
		this.className = className;
		this.awakenFieldName = awakenFieldName;
		this.messageValid = true;

	}
	
	
	@Override
	public void fromBytes(ByteBuf buf) {
		try {
			this.awake = buf.readBoolean();
			this.className = ByteBufUtils.readUTF8String(buf);
			this.awakenFieldName = ByteBufUtils.readUTF8String(buf);
		}catch (IndexOutOfBoundsException ioe) {
			Utils.getLogger().catching(ioe);
			return;
		}
		this.messageValid = true;
	}

	@Override
	public void toBytes(ByteBuf buf) {
		if(!this.messageValid)
			return;
		buf.writeBoolean(awake);
		ByteBufUtils.writeUTF8String(buf, className);
		ByteBufUtils.writeUTF8String(buf, awakenFieldName);
	}
	
	public static class Handler implements IMessageHandler<PacketReturnAwaken, IMessage>{

		@Override
		public IMessage onMessage(PacketReturnAwaken message, MessageContext ctx) {
			if(!message.messageValid && ctx.side != Side.CLIENT) {
				return null;
			}
			
			Minecraft.getMinecraft().addScheduledTask(() -> proccessMessage(message));
			
			return null;
		}

		void proccessMessage(PacketReturnAwaken message) {
			try {
				Class clazz = Class.forName(message.className);
				Field awakeField = clazz.getDeclaredField(message.awakenFieldName);
				awakeField.setBoolean(clazz, message.awake);
			}catch(Exception e) {
				Utils.getLogger().catching(e);
			}
		}
	}
}

 

 

Now you'll probably see a lot of weird things, but, like I said, I kinda just tumbled through this.

Usually, I'm able to figure it out, but Networking is something I have never worked with

Edited by GooberGunter
Link to comment
Share on other sites

java.lang.NullPointerException
    at com.ninja3659.explorationexpansion.client.model.ModelBeelzebook.AwakeAnimation(ModelBeelzebook.java:193) ~[ModelBeelzebook.class:?]

Something is null where it shouldn't be. I'm guessing line 193 is probably this one, right?

NeemPacketHandler.INSTANCE.sendToServer(new PacketGetAwaken(entity.getentityAwake(), "com.ninja3659.explorationexpansion.client.model.ModelBeelzebook", "awake", entity.getEntityId()));

 

Where do you call the registerMessages method of your PacketHandler?

Link to comment
Share on other sites

Yeah...I had no idea what was going on in the tutorial. The class name and field name were supposed to be "java reflection" but I never saw the point in it. But considering the fact that I've never done this before, I figured, what do I know.

I updated the code, it should be a little better but I still don't know when and where to call the sendTo part. 

 

NeemPacketHandler:

Spoiler

package com.ninja3659.explorationexpansion.networking;

import com.ninja3659.explorationexpansion.Reference;
import com.ninja3659.explorationexpansion.client.entities.EntityBeelzebook;

import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;

//Sweet baby Jesus help me

public class NeemPacketHandler {

	public static SimpleNetworkWrapper INSTANCE; 
	private static int id=0;
	public NeemPacketHandler() {
		
	}//TargetPoint
	
	public static int nextID() {
		return id++;
	}
	
	public static void registerMessages(String channelName) {
		INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(channelName);
		
		//server packets
	
		//client Packets
		INSTANCE.registerMessage(PacketReturnAwaken.Handler.class, PacketReturnAwaken.class, nextID(), Side.CLIENT);
	}
	
	

}

 

 

PacketReturnAwaken:

Spoiler

package com.ninja3659.explorationexpansion.networking;


import java.lang.reflect.Field;

import org.lwjgl.BufferUtils;

import com.ninja3659.explorationexpansion.util.Utils;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;

public class PacketReturnAwaken implements IMessage{

	private boolean messageValid;
	
	private boolean awake;
	
	public PacketReturnAwaken() {
		this.messageValid = false;
	}
	
	public PacketReturnAwaken(boolean awake) {
		this.awake = awake;
		this.messageValid = true;

	}
	
	
	@Override
	public void fromBytes(ByteBuf buf) {
		try {
			this.awake = buf.readBoolean();
		}catch (IndexOutOfBoundsException ioe) {
			Utils.getLogger().catching(ioe);
			return;
		}
		this.messageValid = true;
	}

	@Override
	public void toBytes(ByteBuf buf) {
		if(!this.messageValid)
			return;
		buf.writeBoolean(awake);
	}
	
	public static class Handler implements IMessageHandler<PacketReturnAwaken, IMessage>{

		@Override
		public IMessage onMessage(PacketReturnAwaken message, MessageContext ctx) {
			if(!message.messageValid && ctx.side != Side.CLIENT) {
				return null;
			}
			
			Minecraft.getMinecraft().addScheduledTask(() -> proccessMessage(message));
			
			return null;
		}

		void proccessMessage(PacketReturnAwaken message) {
			try {
				
			}catch(Exception e) {
				Utils.getLogger().catching(e);
			}
		}
	}
}

 

Also, I register the messages through the common proxy (which may or may not be a bad idea; which I don't doubt) in a method called preInit() which is called in the preInit message in the main core mod class. But naturally, when I ran that code, I forgot to call the proxy method. 

Edited by GooberGunter
Link to comment
Share on other sites

Your packet doesn't do anything when it arrives. 

		void proccessMessage(PacketReturnAwaken message) {
			try {
				
			}catch(Exception e) {
				Utils.getLogger().catching(e);
			}
		}

So blank, much void, many noop. Wow.

 

Additionally, your packet doesn't have any way of finding the entity it needs to awaken. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So I figured it could find the entity via entityid through this line, 

EntityBeelzebook eb = (EntityBeelzebook) ctx.getServerHandler().playerEntity.getServerWorld().getEntityByID(id);

so I created another variable int entityid and wrote the code to and from bytes, I just don't know where I should go from here

Spoiler

public class PacketReturnAwaken implements IMessage{

	private boolean messageValid;
	
	private boolean awake;
	private int entityid;
	
	public PacketReturnAwaken() {
		this.messageValid = false;
	}
	
	public PacketReturnAwaken(boolean awake, int id) {
		this.awake = awake;
		this.entityid = id;
		this.messageValid = true;

	}
	
	
	@Override
	public void fromBytes(ByteBuf buf) {
		try {
			this.awake = buf.readBoolean();
			this.entityid = buf.readInt();
		}catch (IndexOutOfBoundsException ioe) {
			Utils.getLogger().catching(ioe);
			return;
		}
		this.messageValid = true;
	}

	@Override
	public void toBytes(ByteBuf buf) {
		if(!this.messageValid)
			return;
		buf.writeBoolean(awake);
		buf.writeInt(entityid);
	}
	
	public static class Handler implements IMessageHandler<PacketReturnAwaken, IMessage>{

		@Override
		public IMessage onMessage(PacketReturnAwaken message, MessageContext ctx) {
			if(!message.messageValid && ctx.side != Side.CLIENT) {
				return null;
			}
			
			Minecraft.getMinecraft().addScheduledTask(() -> proccessMessage(message, ctx, message.entityid));
			
			return null;
		}

		void proccessMessage(PacketReturnAwaken message, MessageContext ctx, int id) {
			try {
				EntityBeelzebook eb = (EntityBeelzebook) ctx.getServerHandler().playerEntity.getServerWorld().getEntityByID(id);
				NeemPacketHandler.INSTANCE.sendToAll(new PacketReturnAwaken(eb.getentityAwake(), eb.getEntityId()));

			}catch(Exception e) {
				Utils.getLogger().catching(e);
			}
		}
	}
}

 

What code belongs in the handler and how do I connect the variables in the constructor of the message to the variables in my entity class?

EDIT: Ok so I think I'm good storing the boolean from the entity to the packet. I just don't know how to update the other boolean in my model class to the packet one

 

Also I know that send to all is a very bad idea for this, but I can't get the entity tracker working right now and since I'm the only one testing, I'll just put it in for now and fix it later when the actual packet works

Edited by GooberGunter
Link to comment
Share on other sites

Wait, would I set the boolean in the model class to the packet boolean in the message handler?

EDIT: I looked back at the forge documentation and I got an idea, I'm about to test this

PacketReturnAwake:

Spoiler

package com.ninja3659.explorationexpansion.networking;


import java.lang.reflect.Field;

import org.lwjgl.BufferUtils;

import com.ninja3659.explorationexpansion.client.entities.EntityBeelzebook;
import com.ninja3659.explorationexpansion.util.Utils;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityTracker;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;

public class PacketReturnAwaken implements IMessage{

	private boolean messageValid;
	
	private boolean awake;
	private int entityid;
	
	public PacketReturnAwaken() {
		this.messageValid = false;
	}
	
	public PacketReturnAwaken(boolean awake, int id) {
		this.awake = awake;
		this.entityid = id;
		this.messageValid = true;

	}
	
	
	@Override
	public void fromBytes(ByteBuf buf) {
		try {
			this.awake = buf.readBoolean();
			this.entityid = buf.readInt();
		}catch (IndexOutOfBoundsException ioe) {
			Utils.getLogger().catching(ioe);
			return;
		}
		this.messageValid = true;
	}

	@Override
	public void toBytes(ByteBuf buf) {
		if(!this.messageValid)
			return;
		buf.writeBoolean(awake);
		buf.writeInt(entityid);
	}
	
	public static class Handler implements IMessageHandler<PacketReturnAwaken, IMessage>{

		@Override
		public IMessage onMessage(PacketReturnAwaken message, MessageContext ctx) {
		//	if(!message.messageValid && ctx.side != Side.CLIENT) {
		//		return null;
		//	}
			
			Minecraft.getMinecraft().addScheduledTask(() -> proccessMessage(message, ctx, message.entityid));
			
			return null;
		}

		void proccessMessage(PacketReturnAwaken message, MessageContext ctx, int id) {
			try {
				EntityBeelzebook eb = (EntityBeelzebook) ctx.getServerHandler().playerEntity.getServerWorld().getEntityByID(id);
				eb.getModel().awake = message.awake;
			}catch(Exception e) {
				Utils.getLogger().catching(e);
			}
		}
	}
}

 

And the Method in EntityBeelzebook:

Spoiler

@Override
	public void onLivingUpdate() {
		super.onLivingUpdate();
		if(entityAwake && !bookmodel.awake) {
			bookmodel.setAwake(entityAwake);
			//Utils.getLogger().info("Living Update works");
		}
		if(entityAwake) {
			applyAttackAI();
		}
		sync++;
		sync %= 10;
		if(sync == 0) {
			NeemPacketHandler.INSTANCE.sendToAll(new PacketReturnAwaken(this.getentityAwake(), this.getEntityId()));
		}
	}

 

it gave me an error about casting NetHandlerPlayClient to NetHanlderPlayServer at the declaration of eb

 

 

Edited by GooberGunter
Link to comment
Share on other sites

Random question: why do uou pass both message (which you use to pull message.awake) and message.id?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I pass the message. id to put in the entityid for the initialization of the eb variable so that I could use the getModel() method in my EntityBeelzebook class and have access from there. Without the id i can't initialize it. Why? is there a better way?

 

Initialization is my weakness

Edited by GooberGunter
Link to comment
Share on other sites

If you're passing the message itself as a parameter, then you can access the message's entityid field locally in the method - by passing it separately you're basically passing the same information to the method twice.

1 hour ago, GooberGunter said:

it gave me an error about casting NetHandlerPlayClient to NetHanlderPlayServer at the declaration of eb

Post the error.

Edited by Jay Avery
Link to comment
Share on other sites

Here's the error

Spoiler

[09:35:35] [Client thread/ERROR] [neem]: catching
java.lang.ClassCastException: net.minecraft.client.network.NetHandlerPlayClient cannot be cast to net.minecraft.network.NetHandlerPlayServer
    at net.minecraftforge.fml.common.network.simpleimpl.MessageContext.getServerHandler(MessageContext.java:55) ~[MessageContext.class:?]
    at com.ninja3659.explorationexpansion.networking.PacketReturnAwaken$Handler.proccessMessage(PacketReturnAwaken.java:76) ~[PacketReturnAwaken$Handler.class:?]
    at com.ninja3659.explorationexpansion.networking.PacketReturnAwaken$Handler.lambda$0(PacketReturnAwaken.java:69) ~[PacketReturnAwaken$Handler.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_131]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_131]
    at net.minecraft.util.Util.runTask(Util.java:29) [Util.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1109) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:407) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
    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_131]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:26) [start/:?]

 

And I got rid of int id in processMessage and replaced it with message.entityid

Edited by GooberGunter
Link to comment
Share on other sites

So I have it all set up, but the boolean awake in the model class is Not being set to true for some reason

PacketReturnAwaken:

Spoiler

package com.ninja3659.explorationexpansion.networking;


import java.lang.reflect.Field;

import org.lwjgl.BufferUtils;

import com.google.common.primitives.Bytes;
import com.ninja3659.explorationexpansion.client.entities.EntityBeelzebook;
import com.ninja3659.explorationexpansion.client.model.ModelBeelzebook;
import com.ninja3659.explorationexpansion.util.Utils;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityTracker;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;

public class PacketReturnAwaken implements IMessage{

	private boolean messageValid;
	
	private boolean awake;
	private int entityid;
	
	
	public PacketReturnAwaken() {
		this.messageValid = false;
	}
	
	public PacketReturnAwaken(boolean awake, int id) {
		this.awake = awake;
		this.entityid = id;
		this.messageValid = true;

	}
	
	
	@Override
	public void fromBytes(ByteBuf buf) {
		try {
			this.awake = buf.readBoolean();
			this.entityid = buf.readInt();
		}catch (IndexOutOfBoundsException ioe) {
			Utils.getLogger().catching(ioe);
			return;
		}
		this.messageValid = true;
	}

	@Override
	public void toBytes(ByteBuf buf) {
		if(!this.messageValid)
			return;
		buf.writeBoolean(awake);
		buf.writeInt(entityid);
		
	}
	
	public static class Handler implements IMessageHandler<PacketReturnAwaken, IMessage>{

		@Override
		public IMessage onMessage(PacketReturnAwaken message, MessageContext ctx) {
		//	if(!message.messageValid && ctx.side != Side.CLIENT) {
		//		return null;
		//	}
			
			Minecraft.getMinecraft().addScheduledTask(() -> proccessMessage(message, ctx));
			
			return null;
		}

		void proccessMessage(PacketReturnAwaken message, MessageContext ctx) {
			try {
				EntityBeelzebook eb = (EntityBeelzebook) Minecraft.getMinecraft().world.getEntityByID(message.entityid);
				eb.getModel().awake = message.awake;
				Utils.getLogger().info("packet set: " + eb.getModel().awake);
			}catch(Exception e) {
				Utils.getLogger().catching(e);
			}
		}
	}
}

 

Model:

Spoiler

package com.ninja3659.explorationexpansion.client.model;

import java.awt.print.Book;

import com.ninja3659.explorationexpansion.client.entities.EntityBeelzebook;
import com.ninja3659.explorationexpansion.networking.NeemPacketHandler;
import com.ninja3659.explorationexpansion.networking.PacketReturnAwaken;
import com.ninja3659.explorationexpansion.util.Utils;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.server.network.NetHandlerStatusServer;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLModIdMappingEvent.ModRemapping;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import scala.specialized;

public class ModelBeelzebook extends ModelBase{
	//EntityFlying

	public ModelRenderer book;
	public ModelRenderer BookTop;
	public ModelRenderer BookBottom;
	public ModelRenderer Eye1;
	public ModelRenderer Eye2;
	public ModelRenderer Eye3;
	public ModelRenderer Eye4;
	public ModelRenderer Spine;
	public ModelRenderer pagesT;
	public ModelRenderer pagesB;
	public ModelRenderer page1;
	public ModelRenderer page2;
	public ModelRenderer page3;
	public boolean awake = false;
	
	public static int sync = 0;
	
	public ModelBeelzebook() {
		textureWidth = 128;
		textureHeight = 128;
		
	
		book = new ModelRenderer(this, 0, 0);
		book.addBox(0, 0, 0, 0, 0, 0);
		book.setRotationPoint(0, 22, 0);
		
		BookTop = new ModelRenderer(this, 0, 0);
		BookTop.addBox(-10, -1.5f, -14, 20, 1, 14);
		BookTop.setRotationPoint(0, 0, 0);
		setRotation(BookTop, 0, 0, 0);
		book.addChild(BookTop);
		
		Eye1 = new ModelRenderer(this, 0, 32);
		Eye1.addBox(-1, -2, -2, 2, 2, 2);
		Eye1.setRotationPoint(-5, -1, -6);
		setRotation(Eye1, 81, 0, 0);
		BookTop.addChild(Eye1);
		
		Eye2 = new ModelRenderer(this, 0, 36);
		Eye2.addBox(-1, -2, -2, 2, 2, 2);
		Eye2.setRotationPoint(-2, -1, -8);
		setRotation(Eye2, 81, 0, 0);
		BookTop.addChild(Eye2);
		
		Eye3 = new ModelRenderer(this, 0, 40);
		Eye3.addBox(-1, -2, -2, 2, 2, 2);
		Eye3.setRotationPoint(4, 0, 0);
		Eye2.addChild(Eye3);
		
		Eye4 = new ModelRenderer(this, 0, 44);
		Eye4.addBox(-1, -2, -2, 2, 2, 2);
		Eye4.setRotationPoint(10, 0, 0);
		Eye1.addChild(Eye4);
		
		pagesT = new ModelRenderer(this, 0, 48);
		pagesT.addBox(-9, -.5f, -13, 18, 1, 13);
		pagesT.setRotationPoint(0, 0, 0);
		setRotation(pagesT, 0, 0, 0);
		BookTop.addChild(pagesT);
		
		BookBottom = new ModelRenderer(this, 0, 16);
		BookBottom.addBox(-10, .5f, -14, 20, 1, 14);
		BookBottom.setRotationPoint(0, 0, 0);
		book.addChild(BookBottom);
		
		pagesB = new ModelRenderer(this, 0, 48);
		pagesB.addBox(-9, -.5f, -13, 18, 1, 13);
		pagesB.setRotationPoint(0, 0, 0);
		BookBottom.addChild(pagesB);
		
		Spine = new ModelRenderer(this, 68, 13);
		Spine.addBox(-10, -1.5f, 0, 20, 3, 1);
		Spine.setRotationPoint(0, 0, 0);
		book.addChild(Spine);
		
		page1 = new ModelRenderer(this, 9, 32);
		page1.addBox(-1.5f, -19, 0, 3, 4, 0);
		page1.setRotationPoint(0, 0, 0);
		book.addChild(page1);
		
		page2 = new ModelRenderer(this, 9, 32);
		page2.addBox(-1.5f, -24, 0, 3, 4, 0);
		page2.setRotationPoint(0, 0, 0);
		book.addChild(page2);
		
		page3 = new ModelRenderer(this, 9, 32);
		page3.addBox(-1.5f, -29, 0, 3, 4, 0);
		page3.setRotationPoint(0, 0, 0);
		book.addChild(page3);
		
	}
	
	public void setAwake(boolean entityAwake) {
		awake = entityAwake;
		Utils.getLogger().info("Awake is now: " + awake);
	}//used to set the awake animation to true
	
	public boolean getAwake() {
		Utils.getLogger().info("FETCHED AWAKE IS: " + awake);
		return awake;
	
	}
	
	public float deg2Rad(float d) {
		return d * ((float)Math.PI / 180);
	}
	
	public void setRotation(ModelRenderer model, float x, float y, float z) {
		model.rotateAngleX = deg2Rad(x);
		model.rotateAngleY = deg2Rad(y);
		model.rotateAngleZ  = deg2Rad(z);
	}
	

	@Override
	public void render(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
		renderBook((EntityBeelzebook) entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
		
	}
	
	public void renderBook(EntityBeelzebook entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
		book.render(scale);
		setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entity);
	}
	
	@Override
	public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw,
			float headPitch, float scaleFactor, Entity entityIn) {
		super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);
		BookTop.rotateAngleX = 0;
		BookBottom.rotateAngleX = MathHelper.cos(limbSwing * .666f) * .4F * limbSwingAmount + deg2Rad(20);
		
		
		
//		if(entityIn.ticksExisted%60 == 0) {
//			book.rotateAngleX = headPitch * .666f;
//			book.rotateAngleY = netHeadYaw * .666f;
//		}
		
		AwakeAnimation((EntityBeelzebook) entityIn);
		deathAnim((EntityBeelzebook)entityIn, limbSwing, limbSwingAmount, ageInTicks);
	}
	
	public void deathAnim(EntityBeelzebook entity, float limbSwing, float limbSwingAmount, float ageInTicks) {
		if (entity.getdeathTime() != 0) {
			BookTop.rotateAngleX = deg2Rad(-(5 * MathHelper.cos(entity.ticksExisted * 2)) - 85);
			BookBottom.rotateAngleX = deg2Rad((5 * MathHelper.cos(entity.ticksExisted * 2)) +85);
		}		
	}	
	
	@Override
	public void setLivingAnimations(EntityLivingBase entitylivingbaseIn, float limbSwing, float limbSwingAmount,
			float partialTickTime) {
		
	}
	
	public void AwakeAnimation(EntityBeelzebook entity) {
		Utils.getLogger().info("awake? " + awake);
		if(awake) {
			this.setRotation(Eye1, 33, 0, 0);
			this.setRotation(Eye2, 33, 0, 0);
			Utils.getLogger().info("animation!");
		}
	}//opens the book's eyes

}

 

Here is the method in the entity class:

Spoiler

@Override
	public void onLivingUpdate() {
		super.onLivingUpdate();
		if(entityAwake && !bookmodel.awake) {
			//Utils.getLogger().info("Living Update works");
		}
		if(entityAwake) {
			applyAttackAI();
		}
		sync++;
		sync %= 10;
		if(sync == 0 && entityAwake) {
			NeemPacketHandler.INSTANCE.sendToAll(new PacketReturnAwaken(this.entityAwake, this.getEntityId()));
			Utils.getLogger().info("synched!: " + entityAwake);
		}
	}

 

Everything Looks to be in good shape, i don't know what could be the problem

 

on the flip side, I feel like I'm getting a better understanding of packets

Edited by GooberGunter
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.



×
×
  • Create New...

Important Information

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