Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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;
}

}

 

You pasted your block twice.

But im gunna take a wild stab in the dark. http://bit.ly/P4ab2i

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

  • Author

...I'll be the one in the corner, banging my head against the wall.

 

Thanks.

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.