I've been trying to modify vanilla minecraft things with out actually changing the base classes and compromising compatibility how can i do such a thing
Bedrock uses the setUnbreakable method anway so what you're trying to do won't work. It is marked as final so you cannot modify it unless you change the declaration and instantiation in Block. I don't think that AccessTransformers work for this purpose either.
Meh, your NBT-methods never get called because your TileEntity never gets created, it's that easy. You use createNewTileEntity in a class that extends Block but the method is actually from BlockContainer. So you have to switch Block to BlockContainer or find another way to create your TileEntity on creation of your block.
(You would've seen that if you'd use @Override btw, it gives you an error everytime you try to use a method from a parent-class that isn't actually there.)
Try to use System.err.println(); instead, does it still print out in the console?
As for your actual problem, try to give channel a value in the constructor, and use an if statement in readEntityFromNBT like this:
if (par1NBTTagCompound.hasKey("channel")) {
System.err.println("channel exists in NBT");
this.channel = par1NBTTagCompound.getInteger("channel");
}
Does it print channel exists in NBT?
The methods aren't called at all so this will not show anything anyway. I did test it just to make sure but nothing is printed at all, not even from prints in the latest code I posted on the previous page.
Techne doesn't make the animation code for you. Get the setRotationAngles from ModelBiped or another Vanilla mob model class and change the fields to suit yours.
Here's the rest of my code, there would be a problem somewhere else no doubt.
Registry:
package techguy.mods.cctv.common;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid="techguy543CCTV", name="TechGuy's CCTV", version="[MC1.4.7] v0.0.1")
@NetworkMod
(
clientSideRequired = true,
serverSideRequired = false,
channels = {"techguy_cctv"},
packetHandler = CCTVPacketHandler.class
)
public class CCTVMainRegistry
{
public static int cameraID = 150;
public static int monitorID = 151;
public static final Block camera = new CCTVBlockCamera(cameraID, 1).setBlockName("cctvCamera").setHardness(1.3F).setCreativeTab(CreativeTabs.tabDecorations);
public static final Item monitor = new CCTVItemMonitor(monitorID, CCTVEntityMonitor.class).setItemName("cctvMonitor").setCreativeTab(CreativeTabs.tabDecorations).setIconIndex(0);
@PreInit
public void preInit(FMLPreInitializationEvent evt)
{
/*Configuration config = new Configuration(evt.getSuggestedConfigurationFile());
config.load();
cameraID = config.getBlock(Configuration.CATEGORY_BLOCK, "Camera", 3500).getInt();
config.save();*/
}
@Init
public void init(FMLInitializationEvent evt)
{
GameRegistry.registerTileEntity(CCTVTileEntityCamera.class, "CCTVCameraEntity");
GameRegistry.registerBlock(camera, "cctvCamera");
LanguageRegistry.addName(camera, "CCTV Camera");
LanguageRegistry.addName(monitor, "CCTV Monitor");
CCTVCommonProxy.registerRenderInformation();
}
@PostInit
public void postInit(FMLPostInitializationEvent evt)
{
}
}
Block:
package techguy.mods.cctv.common;
import techguy.mods.cctv.client.CCTVGuiCamera;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class CCTVBlockCamera extends Block
{
public int channel;
public CCTVBlockCamera(int i, int j)
{
super(i, j, Material.wood);
}
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
Minecraft.getMinecraft().displayGuiScreen(new CCTVGuiCamera(par1World, par5EntityPlayer, Minecraft.getMinecraft()));
TileEntity tile1 = Minecraft.getMinecraft().getIntegratedServer().worldServers[par5EntityPlayer.dimension].getBlockTileEntity(par2, par3, par4);
return true;
}
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)
{
int l = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
switch (l)
{
case 0:
world.setBlockMetadataWithNotify(i, j, k, 2);
break;
case 1:
world.setBlockMetadataWithNotify(i, j, k, 5);
break;
case 2:
world.setBlockMetadataWithNotify(i, j, k, 3);
break;
case 3:
world.setBlockMetadataWithNotify(i, j, k, 4);
break;
}
}
public int getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
return l != iblockaccess.getBlockMetadata(i, j, k) ? blockIndexInTexture : 0;
}
/**
* Returns the block texture based on the side being looked at. Args: side
*/
public int getBlockTextureFromSide(int i)
{
return i != 3 ? blockIndexInTexture : 0;
}
public TileEntity createNewTileEntity(World par1World)
{
return new CCTVTileEntityCamera();
}
public String getTextureFile()
{
return "/CCTV/terrain.png";
}
}
TileEntity:
package techguy.mods.cctv.common;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;
public class CCTVTileEntityCamera extends TileEntity
{
public int channel;
public CCTVTileEntityCamera()
{
}
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setInteger("channel", this.channel);
System.out.println("writing NBT");
}
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
this.channel = par1NBTTagCompound.getInteger("channel");
System.out.println("reading NBT");
}
public Packet getDescriptionPacket() //Not sure if I need this
{
NBTTagCompound var1 = new NBTTagCompound();
this.writeToNBT(var1);
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 2, var1);
}
public void updateEntity()
{
System.out.println("updateTE");
}
}
Gui:
package techguy.mods.cctv.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import techguy.mods.cctv.common.CCTVTileEntityCamera;
public class CCTVGuiCamera extends GuiScreen
{
CCTVTileEntityCamera tile = new CCTVTileEntityCamera();
private Minecraft mc;
private World world;
private EntityPlayer entityPlayer;
public CCTVGuiCamera(World world1, EntityPlayer entityPlayer1, Minecraft minecraft)
{
world = world1;
entityPlayer = entityPlayer1;
mc = minecraft;
}
public GuiButton channelPlusOne;
public GuiButton channelPlusTen;
public GuiButton channelPlusHundred;
public GuiButton channelSubtractOne;
public GuiButton channelSubtractTen;
public GuiButton channelSubtractHundred;
public void initGui()
{
controlList.clear();
channelPlusOne = new GuiButton(0, width / 2 + 3, height / 2 - 20, 25, 20, "+");
controlList.add(channelPlusOne);
channelPlusTen = new GuiButton(1, width / 2 + 29, height / 2 - 20, 27, 20, "+10");
controlList.add(channelPlusTen);
channelPlusHundred = new GuiButton(2, width / 2 + 57, height / 2 - 20, 31, 20, "+100");
controlList.add(channelPlusHundred);
channelSubtractOne = new GuiButton(3, width / 2 - 28, height / 2 - 20, 25, 20, "-");
controlList.add(channelSubtractOne);
channelSubtractTen = new GuiButton(4, width / 2 - 56, height / 2 - 20, 27, 20, "-10");
controlList.add(channelSubtractTen);
channelSubtractHundred = new GuiButton(5, width / 2 - 88, height / 2 - 20, 31, 20, "-100");
controlList.add(channelSubtractHundred);
}
public void updateScreen()
{
if(tile.channel < 0)
tile.channel = 0;
}
protected void actionPerformed(GuiButton guibutton)
{
if (guibutton.id == 0)
{
tile.channel++;
}
if (guibutton.id == 1)
{
for( int l = 0; l < 10; l++)
{
tile.channel++;
}
}
if (guibutton.id == 2)
{
for( int l = 0; l < 100; l++)
{
tile.channel++;
}
}
if (guibutton.id == 3)
{
tile.channel--;
}
if (guibutton.id == 4)
{
for( int l = 0; l < 10; l++)
{
tile.channel--;
}
}
if (guibutton.id == 5)
{
for( int l = 0; l < 100; l++)
{
tile.channel--;
}
}
}
public boolean doesGuiPauseGame()
{
return false;
}
public void drawScreen(int i, int j, float f)
{
mc.renderEngine.bindTexture(mc.renderEngine.getTexture("/CCTV/cameraGui.png"));
drawTexturedModalRect(width / 2 - 100, height / 2 - 64, 0, 0, 256, 177);
drawCenteredString(fontRenderer, "CCTV Camera", width / 2, height / 2 - 55, 0xffffff);
drawCenteredString(fontRenderer, "Channel: " + tile.channel, width / 2, height / 2 - 40, 0xffffff);
for( int l = 0; l < controlList.size(); l++)
{
GuiButton guibutton = (GuiButton)controlList.get(l);
guibutton.drawButton(mc, i, j);
}
}
}
These NBT methods in TileEntity are usually not called if the tile has not been registered. Are you using GameRegistry.registerTileEntity in your load method. If you have make sure that updateEntity is been called in your tile. And also:
Make sure you have createNewTileEntity in your block file as well
Also need to be syncing your data from client to server using Container.class
It is registered and createNewTileEntity is being used. I'll give updateEntity a go but I don't specifically require its use. I'm not using a Container.
I added some prints to my NBT methods and it seems they are never even called. Do you have to call them or is that done automatically in another class? They should just call from super shouldn't they?
0
Depends on what you are trying to change...
1
0
Or you didn't know there was a difference between the two.
0
0
0
Forgot about that... Thanks
0
The methods aren't called at all so this will not show anything anyway. I did test it just to make sure but nothing is printed at all, not even from prints in the latest code I posted on the previous page.
0
I'll give it a go now. The ids are not in use till the 1.5 update. They're only really testing ids anyway, no plan to actually use them in a release.
Edit: Adding that method didn't work.
0
0
Registry:
Block:
TileEntity:
Gui:
0
25565 is the default port that the server uses. It isn't the IP address.
0
0
It is registered and createNewTileEntity is being used. I'll give updateEntity a go but I don't specifically require its use. I'm not using a Container.
0
0