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

  • Author

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());
}

}

  • Author

I have Waila integration for my energy system. When I place the storage block down, it says it has the correct amount of energy, but then it jumps to zero.

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

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.

  • Author

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

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.