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

So, I'm trying to use a custom entity to render lasers, i have entity variable syncing working using the datawatcher and my client seems receiving the necessary coordinates for its laser rendering, however my onUpdate never gets called for this entity, so none of my code ever gets hit. What am i doing wrong?

 

Entity is spawned from inside a TileEntity (My Laser)

if (!worldObj.isRemote){
laserBeam();
}

public void laserBeam(){

if(laserToList != null && laserToList.size() > 1){
	for(int j = 0; j < laserToList.size() - 1; j++){
		ForgeDirection or = laserToDirection.get(j);			

		System.out.println("spawningLaser");
		EntityBeam beam = new EntityBeam(worldObj, laserToList.get(0), laserToList.get(1));
		worldObj.spawnEntityInWorld(beam);
                	beam.updateDataServer();
                
                	laserToList.clear();
	}
}
}

 

The Entity

package opticraft.entitys;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.List;

import cpw.mods.fml.common.network.PacketDispatcher;
import opticraft.lib.ModInfo;
import opticraft.lib.Position;
import net.minecraft.entity.DataWatcher;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class EntityBeam extends Entity {

public List<Position> laserToList;
public World world;
public Position start, end;
private DataWatcher dw;

public EntityBeam(World par1World) {
	super(par1World);
	this.world = par1World;
}

public EntityBeam(World par1World, Position start, Position end) {
	super(par1World);
	this.start = start;
	this.end = end;

	this.dw = this.getDataWatcher();
	this.dw.addObject(8, 0);
	this.dw.addObject(9, 0);
	this.dw.addObject(10, 0);
	this.dw.addObject(11, 0);
	this.dw.addObject(12, 0);
	this.dw.addObject(13, 0);

	System.out.println("EntityBeamInitialised, start: " + start.toString() + " - " + end.toString());
}

@Override
public void onUpdate() {

	if (!worldObj.isRemote) {
		updateDataServer();
		System.out.println("UpdatedServer");
	}

	if (worldObj.isRemote) {
		updateDataClient();
		System.out.println("UpdatedClient");
	}

	if (this.ticksExisted > 5) {
		this.setDead();
	}

	boundingBox.minX = Math.min(start.x, end.x);
        	boundingBox.minY = Math.min(start.y, end.y);
    	    	boundingBox.minZ = Math.min(start.z, end.z);

   	  	boundingBox.maxX = Math.max(start.x, end.x);
    		boundingBox.maxY = Math.max(start.y, end.y);
        	boundingBox.maxZ = Math.max(start.z, end.z);

        	boundingBox.minX--;
        	boundingBox.minY--;
        	boundingBox.minZ--;

        	boundingBox.maxX++;
       	 	boundingBox.maxY++;
        	boundingBox.maxZ++;

        	super.onUpdate();
}

@Override
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
	// TODO Auto-generated method stub

}

@Override
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
	// TODO Auto-generated method stub

}

protected void updateDataClient() {
	start.x = decodeDouble(dw.getWatchableObjectInt();
	start.y = decodeDouble(dw.getWatchableObjectInt(9));
	start.z = decodeDouble(dw.getWatchableObjectInt(10));
	end.x = decodeDouble(dw.getWatchableObjectInt(11));
	end.y = decodeDouble(dw.getWatchableObjectInt(12));
	end.z = decodeDouble(dw.getWatchableObjectInt(13));
}

protected void updateDataServer() {
	if (!worldObj.isRemote) {
		System.out.println("lolwut");
	}
	dw.updateObject(8, Integer.valueOf(encodeDouble(start.x)));
	dw.updateObject(9, Integer.valueOf(encodeDouble(start.y)));
	dw.updateObject(10, Integer.valueOf(encodeDouble(start.z)));
	dw.updateObject(11, Integer.valueOf(encodeDouble(end.x)));
	dw.updateObject(12, Integer.valueOf(encodeDouble(end.y)));
	dw.updateObject(13, Integer.valueOf(encodeDouble(end.z)));
}

protected int encodeDouble(double d) {
	return (int) (d * 8192);
}

protected double decodeDouble(int i) {
	return (i / 8192D);
}

@Override
protected void entityInit() {
	// TODO Auto-generated method stub

}

}

 

Main Mod Class

EntityRegistry.registerModEntity(EntityBeam.class, "EntityBeam", 23, this, 128, 1, false);

 

If there's any more code you need to see you can find it on my GitHub https://github.com/lexwebb/opticraft

 

 

EntityRegistry.registerModEntity(EntityBeam.class, "EntityBeam", 23, this, 128, 1, false);

Using "EntityBeam.class" grabs a compiled class file not a java file, I think you need to just use "EntityBeam" (w/o the quotes).

or

EntityBeam.java (which I don't think is right)

  • Author

@diesieben07 When i tried using the inherited datawatcher i was getting NULL pointer exceptions thrown on the very first line i tried to use it. When debugging, i found that nothing was NULL, so i had no idea what was going on. I then decided to implement the datawatcher how i found in a tutorial which seemed to resolve the errors. I'll have a closer look at it.

 

Even still, the fact the the datawatcher may not work does not explain the fact that my entity does never update.

  • Author

Welp i found he source of the datawatcher null pointers i was having. You can ignore that bit :)

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.