Jump to content

jh62

Members
  • Posts

    21
  • Joined

  • Last visited

Everything posted by jh62

  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!
  16. I forgot to mention that I'm using minecraft 1.4.7 because of some mods that are incompatible (or don't exists) for 1.6.x and I have a big world and I don't want to lose it. I cant find those interfaces you mentioned (readFromNBT, writeFromNBT) and what does ISBRH stand for? I'm a noob at Minecraft code yet...
  17. Hi. My problem is that when I create a block, it's metadata matches the one from the material it's been made, but when I reset the game, that information is gone. I followed the metadaba based subblocks tutorial and the block and item i followed another tutorial: Block: package pablisMod.blocks; import java.util.List; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLiving; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import pablisMod.entities.TableOneEntity; import pablisMod.items.TableOneItem; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class TableOneBlock extends BlockContainer { public static int id; public TableOneBlock(int id) { super(id, Material.wood); this.id = id; this.setBlockName("Table"); this.setCreativeTab(CreativeTabs.tabDecorations); this.setStepSound(Block.soundWoodFootstep); this.setHardness(0.5F); this.setTextureFile("/pablisMod/textures/TableOneIcon.png"); this.setRequiresSelfNotify(); // absolutely needed } public int quantityDropped(Random par1Random) { return 1; } @Override public int getRenderType() { return -1; } @Override public int getBlockTextureFromSideAndMetadata (int side, int metadata) { return 16 + metadata; } @Override public TileEntity createNewTileEntity(World var1) { return null; } @Override public TileEntity createTileEntity(World world, int metadata) { return new TableOneEntity(); } @Override public boolean renderAsNormalBlock() { return false; } @Override public boolean isBlockSolid(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5) { return super.isBlockSolid(par1iBlockAccess, par2, par3, par4, par5); } @Override public boolean isOpaqueCube() { return false; } @Override public boolean canPlaceTorchOnTop(World world, int x, int y, int z) { return super.canPlaceTorchOnTop(world, x, y, z); } @Override public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l) { return false; } @SideOnly(Side.CLIENT) public void getSubBlocks(int par1, CreativeTabs tab, List subItems) { for (int ix = 0; ix < 4; ix++) { subItems.add(new ItemStack(this, 1, ix)); } } @Override public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving) { int var6 = MathHelper .floor_double((double) (par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; switch (var6) { case 0: par1World.setBlockMetadataWithNotify(par2, par3, par4, 2); break; case 1: par1World.setBlockMetadataWithNotify(par2, par3, par4, 5); break; case 2: par1World.setBlockMetadataWithNotify(par2, par3, par4, 4); break; case 3: par1World.setBlockMetadataWithNotify(par2, par3, par4, 3); break; } } public static Block registerBlock(int id) { Block m_fieldName = new TableOneBlock(id); GameRegistry.registerBlock(m_fieldName, TableOneItem.class, "TableOneItem"); GameRegistry.registerTileEntity(TableOneEntity.class, "TableOneEntity"); ItemStack stack = new ItemStack(m_fieldName, 1, 0); LanguageRegistry.addName(stack, "Oak Table"); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack( Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1, 0)); stack = new ItemStack(m_fieldName, 1, 1); LanguageRegistry.addName(stack, "Spruce Table"); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack( Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1, 1)); stack = new ItemStack(m_fieldName, 1, 2); LanguageRegistry.addName(stack, "Birch Table"); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack( Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1, 2)); stack = new ItemStack(m_fieldName, 1, 3); LanguageRegistry.addName(stack, "Jungle Table"); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack( Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1, 3)); return m_fieldName; } } Item: package pablisMod.items; import java.util.List; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; public class TableOneItem extends ItemBlock { private static final String[] subTypes = {"Oak ", "Spruce ", "Birch ", "Jungle "}; public TableOneItem(int id) { super(id); maxStackSize = 16; setCreativeTab(CreativeTabs.tabDecorations); setItemName("Table"); setHasSubtypes(true); } public static String[] getSubtypes() { return subTypes; } @Override public int getMetadata (int damageValue) { return damageValue; } @Override public String getItemNameIS(ItemStack par1ItemStack) { return subTypes[par1ItemStack.getItemDamage()] + getItemName(); } } Renderer (The renderer doesn't use the metadata yet because is always changing): package pablisMod.renderers; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; import pablisMod.models.TableOneModel; public class TableOneRenderer extends TileEntitySpecialRenderer { private TableOneModel model; private String texture; public TableOneRenderer() { model = new TableOneModel(); texture = "/pablisMod/textures/SpruceTableOne.png"; } int ang = 0; public void renderTileEntityAt(TileEntity entity, double d, double d1, double d2, float f) { int metadata = entity.getBlockMetadata(); int rotationAngle = 0; switch(metadata % 4){ case 0: rotationAngle = 0; break; case 1: rotationAngle = 90; break; case 2: rotationAngle = 180; break; case 3: rotationAngle = 270; break; } int i = 0; if (entity.worldObj != null) { i = (entity.worldObj.getBlockMetadata(entity.xCoord, entity.yCoord, entity.zCoord)); } GL11.glPushMatrix(); GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F); GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F); GL11.glScalef(1.0F, -1F, -1F); bindTextureByName(texture); model.renderModel(0.0625F); GL11.glPopMatrix(); } } How can I save the metadata of the block and mantain the same number on every world load.
  18. Here's a thing a don't understand: I followed a tutorial I've found (Im using minecraft 1.4.7 because I have some mods that are not compatible with newer versions yet) and the tutorial said this: - Create a block as a BlockContainer. - Create a ItemBlock for that Block. - Register everything (Block, Item, Entity, Recipe). - Bind a special renderer in ClientProxy with ClientRegistry.bindTileEntitySpecialRenderer... Now, my custom renderer (as in the tutorial) it renders the following: public void renderTileEntityAt(TileEntity tile, double d, double d1, double d2, float f) So when I convert that TileEntity to a block, i get it's properties, but I cannot find a way to get the dammageValue when the ItemStack creates a new item (it creates an item and if it is Oak is assigns a dammageValue of 0, spruce 1, birch 2, jungle 3), so I need to get that data from the Block to bind different textures to the model I'm trying to render so if it is a OakTable it displays as Oak, etc... /* Creado con MCObjectCreator 1.5 (Aug-2013) por PDCL*/ package pablisMod.items; import pablisMod.blocks.TableOneBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockCloth; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.util.DamageSource; import net.minecraft.world.World; public class TableOneItem extends ItemBlock { private final static String[] subNames = { "oak", "spruce", "birch", "jungle" }; public TableOneItem(int id) { super(id); maxStackSize = 64; setCreativeTab(CreativeTabs.tabDecorations); setItemName("Table"); setHasSubtypes(true); } @Override public int getMetadata (int damageValue) { return damageValue; } @Override public String getItemNameIS(ItemStack itemstack) { return getItemName() + "." + subNames[itemstack.getItemDamage()]; } } /* Creado con MCObjectCreator 1.5 (Aug-2013) por PDCL*/ package pablisMod.blocks; import java.util.List; import java.util.Random; import pablisMod.entities.TableOneEntity; import pablisMod.items.TableOneItem; import pablisMod.renderers.GenericRenderer; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockWood; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class TableOneBlock extends BlockContainer { public static int id; public int metaColor; public TableOneBlock(int id) { super(id, Material.wood); this.id = id; this.setBlockName("Table"); this.setCreativeTab(CreativeTabs.tabDecorations); this.setStepSound(Block.soundWoodFootstep); this.setHardness(0.5F); this.setTextureFile("/pablisMod/textures/TableOneIcon.png"); this.setBounds(); this.setRequiresSelfNotify(); // absolutely needed } private void setBounds() { this.setBlockBounds(0.0F, 0.0F, 0.0F, 2.5F, 2.5F, 2.5F); } public int quantityDropped(Random par1Random) { return 1; } @Override public int getRenderType() { return -1; } @Override public TileEntity createNewTileEntity(World var1) { return new TableOneEntity(); } @Override public boolean renderAsNormalBlock() { return false; } @Override public boolean isOpaqueCube() { return false; } @Override public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l) { return false; } @SideOnly(Side.CLIENT) public void getSubBlocks(int par1, CreativeTabs tab, List subItems) { for (int ix = 0; ix < 4; ix++) { subItems.add(new ItemStack(this, 1, ix)); } } @Override public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving) { int var6 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; switch(var6){ case 0: par1World.setBlockMetadataWithNotify(par2, par3, par4, 2); break; case 1: par1World.setBlockMetadataWithNotify(par2, par3, par4, 5); break; case 2: par1World.setBlockMetadataWithNotify(par2, par3, par4, 4); break; case 3: par1World.setBlockMetadataWithNotify(par2, par3, par4, 3); break; } } public static Block registerBlock(int id){ Block m_fieldName = new TableOneBlock(id); GameRegistry.registerBlock(m_fieldName, TableOneItem.class, "TableOneItem"); GameRegistry.registerTileEntity(TableOneEntity.class, "TableOneEntity"); ItemStack stack; stack = new ItemStack(m_fieldName, 1, 0); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack(Item.stick, 1, 0) , 'y', new ItemStack(Block.woodSingleSlab, 1, 0) ); LanguageRegistry.addName(stack, "Oak Table"); stack = new ItemStack(m_fieldName, 1, 1); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack(Item.stick, 1, 0) , 'y', new ItemStack(Block.woodSingleSlab, 1, 1) ); LanguageRegistry.addName(stack, "Spruce Table"); stack = new ItemStack(m_fieldName, 1, 2); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack(Item.stick, 1, 0) , 'y', new ItemStack(Block.woodSingleSlab, 1, 2) ); LanguageRegistry.addName(stack, "Birch Table"); stack = new ItemStack(m_fieldName, 1, 3); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack(Item.stick, 1, 0) , 'y', new ItemStack(Block.woodSingleSlab, 1, 3) ); LanguageRegistry.addName(stack, "Jungle Table"); return m_fieldName; } } /* Creado con MCObjectCreator 1.5 (Aug-2013) por PDCL*/ package pablisMod.renderers; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; import pablisMod.blocks.TableOneBlock; import pablisMod.entities.TableOneEntity; import pablisMod.models.*; public class GenericRenderer extends TileEntitySpecialRenderer { private CustomModel model; private TileEntity entity; private String texture; public GenericRenderer(int type) { switch (type) { case 0: model = new OakWoodChairModel(); texture = "/pablisMod/textures/ChairModel.png"; break; case 1: model = new SofaModel(); texture = "/pablisMod/textures/SofaModel.png"; break; case 2: model = new CenterCounterModel(); texture = "/pablisMod/textures/Counter.png"; break; case 3: model = new SandClockModel(); texture = "/pablisMod/textures/SandClock.png"; break; case 4: case 5: model = type == 4 ? new BirchStairRailLeftModel() : new BirchStairRailRightModel(); texture = "/pablisMod/textures/BirchStairRail.png"; break; case 6: case 7: model = type == 4 ? new OakStairRailLeftModel() : new OakStairRailRightModel(); texture = "/pablisMod/textures/OakStairRail.png"; break; case 8: model = new BirchWindowFrameModel(); texture = "/pablisMod/textures/BirchWindowFrame.png"; break; case 9: model = new OakWindowFrameModel(); texture = "/pablisMod/textures/OakWindowFrame.png"; break; case 10: model = new TableOneModel(); texture = "/pablisMod/textures/OakTableOne.png"; break; case 11: model = new BigClockModel(); texture = "/pablisMod/textures/BigClock.png"; break; case 12: model = new ToiletModel(); texture = "/pablisMod/textures/Toilet.png"; break; } } // where and what to render public void renderTileEntityAt(TileEntity tile, double d, double d1, double d2, float f) { int i = 0; // a regular int, with a zero. more on this below entity = tile; /* HOW TO DO THIS switch(entity data to bind different textures){ } */ int metadata = entity.getBlockMetadata(); bindTextureByName(texture); int rotationAngle = 0; if (metadata % 4 == 0) { rotationAngle = 0; } if (metadata % 4 == 1) { rotationAngle = 90; } if (metadata % 4 == 2) { rotationAngle = 180; } if (metadata % 4 == 3) { rotationAngle = 270; } if (tile.worldObj != null) // to tell the world that your object is // placed. { i = (tile.worldObj.getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord)); // to tell the game it needs to pick up // metadata from your block } GL11.glPushMatrix(); // start GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F); // size GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F); // change the first 0 // in like 90 to // make it rotate 90 degrees. GL11.glScalef(1.0F, -1F, -1F); // to make your Block have a normal // positioning. comment out to see what // happens model.renderModel(0.0625F); // renders and 0.0625F is exactly 1/16. // every Block has 16 entitys/pixels. if you // make the number 1, every pixel will be as // big as a block. make it 0.03125 and your // Block will be half as big as a normal // one. GL11.glPopMatrix(); // end } } ClientRegistry.bindTileEntitySpecialRenderer(TableOneEntity.class, new GenericRenderer(MODEL_TABLEONE));
  19. Yes. I don't understand most of it. There is a lot of code in different classes and this is my first time modding for this game, so is kinda confussing. I saw that items have ItemRenderer as a renderer? I'm using TileEntityRenderer because ClientRegistry only has a method that accepts a TileEntityRenderer... I don't know...
  20. Somebody???
  21. Hi. I'm new to this minecraft modding thing. I just want to know how do you change a block texture depending on the material you used to make the block, like wood or wool. I already did what the metadata subblock forge tutorial says, but I don't know how to get the that data to the custom renderer I have for my custom models. I made a table that uses the 4 different woods in the game and i register them properly and everything, but I don't understand how using metadata or something like that you can change it's texture according to it's material in the renderer class.
×
×
  • Create New...

Important Information

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