Jump to content

1.8.9 Tile Entity


dotdot

Recommended Posts

Hi I seem to be having problems with Tile Entity's I feel I'm missing something or I may not be just doing it correctly? what seems to be happening is I have a block that extends BlockContainer I have a GUI that sets data to the tileEntity and when I go to read the data from the block itself it returns the default values I think its not being updated on client side? I have little knowledge of tileEntitys but I have looked up as much as I can to try and solve this problem and how they work and still unable to get it working :( if anyone can shed some light on it and why it may not be working would be greatly appreciated thanks

 

WirelessRedstoneMod.class

 

 

package com.dot6.wireless_redstone;

import com.dot6.wireless_redstone.blocks.BlockWirelessRedstoneReceiver;
import com.dot6.wireless_redstone.gui.WirelessRedstoneReciverHandler;
import com.dot6.wireless_redstone.init.WirelessRedstoneBlocks;
import com.dot6.wireless_redstone.proxy.CommonProxy;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.client.renderer.block.statemap.StateMap.Builder;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
public class WirelessRedstoneMod {

@Mod.Instance(Reference.MOD_ID)
public static WirelessRedstoneMod instance = new WirelessRedstoneMod();;

@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
public static CommonProxy proxy;

/*@SideOnly(Side.CLIENT)
    public static String getPlayerName()
    {
        return null;// Minecraft.getMinecraft().thePlayer.getName();
    }*/

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	//Blocks
	//WindowBlocks.init();
	//WindowBlocks.register();		
	WirelessRedstoneBlocks.init(Minecraft.getMinecraft().getSession().getUsername());
	WirelessRedstoneBlocks.register();


	//Items
	//WindowItems.init();
	//WindowItems.register();

	/*Builder sm = new StateMap.Builder ();		
	sm.ignore(BlockWindow.POWERED);
	ModelLoader.setCustomStateMapper (WindowBlocks.oak_window, sm.build ());
	*/

	Builder smWirelessRedston = new StateMap.Builder ();		
	smWirelessRedston.ignore(BlockWirelessRedstoneReceiver.POWERED);

	ModelLoader.setCustomStateMapper (WirelessRedstoneBlocks.wireless_redstone_receiver, smWirelessRedston.build ());
	ModelLoader.setCustomStateMapper (WirelessRedstoneBlocks.wireless_redstone_receiver_powered, smWirelessRedston.build ());

	ModelLoader.setCustomStateMapper (WirelessRedstoneBlocks.wireless_redstone_sender, smWirelessRedston.build ());
	ModelLoader.setCustomStateMapper (WirelessRedstoneBlocks.wireless_redstone_sender_powered, smWirelessRedston.build ());

	proxy.registerRenders();
}

@EventHandler
public void init(FMLInitializationEvent event)
{

}

@EventHandler
public void postInit(FMLPostInitializationEvent event)
{

}

@Mod.EventHandler
public void load(FMLInitializationEvent event) {
	// Register our event listener:
	WirelessRedstoneReciverHandler events = new WirelessRedstoneReciverHandler();
	MinecraftForge.EVENT_BUS.register(events);

}

}

 

 

 

WilessRedstoneBlock.class

 

 

package com.dot6.wireless_redstone.init;

import com.dot6.wireless_redstone.Reference;
import com.dot6.wireless_redstone.WirelessRedstoneMod;
import com.dot6.wireless_redstone.blocks.BlockWirelessRedstoneReceiver;
import com.dot6.wireless_redstone.blocks.BlockWirelessRedstoneSender;
import com.dot6.wireless_redstone.gui.WirelessRedstoneGuiHandler;
import com.dot6.wireless_redstone.items.ItemWirelessRedstoneRemote;
import com.dot6.wireless_redstone.tileentity.TileEntityWirelessRedstoneReceiver;
import com.dot6.wireless_redstone.tileentity.TileEntityWirelessRedstoneSender;

import net.minecraft.block.Block;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class WirelessRedstoneBlocks {
//Blocks
public static Block wireless_redstone_receiver;
public static Block wireless_redstone_receiver_powered;
public static Block wireless_redstone_sender;
public static Block wireless_redstone_sender_powered;
//Items
public static Item wireless_redstone_remote;
public static Item wireless_redstone_remote_on;

public static void init(String playerName)	
{	
	//Blocks			
	wireless_redstone_receiver = (new BlockWirelessRedstoneReceiver(Boolean.valueOf(false), String.valueOf(playerName)).setHardness(0.8F).setResistance(5.0F).setStepSound(Block.soundTypeGlass).setRegistryName(Reference.MOD_ID + ":" + "wireless_redstone_receiver").setUnlocalizedName("wireless_redstone_receiver").setCreativeTab(CreativeTabs.tabRedstone));
	wireless_redstone_receiver_powered = (new BlockWirelessRedstoneReceiver(Boolean.valueOf(true), String.valueOf(playerName)).setHardness(0.8F).setResistance(5.0F).setStepSound(Block.soundTypeGlass).setRegistryName(Reference.MOD_ID + ":" + "wireless_redstone_receiver_powered"));
	wireless_redstone_sender = (new BlockWirelessRedstoneSender(Boolean.valueOf(false), String.valueOf(playerName)).setHardness(0.8F).setResistance(5.0F).setStepSound(Block.soundTypeGlass).setRegistryName(Reference.MOD_ID + ":" + "wireless_redstone_sender").setUnlocalizedName("wireless_redstone_sender").setCreativeTab(CreativeTabs.tabRedstone));
	wireless_redstone_sender_powered = (new BlockWirelessRedstoneSender(Boolean.valueOf(true), String.valueOf(playerName)).setHardness(0.8F).setResistance(5.0F).setStepSound(Block.soundTypeGlass).setRegistryName(Reference.MOD_ID + ":" + "wireless_redstone_sender_powered"));

	//Items
	wireless_redstone_remote = (new ItemWirelessRedstoneRemote(String.valueOf(playerName)).setRegistryName(Reference.MOD_ID + ":" + "wireless_redstone_remote").setUnlocalizedName("wireless_redstone_remote").setCreativeTab(CreativeTabs.tabRedstone));
	wireless_redstone_remote_on = (new ItemWirelessRedstoneRemote(String.valueOf(playerName)).setMaxStackSize(1).setRegistryName(Reference.MOD_ID + ":" + "wireless_redstone_remote_on").setUnlocalizedName("wireless_redstone_remote_on"));
	NetworkRegistry.INSTANCE.registerGuiHandler(WirelessRedstoneMod.instance, new WirelessRedstoneGuiHandler());


}

public static void register()
{
	//Tile Entity TileEntityWirelessRedstoneRemote
	GameRegistry.registerTileEntity(TileEntityWirelessRedstoneReceiver.class, Reference.MOD_ID + ":" + "wireless_redstone_receiver_tileentity");
	GameRegistry.registerTileEntity(TileEntityWirelessRedstoneSender.class, Reference.MOD_ID + ":" + "wireless_redstone_sender_tileentity");
	//GameRegistry.registerTileEntity(TileEntityWirelessRedstoneRemote.class, Reference.MOD_ID + ":" + "wireless_redstone_remote_tileentity");

	//Tile Mapping
	TileEntity.addMapping(TileEntityWirelessRedstoneReceiver.class, Reference.MOD_ID + ":" + "WirelessRedstoneReceiver");
	TileEntity.addMapping(TileEntityWirelessRedstoneSender.class, Reference.MOD_ID + ":" + "WirelessRedstoneSender");

	//Blocks
	GameRegistry.registerBlock(wireless_redstone_receiver);
	GameRegistry.registerBlock(wireless_redstone_receiver_powered);
	GameRegistry.registerBlock(wireless_redstone_sender);
	GameRegistry.registerBlock(wireless_redstone_sender_powered);

	//Items
	GameRegistry.registerItem(wireless_redstone_remote);
	GameRegistry.registerItem(wireless_redstone_remote_on);		
}

public static void registerRenders() 
{
	//Blocks
	registedrRender(wireless_redstone_receiver);
	registedrRender(wireless_redstone_sender);

	//Items
	registedrRender(wireless_redstone_remote);
	registedrRender(wireless_redstone_remote_on);
}

public static void registedrRender(Block block) 
{
	Item item = Item.getItemFromBlock(block);
	ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));		
}

public static void registedrRender(Item item) 
{		
	ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));		
}

}

 

 

 

BlockWirelessRedstoneSender.class

 

 

package com.dot6.wireless_redstone.blocks;

import java.util.ArrayList;
import java.util.Random;

import com.dot6.wireless_redstone.WirelessRedstoneBlockPos;
import com.dot6.wireless_redstone.WirelessRedstoneHelper;
import com.dot6.wireless_redstone.WirelessRedstoneMod;
import com.dot6.wireless_redstone.gui.WirelessRedstoneGuiHandler;
import com.dot6.wireless_redstone.init.WirelessRedstoneBlocks;
import com.dot6.wireless_redstone.tileentity.TileEntityWirelessRedstoneSender;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockWirelessRedstoneSender extends BlockContainer
{
    private final boolean isOn;
    public int frequency = 0;
    public boolean allaccess = false;
    public static final PropertyBool POWERED = PropertyBool.create("powered");
    public String playerName = null;
    
    public BlockWirelessRedstoneSender(boolean isOn, String playerName)
    {
        super(Material.circuits);
        this.setDefaultState(this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(isOn)));
        
        this.isOn = isOn;
        this.playerName = playerName;
        if (isOn)
        {
            this.setLightLevel(0.5F);
        }
    }    
    
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
    {
        if (!worldIn.isRemote)
        {        	
            if (this.isOn && !worldIn.isBlockPowered(pos))
            {
                worldIn.setBlockState(pos, WirelessRedstoneBlocks.wireless_redstone_sender.getDefaultState(), 2);                
            }
            else if (!this.isOn && worldIn.isBlockPowered(pos))
            {
                worldIn.setBlockState(pos, WirelessRedstoneBlocks.wireless_redstone_sender_powered.getDefaultState(), 2);
            }  
        }
    }

    /**
     * Called when a neighboring block changes.
     */
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
    {    	   		        
        if (!worldIn.isRemote)
        {  
            if (this.isOn && !worldIn.isBlockPowered(pos))
            {            	   
            	worldIn.scheduleUpdate(pos, this, 4);            	
            	
            }
            else if (!this.isOn && worldIn.isBlockPowered(pos))
            {   
            	worldIn.setBlockState(pos, WirelessRedstoneBlocks.wireless_redstone_sender_powered.getDefaultState(), 2);
            	
            	TileEntityWirelessRedstoneSender tile = null;
        		if(worldIn.getTileEntity(pos) instanceof TileEntityWirelessRedstoneSender)
        			tile = (TileEntityWirelessRedstoneSender)worldIn.getTileEntity(pos);
        		if (tile != null)
        		{
        			NBTTagCompound nBTTag = new NBTTagCompound();
        			tile.writeToNBT(nBTTag);
        			this.frequency = tile.getFrequency();
        		}
            	            	
			Minecraft.getMinecraft().thePlayer.sendChatMessage("onNeighborBlockChange: Frequency: " + this.frequency);

			ArrayList<WirelessRedstoneBlockPos> list = WirelessRedstoneHelper.findReceiver(this.frequency, worldIn, pos);    	
			if(list != null && list.size() > 0)
			{    	
				for(int i = 0; i < list.size(); i++)
				{   		
					WirelessRedstoneBlockPos wRBP = (WirelessRedstoneBlockPos)list.get(i);
					if(wRBP != null && wRBP.blockReceiver != null && wRBP.iBlockState != null)
					{
						if (!((Boolean)wRBP.iBlockState.getValue(POWERED)).booleanValue())
						{
							wRBP.iBlockState = wRBP.iBlockState.withProperty(POWERED, Boolean.valueOf(true));
							worldIn.setBlockState(wRBP.pos, wRBP.iBlockState);
							worldIn.notifyBlockOfStateChange(wRBP.pos, wRBP.blockReceiver);
							worldIn.updateBlockTick(wRBP.pos, wRBP.blockReceiver, 4, 0);
						}
					}
				} 
			}
            }
        }
    }

    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
    	
        if (!worldIn.isRemote)
        {
        	TileEntityWirelessRedstoneSender tile = null;
    		if(worldIn.getTileEntity(pos) instanceof TileEntityWirelessRedstoneSender)
    			tile = (TileEntityWirelessRedstoneSender)worldIn.getTileEntity(pos);
    		if (tile != null)
    		{
    			NBTTagCompound nBTTag = new NBTTagCompound();
    			tile.writeToNBT(nBTTag);
    			this.frequency = tile.getFrequency();
    		}
    		
            if (this.isOn && !worldIn.isBlockPowered(pos))
            {       	
    			
                worldIn.setBlockState(pos, WirelessRedstoneBlocks.wireless_redstone_sender.getDefaultState(), 2);
                
                
			ArrayList<WirelessRedstoneBlockPos> list = WirelessRedstoneHelper.findReceiver(this.frequency, worldIn, pos);
			if(list != null && list.size() > 0)
			{
				for(int i = 0; i < list.size(); i++)
				{
					WirelessRedstoneBlockPos wRBP = (WirelessRedstoneBlockPos)list.get(i);
					if(wRBP != null && wRBP.blockReceiver != null && wRBP.iBlockState != null)
						if (((Boolean)wRBP.iBlockState.getValue(POWERED)).booleanValue())
						{
							wRBP.iBlockState = wRBP.iBlockState.withProperty(POWERED, Boolean.valueOf(false));
							worldIn.setBlockState(wRBP.pos, wRBP.iBlockState);
							worldIn.notifyBlockOfStateChange(wRBP.pos, wRBP.blockReceiver);
							worldIn.updateBlockTick(wRBP.pos, wRBP.blockReceiver, 4, 0);
						}        
				}       	
			}

            }
            
        }
    }

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return Item.getItemFromBlock(WirelessRedstoneBlocks.wireless_redstone_sender);
    }

    @SideOnly(Side.CLIENT)
    public Item getItem(World worldIn, BlockPos pos)
    {
        return Item.getItemFromBlock(WirelessRedstoneBlocks.wireless_redstone_sender);
    }

    protected ItemStack createStackedBlock(IBlockState state)
    {
        return new ItemStack(WirelessRedstoneBlocks.wireless_redstone_sender);
    }
    
    /**
     * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
     */
    public int getRenderType()
    {
        return 3;
    }
    
    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
    	return this.getDefaultState().withProperty(POWERED, Boolean.valueOf((meta &  > 0));
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        int i = 0;
       
        if (((Boolean)state.getValue(POWERED)).booleanValue())
        {
            i |= 8;
        }

        return i;
    }
        
    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
    {
    	super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ);
    	    	
    		Minecraft.getMinecraft().thePlayer.sendChatMessage("onBlockActivated: Frequency: " + this.frequency); 
    		playerIn.openGui(WirelessRedstoneMod.instance, WirelessRedstoneGuiHandler.WIRELESS_REDSTONE_SENDER_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ());
    	     	
    	return true;
    }
        
    protected BlockState createBlockState()
    {
        return new BlockState(this, new IProperty[] {POWERED});
    }

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
	return new TileEntityWirelessRedstoneSender();
}

}

 

 

 

GuiWirelessRedstoneSender.class

 

 

package com.dot6.wireless_redstone.gui;

import java.awt.Color;
import java.io.IOException;

import com.dot6.wireless_redstone.tileentity.TileEntityWirelessRedstoneSender;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;

public class GuiWirelessRedstoneSender extends GuiScreen{

private GuiButton minus;
private GuiButton plus;
private GuiButton minus5;
private GuiButton plus5;
private GuiButton minus10;
private GuiButton plus10;
private GuiButton minus50;
private GuiButton plus50;
private GuiButton minus100;
private GuiButton plus100;
private GuiButton ok;
private int frequency = 0;
private boolean allaccess = false;
private World world = null;
private BlockPos bPos = null;
private String wirelessName;

//private static final ResourceLocation textureLocation = new ResourceLocation("fasttravelmod:textures/guitravelmark/travelblockgui.png");

public GuiWirelessRedstoneSender(EntityPlayer playerIn, World worldIn, int x, int y, int z)
{
	this.wirelessName = "Wireless Redstone Sender";
	this.world = worldIn;
	this.bPos = new BlockPos(x, y, z);	

	TileEntityWirelessRedstoneSender tileSender = null;
	if(this.world.getTileEntity(this.bPos) instanceof TileEntityWirelessRedstoneSender)
		tileSender = (TileEntityWirelessRedstoneSender)this.world.getTileEntity(this.bPos);

	if (tileSender != null)
	{
		NBTTagCompound nBTTag = new NBTTagCompound();
		tileSender.writeToNBT(nBTTag);
	    this.frequency = nBTTag.getInteger("FREQUENCY");
	    this.allaccess = nBTTag.getBoolean("ALLACCESS");
	}									
}

public void initGui()
{				
	this.buttonList.add(this.minus = new GuiButton(0, (this.width / 2) - 50, (this.height / 2), 30, 20, "-"));	
    this.buttonList.add(this.plus = new GuiButton(1, (this.width / 2) + 20, (this.height / 2), 30, 20, "+"));
    
    this.buttonList.add(this.minus5 = new GuiButton(2, (this.width / 2) - 80, (this.height / 2), 30, 20, "-5"));	
    this.buttonList.add(this.plus5 = new GuiButton(3, (this.width / 2) + 50, (this.height / 2), 30, 20, "+5"));
    
    this.buttonList.add(this.minus10 = new GuiButton(4, (this.width / 2) - 110, (this.height / 2), 30, 20, "-10"));	
    this.buttonList.add(this.plus10 = new GuiButton(5, (this.width / 2) + 80, (this.height / 2), 30, 20, "+10"));
    
    this.buttonList.add(this.minus50 = new GuiButton(6, (this.width / 2) - 140, (this.height / 2), 30, 20, "-50"));	
    this.buttonList.add(this.plus50 = new GuiButton(7, (this.width / 2) + 110, (this.height / 2), 30, 20, "+50"));
    
    this.buttonList.add(this.minus100 = new GuiButton(8, (this.width / 2) - 170, (this.height / 2), 30, 20, "-100"));	
    this.buttonList.add(this.plus100 = new GuiButton(9, (this.width / 2) + 140, (this.height / 2), 30, 20, "+100"));
    
    this.buttonList.add(this.ok = new GuiButton(10, (this.width / 2) + 140  , this.height - 65, 40, 20, "ok"));
    
}

private void doUpdateBlock()
{
	if((this.bPos != null))
	{
		TileEntityWirelessRedstoneSender tileSender = null;
		if(this.world.getTileEntity(this.bPos) instanceof TileEntityWirelessRedstoneSender)
			tileSender = (TileEntityWirelessRedstoneSender)this.world.getTileEntity(this.bPos);
		if (tileSender != null)
		{
		   NBTTagCompound nBTTag = new NBTTagCompound();
		   nBTTag.setInteger("FREQUENCY", this.frequency);	  
		   nBTTag.setBoolean("POWERED", false);	
		   nBTTag.setBoolean("ALLACCESS", this.allaccess);	
		   tileSender.readFromNBT(nBTTag);
		   tileSender.markDirty();
		}	
	}			
}

@Override
protected void actionPerformed(GuiButton button) throws IOException {
    if (this.frequency < 0)
    	this.frequency = 0;
    
    if(this.frequency > 999)
    	this.frequency = 999;
    
	if (button == this.minus) {	       
    	if(this.frequency >= 0)
    		this.frequency--;	    	
    }
    	    
    if (button == this.minus5) {	       
    	if(this.frequency -5 >= 0)
    		this.frequency = this.frequency-5;	    	
    }
    
    if (button == this.minus10) {	       
    	if(this.frequency -10 >= 0)
    		this.frequency = this.frequency-10;	    	
    }
    
    if (button == this.minus50) {	       
    	if(this.frequency -50 >= 0)
    		this.frequency = this.frequency-50;	    	
    }
    
    if (button == this.minus100) {	       
    	if(this.frequency -100 >= 0)
    		this.frequency = this.frequency-100;	    	
    }
    
    if (button == this.plus){	        
    	if(this.frequency <= 999)
    		this.frequency++;	    	
    }
    
    if (button == this.plus5){	        
    	if(this.frequency+5 <= 999)
    		this.frequency = this.frequency+5;
    }
    
    if (button == this.plus10){	        
    	if(this.frequency+10 <= 999)
    		this.frequency = this.frequency+10;
    }
    
    if (button == this.plus50){	        
    	if(this.frequency+50 <= 999)
    		this.frequency = this.frequency+50;
    }
    
    if (button == this.plus100){	        
    	if(this.frequency+100 <= 999)
    		this.frequency = this.frequency+100;
    }
    
    if(button == this.ok){
    	this.doUpdateBlock();
		//Main.packetHandler.sendToServer(...);
		this.mc.displayGuiScreen(null);
        if (this.mc.currentScreen == null)
            this.mc.setIngameFocus(); 
    }
    
}

@Override	
public boolean doesGuiPauseGame()
{
	return false;
}

@Override
public void drawScreen(int mouseX, int mouseY, float f)
{
	drawDefaultBackground();

	drawRect(20, 20, width - 20, height - 20, new Color(50, 170, 170, 70).getRGB());
        this.drawCenteredString(fontRendererObj, I18n.format(this.wirelessName), width / 2, 25, Color.WHITE.getRGB());
        this.drawCenteredString(fontRendererObj, I18n.format("Frequencey: "), (this.width / 2), (this.height /2) - 25, Color.WHITE.getRGB());
        this.drawCenteredString(fontRendererObj, I18n.format(String.valueOf(this.frequency)), (this.width / 2), (this.height /2) + 5, Color.WHITE.getRGB());
                
        // Call this methods super, as it draws buttons and stuff
        super.drawScreen(mouseX, mouseY, f);
                	
}

/*@Override
protected void mouseClicked(int par1, int par2, int par3) throws IOException
    {   
        super.mouseClicked(par1, par2, par3);
    }*/

/*@Override
public void updateScreen()
    {
        
        super.updateScreen();
    }*/

/*@Override
protected void keyTyped(char par1, int par2) throws IOException
{
	super.keyTyped(par1, par2);

}*/
}

 

 

 

TileEntityWirelessRedstoneSender.class

 

 

package com.dot6.wireless_redstone.tileentity;

import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;

public class TileEntityWirelessRedstoneSender extends TileEntity
{
public int frequency = 0;
public boolean powered = false;
public boolean allaccess = false;

    @Override
public void writeToNBT(NBTTagCompound par1)
{    	
    	super.writeToNBT(par1);
   
    	par1.setInteger("FREQUENCY", this.frequency);	  
    par1.setBoolean("POWERED", this.powered);	
    par1.setBoolean("ALLACCESS", this.allaccess);	
}

@Override
public void readFromNBT(NBTTagCompound par1)
{
   super.readFromNBT(par1);

   this.frequency = par1.getInteger("FREQUENCY");
   this.powered = par1.getBoolean("POWERED");
   this.allaccess = par1.getBoolean("ALLACCESS");
} 

public Packet getDescriptionPacket()
    {
        NBTTagCompound nBTTag = new NBTTagCompound();
        this.writeToNBT(nBTTag);
        return new S35PacketUpdateTileEntity(this.pos, 1, nBTTag);
    }

@Override
public void onDataPacket(net.minecraft.network.NetworkManager net, net.minecraft.network.play.server.S35PacketUpdateTileEntity pkt)
{
 readFromNBT(pkt.getNbtCompound());
}

public int getFrequency()
{
	return this.frequency;
}

public boolean getPowered()
{
	return this.powered;
}

public boolean getAllAccess()
{
	return this.allaccess;
}

public void setFrequency(int frequency)
{
	this.frequency = frequency;
}

public void setPowered(boolean powered)
{
	this.powered = powered;
}

public void setAllAccess(boolean allaccess)
{
	this.allaccess = allaccess;
}

@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
    {
	return (oldState.getBlock() != newState.getBlock());
    }

}

 

 

 

the sender and receiver classes are almost identical and is why I only posted just the sender classes I must state that both the sender and reciever classes are not saving data in the tile entity I'm thinking its just not updating client side but I'm not 100% sure either :(

Link to comment
Share on other sites

Hi

 

Have you seen this guide?

http://greyminecraftcoder.blogspot.com.au/2015/01/gui-containers.html

and this sample code

https://github.com/TheGreyGhost/MinecraftByExample

 

It sounds like your onDataPacket() and/or getDescriptionPacket() aren't right.  Try putting breakpoints or System.out.println() in there to see what's happening.

 

Cheers

  TGG

 

Link to comment
Share on other sites

Hi I seem to be having problems with Tile Entity. I have a block that extends BlockContainer...

Every thread that starts this way gets the same advice: Don't extend BlockContainer. Google these threads, then filter for the most recent month (because there are so many of them here). At least one is on page 1 of this very forum. Read D7's frequent advice on what Block methods to override instead of extending BlockContainer (or implementing ITileEntityProvider).

 

PS: Don't forget to register your TE. Whenever setting any data in your TE, mark it dirty so it is saved. Override (extend) the read and write NBT methods.

 

See how far you can get on that reading and advice. If you then face a crash, come back with a log (in spoiler frame). If it's just not doing what you expect, then step through at least once in a debugger before posting what's happening (versus what you expect).

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

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.