Jump to content

Recommended Posts

Posted

hi

I need to get an int from my tile entity

if i do it this way:

    	TileEntityHeatConductant tile = (TileEntityHeatConductant) p_149674_1_.getTileEntity(p_149674_2_, p_149674_3_, p_149674_4_);
    	if (tile != null)
    	{
    		temp = (int) tile.Temperature;
    	}

it'll end up changing the int for all the blocks.

 

i need to get the int inside here

    public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_)
    {
   		return the tileentity int;
    }

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

Couldn't you do something like

 

TileEntityHeatConductant tile = (TileEntityHeatConductant)world.getBlockTileEntity(x,y,z);
    	if (tile != null)
    	{
    		color = tile.color;
    	}

 

You have those 4 parameters (pos and world) so it won't be a problem.

I try my best, so apologies if I said something obviously stupid!

Posted

Thanks for the quick reply's   

 

@SideOnly(Side.CLIENT)

    public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_)

    {

  return 0;

    }

 

I can't get the tile entity variable tile.color from here because this doesn't have world

 

if i get it via another method it sets the color for all current blocks. because i do color = tile.color

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

For the no world argument, use the IBlockAccess one.

 

For the other issue, I don't really get why that's happening

I try my best, so apologies if I said something obviously stupid!

Posted

Yeah the other one was because i set the color for the whole class thus changing all colors.

 

And thanks the iblockacces works!

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

So right now are you still having the second issue or you fixed everything? :)

I try my best, so apologies if I said something obviously stupid!

Posted

Gosh, these look frighteningly similar.

 

gosh.png

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

Gosh, these look frighteningly similar.

 

gosh.png

 

I know haha I just didn't knew I could use iblockacces as world

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

I know haha I just didn't knew I could use iblockacces as world

 

class World implements IBlockAccess at some level (I just don't recall where).

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

Okay thanks for your help the block works great now only thing is my tileenity's nbt data is lost when I disconnect from my world.

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

Okay thanks for your help the block works great now only thing is my tileenity's nbt data is lost when I disconnect from my world.

 

override readFromNBT and writeToNBT

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'm already doing that could it be because I do this in the class start :

 

double Temperature = 21;

 

int color = 0x555555;

int conductiveness = 0;

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

That is NOT the same thing at all.

 

read/write NBT methods are for SAVING AND LOADING DATA.  Resetting data is not even close to the same thing.

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

yeah i know but i thaught maybe that overrides my nbt again

this is my nbt

	@Override
   	public void writeToNBT(NBTTagCompound nbt)
   	{
   		super.writeToNBT(nbt);
      	nbt.setDouble("Temperature", Temperature);
      	nbt.setInteger("Color", color);
   	}

   	@Override
   	public void readFromNBT(NBTTagCompound nbt)
   	{
   		super.readFromNBT(nbt);
      	this.Temperature = nbt.getDouble("Temperature");
      	this.color = nbt.getInteger("Color");
   	}

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

No, read and write is always called after construction.

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

Then would you maybe know why it isn't saving the data correctly?

pretty wierd because it used to but now it doesn't

BlockCode

package molecularscience.moditems;

import java.util.List;
import java.util.Random;

import molecularscience.MolecularScience;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.world.ColorizerGrass;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockHeatConductant extends BlockContainer{

int conductiveness = 0;

public BlockHeatConductant(Material material, int conduct) {
	super(material);
	this.setCreativeTab(MolecularScience.MBlocks);
	this.setBlockTextureName("molecularscience:BlockHeatConductant");
	this.conductiveness = conduct;
}
    
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityHeatConductant(this, conductiveness);
}

    public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_){}
    
    @Override
    public void onEntityCollidedWithBlock(World p_149670_1_, int p_149670_2_, int p_149670_3_, int p_149670_4_, Entity p_149670_5_)
    {
        p_149670_5_.attackEntityFrom(DamageSource.fallingBlock, 2);
    }

    @SideOnly(Side.CLIENT)
    public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_)
    {
    	int temp = 0;
    	TileEntityHeatConductant tile = (TileEntityHeatConductant) p_149720_1_.getTileEntity(p_149720_2_, p_149720_3_, p_149720_4_);
    	if (tile != null)
    	{
    		temp = tile.color;
    	}
   		return temp;
    }
    
    public boolean isOpaqueCube(){
    	return false;
    }
    
    public boolean renderAsNormalBlock(){
    	return false;
    }
}

 

TileEntity4

package molecularscience.moditems;

import org.apache.logging.log4j.core.pattern.ConverterKeys;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import molecularscience.MolecularScience;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class TileEntityHeatConductant extends TileEntity{

double Temperature = 21;

int color = 0x555555;
int conductiveness = 0;

Block Block;

public TileEntityHeatConductant(Block block, int conduct) {
	this.Block = block;
	this.conductiveness = conduct;
}

@Override
   	public void writeToNBT(NBTTagCompound nbt)
   	{
   		super.writeToNBT(nbt);
      	nbt.setDouble("Temperature", Temperature);
      	nbt.setInteger("Color", color);
   	}

   	@Override
   	public void readFromNBT(NBTTagCompound nbt)
   	{
   		super.readFromNBT(nbt);
      	this.Temperature = nbt.getDouble("Temperature");
      	this.color = nbt.getInteger("Color");
   	}
   	
   	@Override
   	public boolean canUpdate(){
   		return true;
   	}
   	
   	public int getColor(){
   		int intcolor = 0;
   		int green = (int) ((64.0 / 700.0) * this.Temperature);
   		int red = (int) ((255.0 / 700.0) * this.Temperature);
   		return ((green*256) + (red*65536));
   	}
   	
   	@Override
   	public void updateEntity() {
   		checkblocks(worldObj.getBlock(xCoord+1, yCoord, zCoord).getLocalizedName(), "1 0 0");
   		checkblocks(worldObj.getBlock(xCoord-1, yCoord, zCoord).getLocalizedName(), "-1 0 0");
   		checkblocks(worldObj.getBlock(xCoord, yCoord+1, zCoord).getLocalizedName(), "0 1 0");
   		checkblocks(worldObj.getBlock(xCoord, yCoord-1, zCoord).getLocalizedName(), "0 -1 0");
   		checkblocks(worldObj.getBlock(xCoord, yCoord, zCoord+1).getLocalizedName(), "0 0 1");
   		checkblocks(worldObj.getBlock(xCoord, yCoord, zCoord-1).getLocalizedName(), "0 0 -1");
   		worldObj.scheduleBlockUpdate(xCoord, yCoord, zCoord, Block, 1);
   		this.color = getColor();
   		this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
   	}
   	
   	public void checkblocks(String block, String coord){
   		boolean aircool = true;

	String[] coords = coord.split(" ");
   		if(block.equals("Fire")){
   			if(Temperature <= 600.0){
   				Temperature = Temperature + 0.1;
   			}
   			aircool = false;
   		}
   		if(block.equals("Lava")){
   			if(Temperature <= 700.0){
   				Temperature = Temperature + 0.5;
   			}else{
   				
   			}
   			aircool = false;
   		}
   		if(block.equals("Water")){
   			if(Temperature >= 10.0){
   				Temperature = Temperature - 20;
   				if(Temperature >= 100){
   					//worldObj.setBlockToAir(xCoord + Integer.parseInt(coords[0]), yCoord + Integer.parseInt(coords[1]), zCoord + Integer.parseInt(coords[2]));
   				}
   			}
   			aircool = false;
   		}
   		if(block.contains("HeatConductant")){
   			int gettiletemp = 0;
   			
   	    	TileEntityHeatConductant tile = (TileEntityHeatConductant) worldObj.getTileEntity(xCoord + Integer.parseInt(coords[0]), yCoord + Integer.parseInt(coords[1]), zCoord + Integer.parseInt(coords[2]));
   	    	if (tile != null)
   	    	{
   	    		gettiletemp = (int) tile.Temperature;
   	    	}
   	    	if(gettiletemp >= this.Temperature){
   	    		double add = gettiletemp - this.Temperature;
   	    		add = add / conductiveness;
   	    		Temperature = Temperature + add;
   	    	}
   	    	aircool = false;
   		}
   		if(aircool == true){
   			if(Temperature >= 20){
   				Temperature = Temperature - 0.3;
   			}
   		}
   	}
}

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

Do not pass references to a TileEntity's constructor.  It messes up all of the things.

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

Do not pass references to a TileEntity's constructor.  It messes up all of the things.

Even just 1 int?

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

Do not pass references to a TileEntity's constructor.  It messes up all of the things.

Even just 1 int?

 

Yes.  It screws with the save/load process.  I don't know why, but it does.

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

Ah well thats wierd atleast thanks for the help I would have never figured that out.

Would you know how I can get the block the tileentity is connected to?

EDIT: Stupid me this.getblocktype(); :3

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

hmm somehow the nbt data is still lost

this is my tile entity

 

public class TileEntityHeatConductant extends TileEntity{

double Temperature = 21;

int color = 0x555555;

@Override
   	public void writeToNBT(NBTTagCompound nbt)
   	{
   		super.writeToNBT(nbt);
      	nbt.setDouble("Temperature", Temperature);
      	nbt.setInteger("Color", color);
   	}

   	@Override
   	public void readFromNBT(NBTTagCompound nbt)
   	{
   		super.readFromNBT(nbt);
      	this.Temperature = nbt.getDouble("Temperature");
      	this.color = nbt.getInteger("Color");
   	}
   	
   	@Override
   	public boolean canUpdate(){
   		return true;
   	}
   	
   	public int getColor(){
   		int intcolor = 0;
   		int green = (int) ((64.0 / 700.0) * this.Temperature);
   		int red = (int) ((255.0 / 700.0) * this.Temperature);
   		return ((green*256) + (red*65536));
   	}
   	
   	@Override
   	public void updateEntity() {
   		checkblocks(worldObj.getBlock(xCoord+1, yCoord, zCoord).getLocalizedName(), "1 0 0");
   		checkblocks(worldObj.getBlock(xCoord-1, yCoord, zCoord).getLocalizedName(), "-1 0 0");
   		checkblocks(worldObj.getBlock(xCoord, yCoord+1, zCoord).getLocalizedName(), "0 1 0");
   		checkblocks(worldObj.getBlock(xCoord, yCoord-1, zCoord).getLocalizedName(), "0 -1 0");
   		checkblocks(worldObj.getBlock(xCoord, yCoord, zCoord+1).getLocalizedName(), "0 0 1");
   		checkblocks(worldObj.getBlock(xCoord, yCoord, zCoord-1).getLocalizedName(), "0 0 -1");
   		worldObj.scheduleBlockUpdate(xCoord, yCoord, zCoord, this.getBlockType(), 1);
   		this.color = getColor();
   		this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
   	}
   	
   	public void checkblocks(String block, String coord){
   		boolean aircool = true;

	String[] coords = coord.split(" ");
   		if(block.equals("Fire")){
   			if(Temperature <= 600.0){
   				Temperature = Temperature + 0.1;
   			}
   			aircool = false;
   		}
   		if(block.equals("Lava")){
   			if(Temperature <= 700.0){
   				Temperature = Temperature + 0.5;
   			}else{
   				
   			}
   			aircool = false;
   		}
   		if(block.equals("Water")){
   			if(Temperature >= 10.0){
   				Temperature = Temperature - 20;
   				if(Temperature >= 100){
   					//worldObj.setBlockToAir(xCoord + Integer.parseInt(coords[0]), yCoord + Integer.parseInt(coords[1]), zCoord + Integer.parseInt(coords[2]));
   				}
   			}
   			aircool = false;
   		}
   		if(block.contains("HeatConductant")){
   			int gettiletemp = 0;
   			
   	    	TileEntityHeatConductant tile = (TileEntityHeatConductant) worldObj.getTileEntity(xCoord + Integer.parseInt(coords[0]), yCoord + Integer.parseInt(coords[1]), zCoord + Integer.parseInt(coords[2]));
   	    	if (tile != null)
   	    	{
   	    		gettiletemp = (int) tile.Temperature;
   	    	}
   	    	if(gettiletemp >= this.Temperature){
   	    		int conductiveness = 0;
   	    		String[] test = this.getBlockType().getLocalizedName().split(" ");
   	    		if(test[0].equals("Fast")){
   	    			conductiveness = 5;
   	    		}
   	    		double add = gettiletemp - this.Temperature;
   	    		add = add / conductiveness;
   	    		Temperature = Temperature + add;
   	    	}
   	    	aircool = false;
   		}
   		if(aircool == true){
   			if(Temperature >= 20){
   				Temperature = Temperature - 0.3;
   			}
   		}
   	}

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

Did you perhaps forget to call TileEntity.addMapping(TileEntityHeatConductant, "MolecularScience_MyHeatConductant");

 

It needs that to reload tile entities and save the data properly.

 

The naming just has to be unique across all tile entities in all mods.

 

You can do that in a static block in your class.

static {
addMapping(Class,"id");
}

Posted

Hmm yes i didn't do that but where would I place that percisely?

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

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