Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.9]TE wont work as planned


Kaneka
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Could you explain what you mean by that, just to clarify I am trying to create a recipe type that handles potions and I'm pretty sure the standard recipe type cannot handle nbt data within the recipe. Do you mean use minecraft:crafting_shapeless as the type in the json file or am I misinterpreting 
    • Use the same recipe type as the crafting table. The recipe and serializer is the only thing that needs to be unique.
    • I have a custom recipe type that has successfully registered into minecraft, however I am trying to get it to work on the standard crafting table as it doesn't need a custom table for it.   { "type": "randomfhings:potion_edible", "ingredients": [ { "item" : "minecraft:glass", "data": "" }, { "item" : "minecraft:diamond" } ], "output": { "item": "randomfhings:ruby", "count": 3 } } This is a test recipe so far . package org.multicoder.randomfhings.recipe; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import net.minecraft.core.NonNullList; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.*; import net.minecraft.world.level.Level; import org.multicoder.randomfhings.RandomFhings; import javax.annotation.Nullable; public class PotionRecipe implements Recipe<CraftingContainer> { private final ResourceLocation id; private final ItemStack output; private final NonNullList<Ingredient> input; public PotionRecipe(ResourceLocation id, ItemStack output, NonNullList<Ingredient> input) { this.id = id; this.output = output; this.input = input; } @Override public NonNullList<Ingredient> getIngredients() { return input; } @Override public boolean matches(CraftingContainer p_44002_, Level p_44003_) { return input.get(0).test(p_44002_.getItem(0)); } @Override public ItemStack assemble(CraftingContainer p_44001_) { return output.copy(); } @Override public boolean canCraftInDimensions(int p_43999_, int p_44000_) { return true; } @Override public ItemStack getResultItem() { return output; } @Override public ResourceLocation getId() { return id; } @Override public RecipeSerializer<?> getSerializer() { return Serializer.INSTANCE; } @Override public RecipeType<?> getType() { return Type.INSTANCE; } public static class Type implements RecipeType<PotionRecipe> { private Type() { } public static final Type INSTANCE = new Type(); public static final String ID = "potion_edible"; } public static class Serializer implements RecipeSerializer<PotionRecipe> { public static final Serializer INSTANCE = new Serializer(); public static final ResourceLocation ID = new ResourceLocation(RandomFhings.MOD_ID,"potion_edible"); @Override public PotionRecipe fromJson(ResourceLocation id, JsonObject json) { ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "output")); JsonArray ingredients = GsonHelper.getAsJsonArray(json, "ingredients"); NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.fromJson(ingredients.get(i))); } return new PotionRecipe(id, output, inputs); } @Override public PotionRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) { NonNullList<Ingredient> inputs = NonNullList.withSize(buf.readInt(), Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.fromNetwork(buf)); } ItemStack output = buf.readItem(); return new PotionRecipe(id, output, inputs); } @Override public void toNetwork(FriendlyByteBuf buf, PotionRecipe recipe) { buf.writeInt(recipe.getIngredients().size()); for (Ingredient ing : recipe.getIngredients()) { ing.toNetwork(buf); } buf.writeItemStack(recipe.getResultItem(), false); } @Override public RecipeSerializer<?> setRegistryName(ResourceLocation name) { return INSTANCE; } @Nullable @Override public ResourceLocation getRegistryName() { return ID; } @Override public Class<RecipeSerializer<?>> getRegistryType() { return Serializer.castClass(RecipeSerializer.class); } @SuppressWarnings("unchecked") // Need this wrapper, because generics private static <G> Class<G> castClass(Class<?> cls) { return (Class<G>)cls; } } } This is my recipe type class and it is registered via a deferred register.
    • The version you are using is no longer supported on this forum. Please update to a modern version of Minecraft to receive support. Currently supported versions are 1.19.2 (Latest) and 1.18.2 (LTS).
    • The version you are using is no longer supported on this forum. Please update to a modern version of Minecraft to receive support. Currently supported versions are 1.19.2 (Latest) and 1.18.2 (LTS).
  • Topics

×
×
  • Create New...

Important Information

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