Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I have an entity extending EntityThrowable, I made a special renderer for it and I can't seem to let it work, the doRender method doesn't even get called.

I should mention that I didn't call super.onUpdate(), but I rather copied the code in it (and called onEntityUpdate which is called in the Entity class), because I wanted to change some things in the original update call.

 

Here's my EntityThrowable class:

 

public class EntityElementCharge extends EntityThrowable {

protected EntityPlayer thrower;
protected float speed;
protected double initialX, initialY, initialZ;

public EntityElementCharge(World world) {
	super(world);
}

public EntityElementCharge(World world, EntityPlayer player, float maxDistance, int tickAge) {
	super(world);
	this.thrower = player;

	float radian = (float)Math.PI / 180.0F; 

	MovingObjectPosition playermop = Utilities.getEntityMOP(world, player, maxDistance, true, true);
	double[] pitchYaw = Utilities.calculatePitchYawFromCoords(
			player.posX, player.posY + player.getEyeHeight(), player.posZ,
			playermop.blockX + 0.5, playermop.blockY + 0.5, playermop.blockZ + 0.5);
	double pitch = pitchYaw[0];
	double yaw = pitchYaw[1];

	setLocationAndAngles(player.posX, player.posY + player.getEyeHeight(), player.posZ, (float)yaw, (float)pitch);

	// copied from setPosition (since we're not using it).
        double bw = (double)this.width / 2.0;
        double bh = (double)this.height;
        this.boundingBox.setBounds(posX - bw, posY - (double)this.yOffset + (double)this.ySize, posZ - bw, posX + bw, posY - (double)this.yOffset + (double)this.ySize + bh, posZ + bw);

        this.initialX = this.posX;
        this.initialY = this.posY;
        this.initialZ = this.posZ;
        
	this.yOffset = 0;

	this.speed = 0.2;

	this.motionX = -Math.sin(this.rotationYaw * radian) * Math.cos(this.rotationPitch * radian) * this.speed;
	this.motionY = -Math.sin(this.rotationPitch * radian) * this.speed;
	this.motionZ = Math.cos(this.rotationYaw * radian) * Math.cos(this.rotationPitch * radian) * this.speed;
	this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, 1.5F, 1.0F);
}

@Override
protected void onImpact(MovingObjectPosition mop) { }

@Override
public void onUpdate() {
	this.lastTickPosX = this.posX;
        this.lastTickPosY = this.posY;
        this.lastTickPosZ = this.posZ;
        this.onEntityUpdate();
        //... a lot of lines copied from super.onUpdate() and modified ...
       	}

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

@Override
protected float getGravityVelocity() {
	return 0;
}
}

 

 

Here's the renderer class (nothing fancy, just testing):

 

public class RenderElementCharge extends Render {

@Override
public void doRender(Entity entity, double x, double y, double z, float f1, float f2) {
	System.out.println("test"); // should get spammed with test even for my entity existing in 5 tick only, but I don't
}

@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	return null;
}
}

 

 

Registering code:

 

Registering entity in base mod's preInit:

EntityRegistry.registerModEntity(EntityElementCharge.class, EntityNames.ENTITY_ELEMENT_CHARGE, eid++, Magematica.instance, 75, 3, true);

 

Registering renderer in ClientProxy's init:

RenderingRegistry.registerEntityRenderingHandler(EntityElementCharge.class, new RenderElementCharge());

 

  • Author

The Entity spawns correctly, and goes where it should go (I made it print where it is every update), could it be because it is server-side only?

 

Entity spawn code:

EntityElementCharge charge = new EntityElementCharge(player.worldObj, player, 5, 5); // server-sided only
player.worldObj.spawnEntityInWorld(charge);

 

Common Proxy (nothing is done here):

public class CommonProxy {

public void preInit() {

}

public void init() {

}
}

 

Client Proxy:

public class ClientProxy extends CommonProxy {

@Override
public void preInit() {
	RenderingRegistry.registerBlockHandler(new TestRenderer());
}

@Override
public void init() {
	FMLCommonHandler.instance().bus().register(new KeyInputHandler());
	RenderingRegistry.registerEntityRenderingHandler(EntityElementCharge.class, new RenderElementCharge());
	Initialization.registerKeyBindings();
}
}

 

Proxy's declaration and base mod's init-preinit:

@SidedProxy(clientSide="insnmods.client.ClientProxy", serverSide="insnmods.common.CommonProxy")
public static CommonProxy proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent event){
	//... registering blocks and items ...
EntityRegistry.registerModEntity(EntityElementCharge.class, EntityNames.ENTITY_ELEMENT_CHARGE, eid++, Magematica.instance, 75, 3, true);
	proxy.preInit();
}	

@EventHandler
public void init(FMLInitializationEvent event){
	//... registering crafting recipes ...
	proxy.init();
}

  • Author

Strangely enough, it gets called perfectly when spawned client-side. It means everything is registered correctly, just that the server is not notifying the clients.

Also I now noticed that onUpdate is called only once, since anything printed there is printed once even if it is called in both sides.

 

  • Author

:D :D LOL I feel stupid now, very stupid :D :D

turned out that I set onDead() without !worldObj.isRemote check

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.