Jump to content

Recommended Posts

Posted

Hi everyone,

 

I am trying to add a solar plants that produces energy. But after a restart the already created energy is removed and until I click on the block, it wont produce energy(when I click on it after waiting a bit, it says "Energy 0/16000")

 

Here is the code:

 

 

Here the SolarPlant.class

package net.kaneka.planttech.blocks.machines.energy.producer;

import net.kaneka.planttech.Main;
import net.kaneka.planttech.blocks.tileentities.TileEntityCompostBin;
import net.kaneka.planttech.blocks.tileentities.energy.producer.TileEntityCreativeEnergyProducer;
import net.kaneka.planttech.blocks.tileentities.energy.producer.TileEntitySolarPlant;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;

public class SolarPlant extends BlockContainer
{

public SolarPlant() {
	super(Material.wood);
	this.setUnlocalizedName("solarplant");
	this.setCreativeTab(Main.planttech3);
	this.setHardness(0.5F);
}

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {

	return new TileEntitySolarPlant();
}

@Override
 public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.MODEL;
    }

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

	if(!worldIn.isRemote)
	{
		TileEntity tileentity = worldIn.getTileEntity(pos);
		if (tileentity instanceof TileEntitySolarPlant)
		{
			 playerIn.addChatMessage(new TextComponentString("Energy:"+((TileEntitySolarPlant) tileentity).getCurrentEnergy() + "/" + ((TileEntitySolarPlant)   tileentity).getEnergyStorageLimit()));
		}
	}
	return true;
}

@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ,
		int meta, EntityLivingBase placer) {
	worldIn.addTileEntity(new TileEntitySolarPlant());
	return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
}

@Override
public boolean isFullBlock(IBlockState state) {
	return false;
}

@Override
public BlockRenderLayer getBlockLayer() {
	return BlockRenderLayer.CUTOUT;
}

@Override
public boolean isOpaqueCube(IBlockState state) {
	return false;
}
}

 

 

and here the TileEntitySolarPlant.class

 

package net.kaneka.planttech.blocks.tileentities.energy.producer;

import net.kaneka.planttech.energysystem.interfaces.IEnergyConsumer;
import net.kaneka.planttech.energysystem.interfaces.IEnergyController;
import net.kaneka.planttech.energysystem.interfaces.IEnergyProducer;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class TileEntitySolarPlant extends TileEntity implements ITickable, IEnergyProducer{

private int maxEnergy = 16000;
private int energyatm = 0;
private int energyPerTick = 1;
private int tickstillremove = 25;
private BlockPos controllercoordinates;


@Override
public void setNetwork(World world, BlockPos controller, int cableAmount, int cableTier) {
	boolean alreadyregisted = false;
	tickstillremove = 25;
	if(controllercoordinates != controller)
	{
		alreadyregisted = true;
	}
	if(alreadyregisted)
	{
		this.controllercoordinates = controller;
		Block controllerblock = world.getBlockState(controller).getBlock();
		if(controllerblock.hasTileEntity(controllerblock.getDefaultState()))
		{
			TileEntity te = world.getTileEntity(controller);
			if(te instanceof IEnergyController)
			{
				((IEnergyController) te).registerEnergyConsumer(this.pos, cableAmount, cableTier);
			}
		}

	}

}

@Override
public int getEnergyStorageLimit() {
	return maxEnergy;
}

@Override
public int getCurrentEnergy() {	
	return energyatm;
}

@Override
public void reduceCE(int amount) {
if(energyatm >= amount)
	{
	energyatm = energyatm - amount;
	}	
}

@Override
public void update() 
{
	if(this.getWorld().getLightFromNeighbors(pos.up()) > 14)
	{
		if(maxEnergy >= (energyatm + energyPerTick))
		{
			energyatm = energyatm + energyPerTick;
		}
		if(maxEnergy < (energyatm + energyPerTick))
		{
			energyatm = maxEnergy;
		}
	}

}

@Override
public void readFromNBT(NBTTagCompound compound) {
	  super.readFromNBT(compound);
       
        
        energyatm = compound.getInteger("energyatm");
        tickstillremove = compound.getShort("TicksTillRemove");
        int x = compound.getShort("ControllerX");
        int y = compound.getShort("ControllerY");
        int z = compound.getShort("ControllerZ");
        controllercoordinates = new BlockPos(x, y, z);
        
}

@Override
public void writeToNBT(NBTTagCompound compound) {
	  super.writeToNBT(compound);
	  	compound.setInteger("energyatm", energyatm);
        compound.setShort("TicksTillRemove", (short)tickstillremove);
        compound.setShort("ControllerX", (short)controllercoordinates.getX());
        compound.setShort("ControllerY", (short)controllercoordinates.getY());
        compound.setShort("ControllerZ", (short)controllercoordinates.getZ());
        
}


}

 

I hope someone can help me.

 

Thanks for every answer!

 

Kaneka

Posted

Your subject line looks like a warning message that you received, which means you've already been told by the compiler what you did wrong. Did you forget to register your TE?

 

See Jabelar's TileEntity article

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

GameRegistry.registerTileEntity(TileEntitySolarPlant.class, "tileentitysolarplant");

 

it is like all my other are and these works fine. Thats what disturb me, everyone of my other TE works. And the compiler don´t tell me what I did wrong...then I could correct it....

Posted

Feeling so dump....it causes an exeption when trying to do writetoNBT cause controllercoordinates was null....

Thanks for the help jerryfisher

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.