Jump to content

[1.7.10] How to stop tile entity from reading nbt data on first place


Recommended Posts

Posted

I have a tile entity that stores energy from a custom energy system I made, but the problem is that when I place down the energy storage block next to another energy storage block, the other energy storage block outputs all of its energy to the one I just placed down. Thats what it is supposed to do, and it does that but the problem is that it outputs all of its energy to the energy storage block I just placed down, before the tile entity initializes, so it outputs the power then that power gets deleted because it reads the nbt data first then writes it. So basically when ever I place a energy storage block next to another one, all the power in the first gets deleted. So, how do I stop a tile entity from reading nbt data when you first place the block?

Posted

Then why is this happening? Here is my code:

 

Main tile entity:

package net.sparklepopprograms.enchantedaura.tileentitys;

import net.minecraft.tileentity.TileEntity;
import net.sparklepopprograms.core.api.energy.BaseEnergyStorageBlock;
import net.sparklepopprograms.core.api.energy.IAuraUser;
import net.sparklepopprograms.core.util.PositionInWorld;
import net.sparklepopprograms.core.util.WorldHelper;

public class TileAuraBuffer extends BaseEnergyStorageBlock {

public TileAuraBuffer() {
	super();
	this.setCapacity(35000);
}

@Override
public void updateEntity() {
	PositionInWorld[] output = WorldHelper.getListOfPositionsAroundBlock(xCoord, yCoord, zCoord);
	int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);

	TileEntity tile = worldObj.getTileEntity(output[meta].getX(), output[meta].getY(), output[meta].getZ());

	if (tile instanceof IAuraUser) {
		this.extractAura(((BaseEnergyStorageBlock)tile).receiveAura(this.getStoredAura(), false), false);
	}
}

}

 

BaseEnergyStorageBlock:

 

package net.sparklepopprograms.core.api.energy;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class BaseEnergyStorageBlock extends TileEntity implements IAuraUser {

long energy;
long capacity;

public void readFromNBT(NBTTagCompound var1) {
    super.readFromNBT(var1);
    energy = var1.getLong("AuraStorage");
  }

public void writeToNBT(NBTTagCompound var1) {
    super.writeToNBT(var1);
    var1.setLong("AuraStorage", energy);
  }

public void setCapacity(long capacity) {

	this.capacity = capacity;

	if (energy > capacity) {
		energy = capacity;
	}
}

public long receiveAura(long maxReceive, boolean simulate) {

	long energyReceived = Math.min(capacity - energy, maxReceive);

	if (!simulate) {
		energy += energyReceived;
	}

	return energyReceived;
}

public long extractAura(long maxExtract, boolean simulate) {

	long energyExtracted = Math.min(energy, maxExtract);

	if (!simulate) {
		energy -= energyExtracted;
	}

	return energyExtracted;
}

public void modifyEnergyStored(int energy) {

	this.energy += energy;

	if (this.energy > capacity) {
		this.energy = capacity;
	} else if (this.energy < 0) {
		this.energy = 0;
	}
}

public long getStoredAura() {

	return energy;
}

public long getMaxStoredAura() {

	return capacity;
}

@Override
public Packet getDescriptionPacket() {
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        this.writeToNBT(nbttagcompound);
        return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 3, nbttagcompound);
    }

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
	this.readFromNBT(pkt.func_148857_g());
}

}

Posted

Well the point is that it might be that the energy value isnt synced, so waila tells you that the energy is zero (on ur side, client) but on server side it is correct and simply not synchronized with client

Posted

How do I synchronize it?

 

Packets.

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.

Posted

I am using packets. It does sync. First it shows the correct value, then it turns to zero, then it starts counting up and works fine after that. It's the initial transfer that does not work, but after that it works fine.

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.