Jump to content

candlemaster

Members
  • Posts

    9
  • Joined

  • Last visited

Everything posted by candlemaster

  1. I'm making a "grass cover" block, which is meant to mimic the behavior of snow (except melting) but look like grass. So far I have the snow behavior working perfectly, but the grass shading has problem to be a bit challenging. The top of the block uses the correct color, but the sides are all completely gray! What am I doing wrong? Here's the source code for the block: package hvh.mod.coverblocks; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Icon; import net.minecraft.world.ColorizerFoliage; import net.minecraft.world.ColorizerGrass; import net.minecraft.world.EnumSkyBlock; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class BlockGrassCover extends Block { public BlockGrassCover(int id) { super(id, Material.grass); setHardness(0.3f); setStepSound(soundGrassFootstep); setCreativeTab(CreativeTabs.tabDecorations); } /** * When this method is called, your block should register all the icons it needs with the given IconRegister. This * is the only chance you get to register icons. */ @SideOnly(Side.CLIENT) public void registerIcons(IconRegister par1IconRegister) { this.blockIcon = par1IconRegister.registerIcon("grass_top"); } /** * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been * cleared to be reused) */ public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { int l = par1World.getBlockMetadata(par2, par3, par4) & 7; float f = 0.125F; return AxisAlignedBB.getAABBPool().getAABB((double)par2 + this.minX, (double)par3 + this.minY, (double)par4 + this.minZ, (double)par2 + this.maxX, (double)((float)par3 + (float)l * f), (double)par4 + this.maxZ); } /** * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. */ public boolean isOpaqueCube() { return false; } /** * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) */ public boolean renderAsNormalBlock() { return false; } /** * Sets the block's bounds for rendering it as an item */ public void setBlockBoundsForItemRender() { this.setBlockBoundsForSnowDepth(0); } /** * Updates the blocks bounds based on its current state. Args: world, x, y, z */ public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { this.setBlockBoundsForSnowDepth(par1IBlockAccess.getBlockMetadata(par2, par3, par4)); } /** * calls setBlockBounds based on the depth of the snow. Int is any values 0x0-0x7, usually this blocks metadata. */ protected void setBlockBoundsForSnowDepth(int par1) { int j = par1 & 7; float f = (float)(2 * (1 + j)) / 16.0F; this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, f, 1.0F); } /** * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z */ public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) { int l = par1World.getBlockId(par2, par3 - 1, par4); Block block = Block.blocksList[l]; if (block == null) return false; if (block == this) return true; if (block == this && (par1World.getBlockMetadata(par2, par3 - 1, par4) & 7) == 7) return true; if (!block.isLeaves(par1World, par2, par3 - 1, par4) && !Block.blocksList[l].isOpaqueCube()) return false; return par1World.getBlockMaterial(par2, par3 - 1, par4).blocksMovement(); } /** * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are * their own) Args: x, y, z, neighbor blockID */ public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { this.canSnowStay(par1World, par2, par3, par4); } /** * Checks if this snow block can stay at this location. */ private boolean canSnowStay(World par1World, int par2, int par3, int par4) { if (!this.canPlaceBlockAt(par1World, par2, par3, par4)) { par1World.setBlockToAir(par2, par3, par4); return false; } else { return true; } } /** * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the * block and l is the block's subtype/damage. */ public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) { super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6); par1World.setBlockToAir(par3, par4, par5); } /** * Returns the quantity of items to drop on block destruction. */ public int quantityDropped(Random par1Random) { return 0; } @Override public int quantityDropped(int meta, int fortune, Random random) { return 0; } @SideOnly(Side.CLIENT) public int getBlockColor() { double d0 = 0.5D; double d1 = 1.0D; return ColorizerGrass.getGrassColor(d0, d1); } @SideOnly(Side.CLIENT) /** * Returns the color this block should be rendered. Used by leaves. */ public int getRenderColor(int par1) { return this.getBlockColor(); } /** * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called * when first determining what to render. */ @SideOnly(Side.CLIENT) public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { int i1 = 0; int j1 = 0; int k1 = 0; for (int l1 = -1; l1 <= 1; ++l1) { for (int i2 = -1; i2 <= 1; ++i2) { int j2 = par1IBlockAccess.getBiomeGenForCoords(par2 + i2, par4 + l1).getBiomeGrassColor(); i1 += (j2 & 16711680) >> 16; j1 += (j2 & 65280) >> 8; k1 += j2 & 255; } } return (i1 / 9 & 255) << 16 | (j1 / 9 & 255) << 8 | k1 / 9 & 255; } @SideOnly(Side.CLIENT) public static Icon getIconSideOverlay() { return CoverBlocksMod.grassCover.getIcon(0, 0); } } Any advice? Thanks in advance.
  2. So, I want to make a new block that uses a custom model, and I have no idea where to begin. I have Techne, but I'm not entirely sure how it works, almost all the tutorials that I found for it are for making mobs. I would like to avoid using a Tile Entity, so my custom block can be pushed and pulled by a piston, like cauldrons and stairs can. Almost all of the tutorials for this that I've seen are either so outdated that I can't figure out how to make them work in 1.5.2, or they use tile entities. Any idea where I can start?
  3. It works! Thank you thank you sooo much!
  4. I had this problem too. Use "setUnlocalizedName()" instead of "setBlockName()"/"setItemName()".
  5. It works great (I had to use setUnlocalizedName() instead of setItemName()), but now I have working double slabs. Problem is, now my double slab has a name, but my single slabs have a blank tooltip. Here's some bits of code that might be relevant: public static BlockHalfSlab haySlab = (BlockHalfSlab) new SlabHay(505, false) .setUnlocalizedName("haySlab") .setCreativeTab(CreativeTabs.tabBlock); public static BlockHalfSlab hayDoubleSlab = (BlockHalfSlab) new SlabHay(506, true) .setUnlocalizedName("hayDoubleSlab"); @Init public void load(FMLInitializationEvent event) { proxy.registerRenderers(); //// Register the block, it's name, and it's harvest level // Hay Double Slab GameRegistry.registerBlock(hayDoubleSlab, "hayDoubleSlab"); LanguageRegistry.addName(hayDoubleSlab, "Hay Double Slab"); MinecraftForge.setBlockHarvestLevel(hayDoubleSlab, "hatchet", 0); // Hay Slab GameRegistry.registerBlock(haySlab, "haySlab"); LanguageRegistry.addName(haySlab, "Hay Slab"); MinecraftForge.setBlockHarvestLevel(haySlab, "hatchet", 0); //// Register the recipes // Hay Slab GameRegistry.addRecipe(new ItemStack(haySlab, 6), "xxx", 'x', new ItemStack(hayBlock)); } @PostInit public void postInit(FMLPostInitializationEvent event) { Item.itemsList[haySlab.blockID] = new ItemSlab(haySlab.blockID - 256, (BlockHalfSlab)haySlab, (BlockHalfSlab)hayDoubleSlab, false) .setUnlocalizedName("haySlab"); } Any idea why my single slab has no name? I tried using LanguageRegistry.addName(Item.itemsList[haySlab.blockID], "Hay Slab"); to no avail.
  6. So, I managed to create a half slab that works nicely, but when I try to put another one on top of it, it doesn't create a double slab; instead it creates a new slab above it. It inherits from BlockHalfSlab, and I used that class as well as BlockWoodSlab as examples, but I can't seem to figure this out. Here's what I have so far: public class SlabHay extends BlockHalfSlab { protected static Icon iconSide; public SlabHay(int id, boolean doubleslab) { super(id, doubleslab, Material.wood); setHardness(1.5f); setResistance(4.0f); setStepSound(Block.soundGrassFootstep); setUnlocalizedName("haySlab"); useNeighborBrightness[id] = true; } public int idDropped(int par1, Random par2Random, int par3) { return HayMod.haySlab.blockID; } public String getFullSlabName(int i) { if (!isDoubleSlab) return super.getUnlocalizedName() + "haySlab"; else return super.getUnlocalizedName() + "hayDoubleSlab"; } @Override public void func_94332_a(IconRegister par1IconRegister) { iconSide = par1IconRegister.func_94245_a("hvh:hay_side"); field_94336_cN = par1IconRegister.func_94245_a("hvh:hay_top"); } @SideOnly(Side.CLIENT) public Icon getBlockTextureFromSideAndMetadata(int par1, int par2) { if (par1 == 0 || par1 == 1) return field_94336_cN; else return iconSide; } } Is there a method that I missed? Am I supposed to register it with something?
  7. I tried registering the blocks before adding the names, but nothing changed. They were both still called "Generic Block".
  8. So, I'm just starting out learning the forge api (7.7.0), following the basic tutorials on the forge wiki (which have been extremely helpful, even with 1.5 being so new). I was able to get a couple of blocks and items working, even with new textures (it wasn't hard to figure out from the wiki, though I'm still not sure how to handle side textures). However, a big problem I'm having, is that both of my items have the same name, and likewise both of my blocks have the same name, despite them being different in code. Here's an except from my Generic.java: public final static Block genericDirt = new GenericBlock(500, Material.rock); public final static Block genericOre = new GenericOre(501, Material.iron); public final static Item genericGem = new GenericItem(5000); public final static Item genericThingy = new GenericThingy(5001); @Init public void load(FMLInitializationEvent event) { proxy.registerRenderers(); LanguageRegistry.addName(genericGem, "Generic Gem"); LanguageRegistry.addName(genericThingy, "Generic Thingy"); LanguageRegistry.addName(genericOre, "Generic Ore"); MinecraftForge.setBlockHarvestLevel(genericOre, "pickaxe", 3); GameRegistry.registerBlock(genericOre, "genericOre"); LanguageRegistry.addName(genericDirt, "Generic Block"); MinecraftForge.setBlockHarvestLevel(genericDirt, "pickaxe", 0); GameRegistry.registerBlock(genericDirt, "genericDirt"); } In-game, both of my blocks are named "Generic Block", when one of them is supposed to be named "Generic Ore". Both of my items are named "Generic Thingy", when one of them is supposed to be named "Generic Gem". Everything else - materials, sounds, textures, item drops, etc. - works as intended. What am I doing wrong? SOLVED: I fixed it by using setUnlocalizedName() with the blocks and items. In the tutorials, setBlockName()/setItemName() was used, but these methods no longer exist, so I simply removed them. Using setUnlocalizedName() in their placed fixed everything.
×
×
  • Create New...

Important Information

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