Jump to content

TileEntity updateEntity() only running client side.


dmillerw

Recommended Posts

Pretty self explanatory. Have a class extending TileEntity, and I'm overriding updateEntity(). It's only being called on the client though, so nothing that happens sticks, and if I tell it to not run on the client, then nothing happens.

 

Yes, my TileEntity is registered, and yes, it's being created.

 

package com.dmillerw.liquidVis.tileentity;

import java.util.Random;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import thaumcraft.api.EnumTag;
import thaumcraft.api.ObjectTags;
import thaumcraft.api.ThaumcraftApi;

import com.dmillerw.liquidVis.core.helper.CoreHelper;
import com.dmillerw.liquidVis.item.ItemHandler;

public class TileEntityVisExtractor extends TileEntity implements ITankContainer {

public static LiquidTank tank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME * 10);

private int timeSinceLastPull = 0;

private Random rand;

public TileEntityVisExtractor() {
	rand = new Random();
	this.validate();
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	timeSinceLastPull = nbt.getInteger("timeSinceLastPull");
	int liquidID = nbt.getInteger("liquidID");
	int liquidMeta = nbt.getInteger("liquidMeta");
	int liquidAmount = nbt.getInteger("liquidAmount");
	LiquidStack toSet = new LiquidStack(liquidID, liquidMeta, liquidAmount);
	tank.setLiquid(toSet);
}

@Override
public void writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);
	nbt.setInteger("timeSinceLastPull", timeSinceLastPull);
	if (tank.getLiquid() != null) {
		int liquidID = tank.getLiquid().itemID;
		int liquidMeta = tank.getLiquid().itemMeta;
		int liquidAmount = tank.getLiquid().amount;

		nbt.setInteger("liquidID", liquidID);
		nbt.setInteger("liquidMeta", liquidMeta);
		nbt.setInteger("liquidAmount", liquidAmount);
	}
}

public Packet getDescriptionPacket() {
	NBTTagCompound data = new NBTTagCompound();
	writeToNBT(data);
        Packet132TileEntityData tePacket = new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 0, data);
	return tePacket;
    }

public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt) {
	if (pkt.xPosition == this.xCoord && pkt.yPosition == this.yCoord && pkt.zPosition == this.zCoord) {
		readFromNBT(pkt.customParam1);
	}
    }

public void updateEntity() {
	if (CoreHelper.isClient(this.worldObj)) {
		return;
	}

	if (timeSinceLastPull == 0) {
		if (tank.getLiquid() == null || tank.getLiquid().amount < tank.getCapacity()) {
			int toPull = rand.nextInt(10);
			int fluxToAdd = rand.nextInt(10);
			int toAdd = toPull * 10;
			LiquidStack liquidVis = LiquidDictionary.getOrCreateLiquid("liquidVis", ItemHandler.liquidVisLS);
			liquidVis.amount = toAdd;

			if (ThaumcraftApi.decreaseClosestAura(this.worldObj, this.xCoord, this.yCoord, this.zCoord, 100, true)) {
				ThaumcraftApi.addFluxToClosest(this.worldObj, this.xCoord, this.yCoord, this.zCoord, new ObjectTags().add(EnumTag.MAGIC, fluxToAdd));
				tank.fill(liquidVis, true);
			} else {
				timeSinceLastPull = 1000;
			}
		}
		timeSinceLastPull = 200;
	} else {
		timeSinceLastPull--;
	}
}

@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) {
	return 0;
}

@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
	return 0;
}

@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
	if (from != ForgeDirection.UP) {
		return drain(0, maxDrain, doDrain);
	}

	return null;
}

@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) {
	return tank.drain(maxDrain, doDrain);
}

@Override
public ILiquidTank[] getTanks(ForgeDirection direction) {
	ILiquidTank[] array = {tank};
	return array;
}

@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) {
	if (type.itemID == ItemHandler.liquidVis.itemID) {
		return tank;
	}

	return null;
}

public int getScaledLiquid(int i) {
	return tank.getLiquid() != null ? (int) (((float) tank.getLiquid().amount / (float) (tank.getCapacity())) * i) : 0;
}

}

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.

Announcements



×
×
  • Create New...

Important Information

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