Jump to content

All blocks copying original blocks tile entity values.


Recommended Posts

Posted

Through a gui, I'm setting values in a tile entity. The tile entity is grabbed through the world function, and is passed the position of the block. The value save just fine, but once they're saved, every block I place after the first one takes those values, instead of creating a new tile entity.

 

What gives?

 

Block File:

 

package dmillerw.rfidtags;

import java.util.Random;

import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;

import net.minecraft.src.BlockContainer;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.Material;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;

public class BlockRFIDDetector extends BlockContainer {

protected BlockRFIDDetector(int par1, Material par2Material) {
super(par1, par2Material);
this.setCreativeTab(CreativeTabs.tabRedstone);
this.setTickRandomly(true);
}

@Override
public TileEntity createNewTileEntity(World var1) {
return new TileEntityRFIDDetector();
}

public int tickRate()
{
return 2;
}

@SideOnly(Side.CLIENT)
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
TileEntityRFIDDetector tileEntity = (TileEntityRFIDDetector) par1World.getBlockTileEntity(par2, par3, par4);

System.out.println(tileEntity.finalized);
System.out.println(tileEntity.setID1);

if (!par5EntityPlayer.isSneaking()) {
//TODO: Fix this damn thing!!
if (tileEntity.finalized == true) {
return true;
} else {
par5EntityPlayer.openGui(RFIDMainFile.instance, 0, par1World, par2, par3, par4);
}
//par5EntityPlayer.addChatMessage("BROKEN");
return true;
} else {
return true;
}
}

public boolean isPoweringTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
TileEntityRFIDDetector tileEntity = (TileEntityRFIDDetector) par1IBlockAccess.getBlockTileEntity(par2, par3, par4);

int metadata = par1IBlockAccess.getBlockMetadata(par2, par3, par4);

if (metadata == 1) {
return true;
} else {
return false;
}
}

/**
* Is this block indirectly powering the block on the specified side
*/
public boolean isIndirectlyPoweringTo(World par1World, int par2, int par3, int par4, int par5)
{
TileEntityRFIDDetector tileEntity = (TileEntityRFIDDetector) par1World.getBlockTileEntity(par2, par3, par4);

int metadata = par1World.getBlockMetadata(par2, par3, par4);

if (metadata == 1) {
return true;
} else {
return false;
}
}

public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int l)
{
notifyNeighbors(world, i, j, k);
world.removeBlockTileEntity(i, j, k);
}

public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
{
super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
}

public void updateTick(World world, int i, int j, int k, Random random) {
super.updateTick(world, i, j, k, random);
world.scheduleBlockUpdate(i, j, k, this.blockID, this.tickRate());
notifyNeighbors(world, i, j, k);
}

public void notifyNeighbors(World world, int i, int j, int k)
{
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
}

/**
* Can this block provide power. Only wire currently seems to have this change based on its state.
*/
public boolean canProvidePower()
{
return true;
}

}

 

 

Tile Entity File:

 

package dmillerw.rfidtags;

import java.util.Random;

import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;

import net.minecraft.src.BlockContainer;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.Material;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;

public class BlockRFIDDetector extends BlockContainer {

protected BlockRFIDDetector(int par1, Material par2Material) {
super(par1, par2Material);
this.setCreativeTab(CreativeTabs.tabRedstone);
this.setTickRandomly(true);
}

@Override
public TileEntity createNewTileEntity(World var1) {
return new TileEntityRFIDDetector();
}

public int tickRate()
{
return 2;
}

@SideOnly(Side.CLIENT)
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
TileEntityRFIDDetector tileEntity = (TileEntityRFIDDetector) par1World.getBlockTileEntity(par2, par3, par4);

System.out.println(tileEntity.finalized);
System.out.println(tileEntity.setID1);

if (!par5EntityPlayer.isSneaking()) {
//TODO: Fix this damn thing!!
if (tileEntity.finalized == true) {
return true;
} else {
par5EntityPlayer.openGui(RFIDMainFile.instance, 0, par1World, par2, par3, par4);
}
//par5EntityPlayer.addChatMessage("BROKEN");
return true;
} else {
return true;
}
}

public boolean isPoweringTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
TileEntityRFIDDetector tileEntity = (TileEntityRFIDDetector) par1IBlockAccess.getBlockTileEntity(par2, par3, par4);

int metadata = par1IBlockAccess.getBlockMetadata(par2, par3, par4);

if (metadata == 1) {
return true;
} else {
return false;
}
}

/**
* Is this block indirectly powering the block on the specified side
*/
public boolean isIndirectlyPoweringTo(World par1World, int par2, int par3, int par4, int par5)
{
TileEntityRFIDDetector tileEntity = (TileEntityRFIDDetector) par1World.getBlockTileEntity(par2, par3, par4);

int metadata = par1World.getBlockMetadata(par2, par3, par4);

if (metadata == 1) {
return true;
} else {
return false;
}
}

public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int l)
{
notifyNeighbors(world, i, j, k);
world.removeBlockTileEntity(i, j, k);
}

public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
{
super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
}

public void updateTick(World world, int i, int j, int k, Random random) {
super.updateTick(world, i, j, k, random);
world.scheduleBlockUpdate(i, j, k, this.blockID, this.tickRate());
notifyNeighbors(world, i, j, k);
}

public void notifyNeighbors(World world, int i, int j, int k)
{
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
}

/**
* Can this block provide power. Only wire currently seems to have this change based on its state.
*/
public boolean canProvidePower()
{
return true;
}

}

 

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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