Jump to content

jh62

Members
  • Posts

    21
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

jh62's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Hi. I created a block with a tile entity and in the custom renderer i cannot make it rotate like say, a chest, that always faces the player in the right direction. Is there a simple way to do this, as getBlockMetadata() returns always 0.
  2. Thanks. That's what I thougth and I tried that also, so I must be missunderstanding something or doing something wrong. The goal of the "InUse" boolean is to trigger an animation on the model. In the renderer i read the tileentity's inUse boolean and use it to rotate a cube. Here is some of the code: BlockTableSaw.java: @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return true; } ItemStack stack = playerIn.getHeldItem(); if (stack == null) { return true; } Item item = stack.getItem(); Block block = Block.getBlockFromItem(item); ItemStack drop = null; if (block != null) { if (block.getMaterial() == Material.wood) { drop = new ItemStack(Blocks.log, stack.stackSize); } } else { drop = new ItemStack(Items.stick, stack.stackSize * 2); } TileEntityTableSaw entity = (TileEntityTableSaw) worldIn .getTileEntity(pos); if (!entity.isInUse()) { playerIn.destroyCurrentEquippedItem(); entity.use(worldIn, playerIn, drop); } else { playerIn.addChatMessage(new ChatComponentText("That is beign used!")); } return true; } TileEntityTableSaw.java: package com.pablismod.tileentity; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; 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 TileEntityTableSaw extends TileEntity { private Timer t; private boolean inUse = false; @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); inUse = compound.getBoolean("inUse"); } @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setBoolean("inUse", isInUse()); } public boolean isInUse() { return t != null && t.isRunning(); } public void use(World worldIn, EntityPlayer player, ItemStack stack) { if (t != null && t.isRunning()) { return; } inUse = true; worldIn.markBlockForUpdate(pos); final World world = worldIn; final EntityPlayer p = player; final ItemStack s = stack; t = new Timer(3000, new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { BlockPos pos = TileEntityTableSaw.this.getPos(); Entity e = new EntityItem(world, pos.getX(), pos.getY() + 1.2f, pos.getZ(), s); world.spawnEntityInWorld(e); inUse = false; world.markBlockForUpdate(TileEntityTableSaw.this.getPos()); } }); t.setRepeats(false); t.start(); } @Override public Packet getDescriptionPacket() { NBTTagCompound tag = new NBTTagCompound(); this.writeToNBT(tag); return new S35PacketUpdateTileEntity(this.getPos(), 0, tag); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.getNbtCompound()); } } Don't mind Im using the javax.swing.Timer. The code is temporary and it works, because if I try to use the table when is in use, it wont let me... just the animation wont play.
  3. I read that part, but where in all that code i write the value of my custom field? I only see two methods that are overriden in TileEntity and then the block is mark for update. Should I do something like this? @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return true; } TileEntityTableSaw entity = (TileEntityTableSaw) worldIn .getTileEntity(pos); if (!entity.isInUse()) { entity.use(worldIn); S35PacketUpdateTileEntity packet = (S35PacketUpdateTileEntity) entity .getDescriptionPacket(); NBTTagCompound tag = packet.getNbtCompound(); tag.setBoolean("inUse", true); entity.onDataPacket(null, packet); worldIn.markBlockForUpdate(pos); } else { playerIn.addChatMessage(new ChatComponentText( "Can't use is it right now!")); } return true; }
  4. I read this tutorial (http://cazzar.net/tutorials/minecraft/Tile-Entity-Updates-The-Quick-and-Dirty-Method/) and theres something I don't understand: Where and how do I send my data just overriding this two methods in TileEntity? @Override public Packet getDescriptionPacket() { NBTTagCompound tag = new NBTTagCompound(); writeToNBT(tag); return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, tag); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { readFromNBT(pkt.func_148857_g()); } I have a field called "InUse" that it should change whenever a player activates a block, but I don't understand how to send it through the block event. I tried onBlockActivated() getting the description Packet and the NBTTag, write the value, but then I don't know how to send it. What Im I Missing?
  5. Hi, I have this code: public abstract class BaseWeapon extends ItemSword { public BaseWeapon(ToolMaterial material) { super(material); } @Override public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) { if (!entity.isDead) { player.worldObj.playSoundAtEntity(player, Reference.MOD_ID + ":" + this.getUnlocalizedName().substring(5) + "_hit", 1.0f, 1.0f); } return super.onLeftClickEntity(stack, player, entity); } } If i run a test server with no mods and connect to it, I hear the sounds playing, but when I use my normal minecraft client/server wich has a lot of mods, the sounds are no longer heard (or played?). Is this a known thing or do you have any suggestion as how to resolve it other than try removing mods until i find the culprit? This is a list of my mods: 1.8 animalsplus-1.3.jar antiqueatlas-4.0.1a-1.7.2.jar BackTools-5.1.0.jar BaseMetals-1.4.0.jar Chameleon-1.8-0.1.0.jar CodeChickenCore-1.8-1.0.5.34-universal.jar CrafableHorseArmour 1.2.jar decorationmegapack-1.18-1.8-1446.jar ExpTranslation-1.0.0-1.8.7.jar Fire's Clay Spawn 2.1.2.0.jar iChunUtil-5.4.0.jar justbackpacks-mc1.8-1.0.jar LunatriusCore-1.8-1.1.2.28-universal.jar MobAmputation-5.0.0.jar MoreEnchantments-1.8-1.3.2.1.jar Morpheus-1.8-2.0.41.jar MouseTweaks-2.5.0-mc1.8.jar MrCrayfishFurnitureModv3.4.8-build1(1..jar NotEnoughItems-1.8-1.0.5.82-universal.jar oldguns-1.3.0_x32.jar pablismod-1.0.jar parachutemod-1.8.0-3.1.2-96.jar redstonepaste-mc1.8-1.7.1.jar SmeltCycle-2.0.jar StalkerCreepers-1.8.jar StorageDrawers-1.8-2.1.8.jar [1.8] ChickenShed (v1.2.0).jar [1.8]ArmorStatusHUD-client-1.29.jar [1.8]bspkrsCore-universal-7.01.jar [1.8]DirectionHUD-client-1.24.jar
  6. I don't know... it seems to be working now... It's weird because sometimes works right away, sometimes you have to use the item a few times in order for the code to work properly: boolean flushed = false; long start = System.currentTimeMillis(); ItemStack drop; @Override public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if (drop == null) { if (par5EntityPlayer.getCurrentEquippedItem() == null) { System.out.println("DROP NULL"); par5EntityPlayer.sendChatToPlayer("DROP NULL"); return true; } } if (par5EntityPlayer.worldObj.isRemote) { System.out.println("CLIENT"); par5EntityPlayer.sendChatToPlayer("CLIENT"); return true; } long end = System.currentTimeMillis(); if (!flushed) { flushed = true; drop = par5EntityPlayer.getCurrentEquippedItem().copy(); par5EntityPlayer.destroyCurrentEquippedItem(); if (!par5EntityPlayer.worldObj.isRemote) par1World.playSoundEffect(par2, par3, par4, "pablisMod.flush", 1.0f, 1.0f); } else { if (end - start > 3000) { flushed = false; start = System.currentTimeMillis(); drop = null; } else { if (drop != null) { par5EntityPlayer.entityDropItem(drop, 1); drop = null; System.out.println("DROPPING"); par5EntityPlayer.sendChatToPlayer("DROPPING"); } par1World.playSoundEffect(par2, par3, par4, "random.click", 0.3F, 0.6F); } } return true; } and I noticed that if I use dropItem instead of EntityDropItem the drop never drops...
  7. Hello. I've searched through the forum, but the search engine is terrible (or is just messed up in my browser i don't know), but the thing is that i couldn't find a proper answer. I've managed to drop an item at the player's feet with par5EntityPlayer.dropItem()...., but if I play on an actual dedicated server the item is duplicated and I can't pick it up, I've tried use isremote && !isremote but i can't pick the item. It seems out of sync or something. How would I go about dropping an item in a dedicated server??? NOTE: I'm using minecraft 1.4.7
  8. And Im not blaming the TE in general. Obviously they work. Im blaming my Block and my TE and some of the tutorials that you find in the internet. Okey, after overriding the hasTileEntity(int metadata) instead of the other it seems to work now. What is the pourpose of the other method then???
  9. Sorry, I forgot to mention: I'm using 1.4.7 beacuse some mods i have are not compatible with 1.6.2.
  10. Sorry if some code is messed up. I don't have the *.java files right now. Im using JD-GUI to view the classes I have uploaded. Mod class: @Mod(modid="pablisMod", name="Pablis Mods", version="0.1") @NetworkMod(clientSideRequired=true, serverSideRequired=false) public class PablisMod { private static int id = 3096; @Mod.Instance("PablisMod") public static PablisMod instance; @SidedProxy(clientSide="pablisMod.ClientProxy", serverSide="pablisMod.CommonProxy") public static CommonProxy proxy; @Mod.PreInit public void preInit(FMLPreInitializationEvent event) { } @Mod.Init public void load(FMLInitializationEvent event) { --> This is a static method in every block to register itself : It's in the block class. <--- BigClockBlock.registerBlock(getNextID()); proxy.registerRenderers(); } @Mod.PostInit public void postInit(FMLPostInitializationEvent event) { } private static int getNextID() { return id++; } } Client Proxy: public class ClientProxy extends CommonProxy { public void registerRenderers() { MinecraftForgeClient.preloadTexture("/pablisMod/textures/BigClock.png"); MinecraftForgeClient.preloadTexture("/pablisMod/textures/BigClockIcon.png"); ClientRegistry.bindTileEntitySpecialRenderer(BigClockEntity.class, new BigClockRenderer()); } } The Block: (I wiped out the unninportant part) public class BigClockBlock extends akb { public static int id; public BigClockBlock(int id) { super(id, agi.d); id = id; b("Big Clock"); a(tj.c); a(amq.e); setTextureFile("/pablisMod/textures/BigClockIcon.png"); c(0.5F); r(); } public TileEntity createTileEntity(World world, int metadata) { return new BigClockEntity(); } public boolean hasTileEntity(){ return true; } public void OnBlockPlacedBy(yc par1World, int par2, int par3, int par4, md par5EntityLiving) { BigClockEntity entity = par1World.getBlockTileEntity( par2, par3, par4); entity.somedata = par2; } public static Block registerBlock(int id) { Block m_fieldName = new BigClockBlock(id); LanguageRegistry.addName(m_fieldName, "Big Clock"); GameRegistry.registerBlock(m_fieldName, BigClockItem.class, "BigClockItem"); GameRegistry.addRecipe(new ItemStack(m_fieldName), new Object[] { "yyy", "xzx", "xxx", Character.valueOf('x'), new ur(amq.M, 1, 1), Character.valueOf('y'), new ur(amq.bR, 1, 1), Character.valueOf('z'), new ur(up.aQ, 1, 0) }); GameRegistry.registerTileEntity(BigClockEntity.class, "BigClockEntity"); return m_fieldName; } } TileEntity: public class BigClockEntity extends TileEntity{ public int somedata = 0; @Override public void writeToNBT(NBTTagCompound par1) { super.writeToNBT(par1); par1.setInteger("somedata ", somedata ); } @Override public void readFromNBT(NBTTagCompound par1) { super.readFromNBT(par1); this.somedata = par1.getInteger("somedata "); } }
  11. Yes. Everything is registred. As I said: on every world reload, the block creates a new TileEntity, so the previous one is obviously overwritten. I don't know how to retrieve the old one, if that's possible...
  12. Hi. I've followed the tutorial from the forge's tutorial page about NBT, but here's what happens: I have a block with a tile entity. I save to that entity some data, but everytime the world reloads the entity get's overwritten by: @Override public TileEntity createTileEntity(World world, int metadata){ return new BlockTileEntity(); } ... inside the block. I see through console prints that the TileEntity is loading saving the current values properly, but the block in question is not bound anymore to that TileEntity. What am I missing?
  13. Nevermind this. It was because I followed some tutorial and at some point it was changing the block's metadata. I'm able now to render the texture based on metadata.
  14. Now, here's another thing I don't understand and it's the final thing i need to grasp: I've found the Basic Tile Entity tutorial on the forge tutorials page and it says to do the following: @Override public TileEntity createTileEntity(World world, int metadata) { try { TableOneEntity entity = new TableOneEntity(); entity.setTextureID(metadata); //System.out.println("metadata " + metadata); return entity; } catch (Exception e) { throw new RuntimeException(e); } } That's fine. I can save the block's TileEntity with the metadata from the block, but whenever the world restarts, the entity get's overwritten by a new one and the metadata changes to some other thing and I can't get the old TileEntity from the block instead of creating a new one with the params provided by this method. How do you do it usually?
  15. Yeah, I imagined that and found it already. Thanks!
×
×
  • Create New...

Important Information

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