Jump to content

Recommended Posts

Posted

Hello everyone, im currently working on a power storage block which im calling EnergyBankT1,

im running into a problem where it is able to store power easily with no problems but when i try to transfer it doesn't work, im using EnderIO for power transfer, I have the cables set to extract and all that but the EnergyBank is only storing not transfering, im trying to make it so that all sides can input and output energy

 

EnergyBankT1

public class EnergyBankT1 extends BlockContainer {

public EnergyBankT1(Material material, String unlocalizedName) {
	super(material);
	this.setHardness(3.0F);
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(EnergyPlus.EnergyPlus);
}

    public EnergyBankT1(String unlocalisedName) {
        this(Material.IRON, unlocalisedName);
    } 
    
    @Override
    public boolean isOpaqueCube(IBlockState state) {
    	return false;
    }
    
    @Override
    public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.MODEL;
    }


public TileEntity createNewTileEntity(World worldIn, int meta) {
	return new TileEnergyBankT1();
}		

@Override
public boolean hasTileEntity() {
	return true;
}

@Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {

	TileEntity te = world.getTileEntity(pos);

        TileEnergyBankT1 ebt1 = (TileEnergyBankT1)te;

	player.addChatMessage(new TextComponentString("Energy Stored: " + ebt1.getEnergyStored(side) + "/" + ebt1.getMaxEnergyStored(side) + " RF") );
	return true;
}	

}

 

TileEnergyBankT1

public class TileEnergyBankT1 extends TileEntity implements IEnergyProvider, IEnergyReceiver {

	protected EnergyStorage capacity = new EnergyStorage(500000);
	private int maxReceive = 5000;
	private int maxExtract = 5000;

public TileEnergyBankT1(int maxReceive, int maxExtract) {

	  this.maxReceive = maxReceive;
	  this.maxExtract = maxExtract;
	  
	 }

public TileEnergyBankT1() {

}

@Override
public void readFromNBT(NBTTagCompound nbt) {

	super.readFromNBT(nbt);
	this.readFromNBT(nbt);
	capacity.readFromNBT(nbt); 
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {

	super.writeToNBT(nbt);
	this.writeToNBT(nbt);
	capacity.writeToNBT(nbt);
	return nbt;
}

@Override
public int getEnergyStored(EnumFacing from) {
	return capacity.getEnergyStored();	
	}

@Override
public int getMaxEnergyStored(EnumFacing from) {
	return capacity.getMaxEnergyStored();

}

@Override
public boolean canConnectEnergy(EnumFacing from) {
	return true;
}

@Override
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
	return capacity.receiveEnergy(this.maxReceive, simulate);
	}

@Override
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {
	return capacity.extractEnergy(this.maxExtract, simulate);
	}

}

Posted

Also, don't use BlockContainer. It is deprecated and not meant to be used by modders.

If my post helped you, please press that "Thank You"-button to show your appreciation.

 

Also if you don't know Java, I would suggest you read the official tutorials by Oracle to get an idea of how to do this. Thanks, and good modding!

 

Also if you haven't, set up a Git repo for your mod not only for convinience but also to make it easier to help you.

Posted

I think its best if i rephrase my question, Basically the TileEntity method for writeToNBT isnt working correctly, it writes on the client side but does not on server side, some help with the correct implementation would be greatly appreciated.

Posted

writeToNbt is not called on the client at all.

 

it isnt hmm, did not know, the reason i was thinking that was because in the block class I read the energy stored and output as a chat componenent. It's been outputting 2 values when i fill it up with energy, one that just says 0/500000 RF and the other one says 500000/500000 RF, hence my reasoning to think it was erroring on client side,

it could also be that since it doesnt call on client side then its erroring on writing on server side

Posted

Well the reason I mention the writing to NBT is because the method seems to cause a ticking world error... not because I thought it was why I couldn't write it to the server.

 

My question was how do I write the packets and store it to NBT for recall.

Posted

Well the reason I mention the writing to NBT is because the method seems to cause a ticking world error... not because I thought it was why I couldn't write it to the server.

Sorry, a what? How does that have anything to do with NBT? What do you mean by "write to the server"?

My question was how do I write the packets and store it to NBT for recall.

That depends. Does the client need to always know the value? Only when the player is viewing the GUI? Other conditions?

And again, NBT has exactly nothing to do with this.

 

During testing, I left an instance of my TileEnergBankT1 receiving energy and attempting to extract energy in world. After exiting, I tried to re-enter that world just for it to crash my client very time.

 

According to my console log, the TileEntity was missing a mapping which was ultimately causing a ticking world error. Is this due to the fact I'm not handling packets server side?

 

If I seem a bit unsure, I apologise. Back in 1.7.10, the writeToNBT method just worked and some of the new methods escape me due to that.

 

Any explanation as to how to implement the server packets would be appreciated

 

Also currently, the only instance I have of needing to know the energy stored is during a player right click. It shows me the current energy stored, and the maximum it can hold.

 

In that instance; yes. The client needs to read from the TileEntity the energy stored, so to output the information into the chat console.

I plan to make most of this GUI free

Posted

There is no need to have any packets here at all, the client does not need to know. Simply add a chat message serverside.

I feel really stupid that i forgot to register the TE

anyways do I call it server side with @SideOnly or is there a better way?

Posted

I have managed to make the chat message only show on the logical server side I think.

 

By utilising:

@Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
	if(world.isRemote) {
		TileEntity te = world.getTileEntity(pos);
		TileEnergyBankT1 ebt1 = (TileEnergyBankT1) te;

		player.addChatMessage(new TextComponentString("Energy Stored: " + ebt1.getEnergyStored(side) + "/" + ebt1.getMaxEnergyStored(side) + " RF"));
		return true;
	}
	return false;
}
}

 

I believe it is now only sending the message server side. If that is the case, it returns 0/500000RF every time I click which confirms my suspicions that it wasn't actually storing the energy and therefore explains why it can not be extracted.

 

Although that being said, I do not understand how the logical client component can be charged by the EnderIO conduits yet not drained by them client side...

Posted

With an item selected in my inventory, the chat message only appears once. With no item in the inventory slot, it appears twice as if pinging the logical server twice for some reason.

 

When I added in another conditional to check for a specific item, when it wasn't that item it would return a null pointer. Not one severe enough to crash the client, but null pointers are never a good thing.

Posted

I have seemed to solve the problem with the storing energy, the only problem left is the transferring of energy, would i have to fix this with packets? if so do you know of any good up to date tutorials on packets?

Posted

If packets are not needed, what is, i have looked at other mods codes such as EnderIO and RFTools, and i cant seem to find how they are making the energy transfer work, unless i am missing something

Posted

push and pull depending

 

This sounds like a terrible idea.

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

push and pull depending

 

This sounds like a terrible idea.

 

Why would you say that? I mean i know myself it isnt gonna work out well and its just a temporary solution for now until i finish mostly everything else then ill go back to it and change it up for players to set their own input/output sides

Posted

Having both sets yourself up for collisions and unexpected behavior.

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.

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.