001package net.minecraft.block; 002 003import static net.minecraftforge.common.ForgeDirection.DOWN; 004import static net.minecraftforge.common.ForgeDirection.UP; 005 006import java.util.ArrayList; 007import java.util.List; 008import java.util.Random; 009 010import net.minecraft.block.material.Material; 011import net.minecraft.client.particle.EffectRenderer; 012import net.minecraft.client.renderer.texture.IconRegister; 013import net.minecraft.creativetab.CreativeTabs; 014import net.minecraft.enchantment.EnchantmentHelper; 015import net.minecraft.entity.Entity; 016import net.minecraft.entity.EntityLiving; 017import net.minecraft.entity.EnumCreatureType; 018import net.minecraft.entity.item.EntityItem; 019import net.minecraft.entity.item.EntityXPOrb; 020import net.minecraft.entity.player.EntityPlayer; 021import net.minecraft.item.Item; 022import net.minecraft.item.ItemAnvilBlock; 023import net.minecraft.item.ItemBlock; 024import net.minecraft.item.ItemCloth; 025import net.minecraft.item.ItemColored; 026import net.minecraft.item.ItemLeaves; 027import net.minecraft.item.ItemLilyPad; 028import net.minecraft.item.ItemMultiTextureTile; 029import net.minecraft.item.ItemPiston; 030import net.minecraft.item.ItemSlab; 031import net.minecraft.item.ItemSnow; 032import net.minecraft.item.ItemStack; 033import net.minecraft.stats.StatList; 034import net.minecraft.tileentity.TileEntity; 035import net.minecraft.tileentity.TileEntitySign; 036import net.minecraft.util.AxisAlignedBB; 037import net.minecraft.util.ChunkCoordinates; 038import net.minecraft.util.Icon; 039import net.minecraft.util.MovingObjectPosition; 040import net.minecraft.util.StatCollector; 041import net.minecraft.util.Vec3; 042import net.minecraft.world.Explosion; 043import net.minecraft.world.IBlockAccess; 044import net.minecraft.world.World; 045import net.minecraft.world.WorldProviderEnd; 046import net.minecraftforge.common.EnumPlantType; 047import net.minecraftforge.common.ForgeDirection; 048import net.minecraftforge.common.ForgeHooks; 049import net.minecraftforge.common.IPlantable; 050import net.minecraftforge.common.RotationHelper; 051import cpw.mods.fml.relauncher.Side; 052import cpw.mods.fml.relauncher.SideOnly; 053 054public class Block 055{ 056 protected static int[] blockFireSpreadSpeed = new int[4096]; 057 protected static int[] blockFlammability = new int[4096]; 058 /** 059 * used as foreach item, if item.tab = current tab, display it on the screen 060 */ 061 private CreativeTabs displayOnCreativeTab; 062 public static final StepSound soundPowderFootstep = new StepSound("stone", 1.0F, 1.0F); 063 public static final StepSound soundWoodFootstep = new StepSound("wood", 1.0F, 1.0F); 064 public static final StepSound soundGravelFootstep = new StepSound("gravel", 1.0F, 1.0F); 065 public static final StepSound soundGrassFootstep = new StepSound("grass", 1.0F, 1.0F); 066 public static final StepSound soundStoneFootstep = new StepSound("stone", 1.0F, 1.0F); 067 public static final StepSound soundMetalFootstep = new StepSound("stone", 1.0F, 1.5F); 068 public static final StepSound soundGlassFootstep = new StepSoundStone("stone", 1.0F, 1.0F); 069 public static final StepSound soundClothFootstep = new StepSound("cloth", 1.0F, 1.0F); 070 public static final StepSound soundSandFootstep = new StepSound("sand", 1.0F, 1.0F); 071 public static final StepSound soundSnowFootstep = new StepSound("snow", 1.0F, 1.0F); 072 public static final StepSound soundLadderFootstep = new StepSoundSand("ladder", 1.0F, 1.0F); 073 public static final StepSound soundAnvilFootstep = new StepSoundAnvil("anvil", 0.3F, 1.0F); 074 075 /** List of ly/ff (BlockType) containing the already registered blocks. */ 076 public static final Block[] blocksList = new Block[4096]; 077 078 /** 079 * An array of 4096 booleans corresponding to the result of the isOpaqueCube() method for each block ID 080 */ 081 public static final boolean[] opaqueCubeLookup = new boolean[4096]; 082 083 /** How much light is subtracted for going through this block */ 084 public static final int[] lightOpacity = new int[4096]; 085 086 /** Array of booleans that tells if a block can grass */ 087 public static final boolean[] canBlockGrass = new boolean[4096]; 088 089 /** Amount of light emitted */ 090 public static final int[] lightValue = new int[4096]; 091 092 /** 093 * Flag if block ID should use the brightest neighbor light value as its own 094 */ 095 public static boolean[] useNeighborBrightness = new boolean[4096]; 096 public static final Block stone = (new BlockStone(1)).setHardness(1.5F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("stone"); 097 public static final BlockGrass grass = (BlockGrass)(new BlockGrass(2)).setHardness(0.6F).setStepSound(soundGrassFootstep).setUnlocalizedName("grass"); 098 public static final Block dirt = (new BlockDirt(3)).setHardness(0.5F).setStepSound(soundGravelFootstep).setUnlocalizedName("dirt"); 099 public static final Block cobblestone = (new Block(4, Material.rock)).setHardness(2.0F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("stonebrick").setCreativeTab(CreativeTabs.tabBlock); 100 public static final Block planks = (new BlockWood(5)).setHardness(2.0F).setResistance(5.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("wood"); 101 public static final Block sapling = (new BlockSapling(6)).setHardness(0.0F).setStepSound(soundGrassFootstep).setUnlocalizedName("sapling"); 102 public static final Block bedrock = (new Block(7, Material.rock)).setBlockUnbreakable().setResistance(6000000.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("bedrock").disableStats().setCreativeTab(CreativeTabs.tabBlock); 103 public static final BlockFluid waterMoving = (BlockFluid)(new BlockFlowing(8, Material.water)).setHardness(100.0F).setLightOpacity(3).setUnlocalizedName("water").disableStats(); 104 public static final Block waterStill = (new BlockStationary(9, Material.water)).setHardness(100.0F).setLightOpacity(3).setUnlocalizedName("water").disableStats(); 105 public static final BlockFluid lavaMoving = (BlockFluid)(new BlockFlowing(10, Material.lava)).setHardness(0.0F).setLightValue(1.0F).setUnlocalizedName("lava").disableStats(); 106 107 /** Stationary lava source block */ 108 public static final Block lavaStill = (new BlockStationary(11, Material.lava)).setHardness(100.0F).setLightValue(1.0F).setUnlocalizedName("lava").disableStats(); 109 public static final Block sand = (new BlockSand(12)).setHardness(0.5F).setStepSound(soundSandFootstep).setUnlocalizedName("sand"); 110 public static final Block gravel = (new BlockGravel(13)).setHardness(0.6F).setStepSound(soundGravelFootstep).setUnlocalizedName("gravel"); 111 public static final Block oreGold = (new BlockOre(14)).setHardness(3.0F).setResistance(5.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("oreGold"); 112 public static final Block oreIron = (new BlockOre(15)).setHardness(3.0F).setResistance(5.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("oreIron"); 113 public static final Block oreCoal = (new BlockOre(16)).setHardness(3.0F).setResistance(5.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("oreCoal"); 114 public static final Block wood = (new BlockLog(17)).setHardness(2.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("log"); 115 public static final BlockLeaves leaves = (BlockLeaves)(new BlockLeaves(18)).setHardness(0.2F).setLightOpacity(1).setStepSound(soundGrassFootstep).setUnlocalizedName("leaves"); 116 public static final Block sponge = (new BlockSponge(19)).setHardness(0.6F).setStepSound(soundGrassFootstep).setUnlocalizedName("sponge"); 117 public static final Block glass = (new BlockGlass(20, Material.glass, false)).setHardness(0.3F).setStepSound(soundGlassFootstep).setUnlocalizedName("glass"); 118 public static final Block oreLapis = (new BlockOre(21)).setHardness(3.0F).setResistance(5.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("oreLapis"); 119 public static final Block blockLapis = (new Block(22, Material.rock)).setHardness(3.0F).setResistance(5.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("blockLapis").setCreativeTab(CreativeTabs.tabBlock); 120 public static final Block dispenser = (new BlockDispenser(23)).setHardness(3.5F).setStepSound(soundStoneFootstep).setUnlocalizedName("dispenser"); 121 public static final Block sandStone = (new BlockSandStone(24)).setStepSound(soundStoneFootstep).setHardness(0.8F).setUnlocalizedName("sandStone"); 122 public static final Block music = (new BlockNote(25)).setHardness(0.8F).setUnlocalizedName("musicBlock"); 123 public static final Block bed = (new BlockBed(26)).setHardness(0.2F).setUnlocalizedName("bed").disableStats(); 124 public static final Block railPowered = (new BlockRailPowered(27)).setHardness(0.7F).setStepSound(soundMetalFootstep).setUnlocalizedName("goldenRail"); 125 public static final Block railDetector = (new BlockDetectorRail(28)).setHardness(0.7F).setStepSound(soundMetalFootstep).setUnlocalizedName("detectorRail"); 126 public static final BlockPistonBase pistonStickyBase = (BlockPistonBase)(new BlockPistonBase(29, true)).setUnlocalizedName("pistonStickyBase"); 127 public static final Block web = (new BlockWeb(30)).setLightOpacity(1).setHardness(4.0F).setUnlocalizedName("web"); 128 public static final BlockTallGrass tallGrass = (BlockTallGrass)(new BlockTallGrass(31)).setHardness(0.0F).setStepSound(soundGrassFootstep).setUnlocalizedName("tallgrass"); 129 public static final BlockDeadBush deadBush = (BlockDeadBush)(new BlockDeadBush(32)).setHardness(0.0F).setStepSound(soundGrassFootstep).setUnlocalizedName("deadbush"); 130 public static final BlockPistonBase pistonBase = (BlockPistonBase)(new BlockPistonBase(33, false)).setUnlocalizedName("pistonBase"); 131 public static final BlockPistonExtension pistonExtension = new BlockPistonExtension(34); 132 public static final Block cloth = (new BlockCloth()).setHardness(0.8F).setStepSound(soundClothFootstep).setUnlocalizedName("cloth"); 133 public static final BlockPistonMoving pistonMoving = new BlockPistonMoving(36); 134 public static final BlockFlower plantYellow = (BlockFlower)(new BlockFlower(37)).setHardness(0.0F).setStepSound(soundGrassFootstep).setUnlocalizedName("flower"); 135 public static final BlockFlower plantRed = (BlockFlower)(new BlockFlower(38)).setHardness(0.0F).setStepSound(soundGrassFootstep).setUnlocalizedName("rose"); 136 public static final BlockFlower mushroomBrown = (BlockFlower)(new BlockMushroom(39, "mushroom_brown")).setHardness(0.0F).setStepSound(soundGrassFootstep).setLightValue(0.125F).setUnlocalizedName("mushroom"); 137 public static final BlockFlower mushroomRed = (BlockFlower)(new BlockMushroom(40, "mushroom_red")).setHardness(0.0F).setStepSound(soundGrassFootstep).setUnlocalizedName("mushroom"); 138 public static final Block blockGold = (new BlockOreStorage(41)).setHardness(3.0F).setResistance(10.0F).setStepSound(soundMetalFootstep).setUnlocalizedName("blockGold"); 139 public static final Block blockIron = (new BlockOreStorage(42)).setHardness(5.0F).setResistance(10.0F).setStepSound(soundMetalFootstep).setUnlocalizedName("blockIron"); 140 141 /** stoneDoubleSlab */ 142 public static final BlockHalfSlab stoneDoubleSlab = (BlockHalfSlab)(new BlockStep(43, true)).setHardness(2.0F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("stoneSlab"); 143 144 /** stoneSingleSlab */ 145 public static final BlockHalfSlab stoneSingleSlab = (BlockHalfSlab)(new BlockStep(44, false)).setHardness(2.0F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("stoneSlab"); 146 public static final Block brick = (new Block(45, Material.rock)).setHardness(2.0F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("brick").setCreativeTab(CreativeTabs.tabBlock); 147 public static final Block tnt = (new BlockTNT(46)).setHardness(0.0F).setStepSound(soundGrassFootstep).setUnlocalizedName("tnt"); 148 public static final Block bookShelf = (new BlockBookshelf(47)).setHardness(1.5F).setStepSound(soundWoodFootstep).setUnlocalizedName("bookshelf"); 149 public static final Block cobblestoneMossy = (new Block(48, Material.rock)).setHardness(2.0F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("stoneMoss").setCreativeTab(CreativeTabs.tabBlock); 150 public static final Block obsidian = (new BlockObsidian(49)).setHardness(50.0F).setResistance(2000.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("obsidian"); 151 public static final Block torchWood = (new BlockTorch(50)).setHardness(0.0F).setLightValue(0.9375F).setStepSound(soundWoodFootstep).setUnlocalizedName("torch"); 152 public static final BlockFire fire = (BlockFire)(new BlockFire(51)).setHardness(0.0F).setLightValue(1.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("fire").disableStats(); 153 public static final Block mobSpawner = (new BlockMobSpawner(52)).setHardness(5.0F).setStepSound(soundMetalFootstep).setUnlocalizedName("mobSpawner").disableStats(); 154 public static final Block stairsWoodOak = (new BlockStairs(53, planks, 0)).setUnlocalizedName("stairsWood"); 155 public static final BlockChest chest = (BlockChest)(new BlockChest(54, 0)).setHardness(2.5F).setStepSound(soundWoodFootstep).setUnlocalizedName("chest"); 156 public static final BlockRedstoneWire redstoneWire = (BlockRedstoneWire)(new BlockRedstoneWire(55)).setHardness(0.0F).setStepSound(soundPowderFootstep).setUnlocalizedName("redstoneDust").disableStats(); 157 public static final Block oreDiamond = (new BlockOre(56)).setHardness(3.0F).setResistance(5.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("oreDiamond"); 158 public static final Block blockDiamond = (new BlockOreStorage(57)).setHardness(5.0F).setResistance(10.0F).setStepSound(soundMetalFootstep).setUnlocalizedName("blockDiamond"); 159 public static final Block workbench = (new BlockWorkbench(58)).setHardness(2.5F).setStepSound(soundWoodFootstep).setUnlocalizedName("workbench"); 160 public static final Block crops = (new BlockCrops(59)).setUnlocalizedName("crops"); 161 public static final Block tilledField = (new BlockFarmland(60)).setHardness(0.6F).setStepSound(soundGravelFootstep).setUnlocalizedName("farmland"); 162 public static final Block furnaceIdle = (new BlockFurnace(61, false)).setHardness(3.5F).setStepSound(soundStoneFootstep).setUnlocalizedName("furnace").setCreativeTab(CreativeTabs.tabDecorations); 163 public static final Block furnaceBurning = (new BlockFurnace(62, true)).setHardness(3.5F).setStepSound(soundStoneFootstep).setLightValue(0.875F).setUnlocalizedName("furnace"); 164 public static final Block signPost = (new BlockSign(63, TileEntitySign.class, true)).setHardness(1.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("sign").disableStats(); 165 public static final Block doorWood = (new BlockDoor(64, Material.wood)).setHardness(3.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("doorWood").disableStats(); 166 public static final Block ladder = (new BlockLadder(65)).setHardness(0.4F).setStepSound(soundLadderFootstep).setUnlocalizedName("ladder"); 167 public static final Block rail = (new BlockRail(66)).setHardness(0.7F).setStepSound(soundMetalFootstep).setUnlocalizedName("rail"); 168 public static final Block stairsCobblestone = (new BlockStairs(67, cobblestone, 0)).setUnlocalizedName("stairsStone"); 169 public static final Block signWall = (new BlockSign(68, TileEntitySign.class, false)).setHardness(1.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("sign").disableStats(); 170 public static final Block lever = (new BlockLever(69)).setHardness(0.5F).setStepSound(soundWoodFootstep).setUnlocalizedName("lever"); 171 public static final Block pressurePlateStone = (new BlockPressurePlate(70, "stone", Material.rock, EnumMobType.mobs)).setHardness(0.5F).setStepSound(soundStoneFootstep).setUnlocalizedName("pressurePlate"); 172 public static final Block doorIron = (new BlockDoor(71, Material.iron)).setHardness(5.0F).setStepSound(soundMetalFootstep).setUnlocalizedName("doorIron").disableStats(); 173 public static final Block pressurePlatePlanks = (new BlockPressurePlate(72, "wood", Material.wood, EnumMobType.everything)).setHardness(0.5F).setStepSound(soundWoodFootstep).setUnlocalizedName("pressurePlate"); 174 public static final Block oreRedstone = (new BlockRedstoneOre(73, false)).setHardness(3.0F).setResistance(5.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("oreRedstone").setCreativeTab(CreativeTabs.tabBlock); 175 public static final Block oreRedstoneGlowing = (new BlockRedstoneOre(74, true)).setLightValue(0.625F).setHardness(3.0F).setResistance(5.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("oreRedstone"); 176 public static final Block torchRedstoneIdle = (new BlockRedstoneTorch(75, false)).setHardness(0.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("notGate"); 177 public static final Block torchRedstoneActive = (new BlockRedstoneTorch(76, true)).setHardness(0.0F).setLightValue(0.5F).setStepSound(soundWoodFootstep).setUnlocalizedName("notGate").setCreativeTab(CreativeTabs.tabRedstone); 178 public static final Block stoneButton = (new BlockButtonStone(77)).setHardness(0.5F).setStepSound(soundStoneFootstep).setUnlocalizedName("button"); 179 public static final Block snow = (new BlockSnow(78)).setHardness(0.1F).setStepSound(soundSnowFootstep).setUnlocalizedName("snow").setLightOpacity(0); 180 public static final Block ice = (new BlockIce(79)).setHardness(0.5F).setLightOpacity(3).setStepSound(soundGlassFootstep).setUnlocalizedName("ice"); 181 public static final Block blockSnow = (new BlockSnowBlock(80)).setHardness(0.2F).setStepSound(soundSnowFootstep).setUnlocalizedName("snow"); 182 public static final Block cactus = (new BlockCactus(81)).setHardness(0.4F).setStepSound(soundClothFootstep).setUnlocalizedName("cactus"); 183 public static final Block blockClay = (new BlockClay(82)).setHardness(0.6F).setStepSound(soundGravelFootstep).setUnlocalizedName("clay"); 184 public static final Block reed = (new BlockReed(83)).setHardness(0.0F).setStepSound(soundGrassFootstep).setUnlocalizedName("reeds").disableStats(); 185 public static final Block jukebox = (new BlockJukeBox(84)).setHardness(2.0F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("jukebox"); 186 public static final Block fence = (new BlockFence(85, "wood", Material.wood)).setHardness(2.0F).setResistance(5.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("fence"); 187 public static final Block pumpkin = (new BlockPumpkin(86, false)).setHardness(1.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("pumpkin"); 188 public static final Block netherrack = (new BlockNetherrack(87)).setHardness(0.4F).setStepSound(soundStoneFootstep).setUnlocalizedName("hellrock"); 189 public static final Block slowSand = (new BlockSoulSand(88)).setHardness(0.5F).setStepSound(soundSandFootstep).setUnlocalizedName("hellsand"); 190 public static final Block glowStone = (new BlockGlowStone(89, Material.glass)).setHardness(0.3F).setStepSound(soundGlassFootstep).setLightValue(1.0F).setUnlocalizedName("lightgem"); 191 192 /** The purple teleport blocks inside the obsidian circle */ 193 public static final BlockPortal portal = (BlockPortal)(new BlockPortal(90)).setHardness(-1.0F).setStepSound(soundGlassFootstep).setLightValue(0.75F).setUnlocalizedName("portal"); 194 public static final Block pumpkinLantern = (new BlockPumpkin(91, true)).setHardness(1.0F).setStepSound(soundWoodFootstep).setLightValue(1.0F).setUnlocalizedName("litpumpkin"); 195 public static final Block cake = (new BlockCake(92)).setHardness(0.5F).setStepSound(soundClothFootstep).setUnlocalizedName("cake").disableStats(); 196 public static final BlockRedstoneRepeater redstoneRepeaterIdle = (BlockRedstoneRepeater)(new BlockRedstoneRepeater(93, false)).setHardness(0.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("diode").disableStats(); 197 public static final BlockRedstoneRepeater redstoneRepeaterActive = (BlockRedstoneRepeater)(new BlockRedstoneRepeater(94, true)).setHardness(0.0F).setLightValue(0.625F).setStepSound(soundWoodFootstep).setUnlocalizedName("diode").disableStats(); 198 199 /** 200 * April fools secret locked chest, only spawns on new chunks on 1st April. 201 */ 202 public static final Block lockedChest = (new BlockLockedChest(95)).setHardness(0.0F).setLightValue(1.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("lockedchest").setTickRandomly(true); 203 public static final Block trapdoor = (new BlockTrapDoor(96, Material.wood)).setHardness(3.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("trapdoor").disableStats(); 204 public static final Block silverfish = (new BlockSilverfish(97)).setHardness(0.75F).setUnlocalizedName("monsterStoneEgg"); 205 public static final Block stoneBrick = (new BlockStoneBrick(98)).setHardness(1.5F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("stonebricksmooth"); 206 public static final Block mushroomCapBrown = (new BlockMushroomCap(99, Material.wood, 0)).setHardness(0.2F).setStepSound(soundWoodFootstep).setUnlocalizedName("mushroom"); 207 public static final Block mushroomCapRed = (new BlockMushroomCap(100, Material.wood, 1)).setHardness(0.2F).setStepSound(soundWoodFootstep).setUnlocalizedName("mushroom"); 208 public static final Block fenceIron = (new BlockPane(101, "fenceIron", "fenceIron", Material.iron, true)).setHardness(5.0F).setResistance(10.0F).setStepSound(soundMetalFootstep).setUnlocalizedName("fenceIron"); 209 public static final Block thinGlass = (new BlockPane(102, "glass", "thinglass_top", Material.glass, false)).setHardness(0.3F).setStepSound(soundGlassFootstep).setUnlocalizedName("thinGlass"); 210 public static final Block melon = (new BlockMelon(103)).setHardness(1.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("melon"); 211 public static final Block pumpkinStem = (new BlockStem(104, pumpkin)).setHardness(0.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("pumpkinStem"); 212 public static final Block melonStem = (new BlockStem(105, melon)).setHardness(0.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("pumpkinStem"); 213 public static final Block vine = (new BlockVine(106)).setHardness(0.2F).setStepSound(soundGrassFootstep).setUnlocalizedName("vine"); 214 public static final Block fenceGate = (new BlockFenceGate(107)).setHardness(2.0F).setResistance(5.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("fenceGate"); 215 public static final Block stairsBrick = (new BlockStairs(108, brick, 0)).setUnlocalizedName("stairsBrick"); 216 public static final Block stairsStoneBrick = (new BlockStairs(109, stoneBrick, 0)).setUnlocalizedName("stairsStoneBrickSmooth"); 217 public static final BlockMycelium mycelium = (BlockMycelium)(new BlockMycelium(110)).setHardness(0.6F).setStepSound(soundGrassFootstep).setUnlocalizedName("mycel"); 218 public static final Block waterlily = (new BlockLilyPad(111)).setHardness(0.0F).setStepSound(soundGrassFootstep).setUnlocalizedName("waterlily"); 219 public static final Block netherBrick = (new Block(112, Material.rock)).setHardness(2.0F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("netherBrick").setCreativeTab(CreativeTabs.tabBlock); 220 public static final Block netherFence = (new BlockFence(113, "netherBrick", Material.rock)).setHardness(2.0F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("netherFence"); 221 public static final Block stairsNetherBrick = (new BlockStairs(114, netherBrick, 0)).setUnlocalizedName("stairsNetherBrick"); 222 public static final Block netherStalk = (new BlockNetherStalk(115)).setUnlocalizedName("netherStalk"); 223 public static final Block enchantmentTable = (new BlockEnchantmentTable(116)).setHardness(5.0F).setResistance(2000.0F).setUnlocalizedName("enchantmentTable"); 224 public static final Block brewingStand = (new BlockBrewingStand(117)).setHardness(0.5F).setLightValue(0.125F).setUnlocalizedName("brewingStand"); 225 public static final BlockCauldron cauldron = (BlockCauldron)(new BlockCauldron(118)).setHardness(2.0F).setUnlocalizedName("cauldron"); 226 public static final Block endPortal = (new BlockEndPortal(119, Material.portal)).setHardness(-1.0F).setResistance(6000000.0F); 227 public static final Block endPortalFrame = (new BlockEndPortalFrame(120)).setStepSound(soundGlassFootstep).setLightValue(0.125F).setHardness(-1.0F).setUnlocalizedName("endPortalFrame").setResistance(6000000.0F).setCreativeTab(CreativeTabs.tabDecorations); 228 229 /** The rock found in The End. */ 230 public static final Block whiteStone = (new Block(121, Material.rock)).setHardness(3.0F).setResistance(15.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("whiteStone").setCreativeTab(CreativeTabs.tabBlock); 231 public static final Block dragonEgg = (new BlockDragonEgg(122)).setHardness(3.0F).setResistance(15.0F).setStepSound(soundStoneFootstep).setLightValue(0.125F).setUnlocalizedName("dragonEgg"); 232 public static final Block redstoneLampIdle = (new BlockRedstoneLight(123, false)).setHardness(0.3F).setStepSound(soundGlassFootstep).setUnlocalizedName("redstoneLight").setCreativeTab(CreativeTabs.tabRedstone); 233 public static final Block redstoneLampActive = (new BlockRedstoneLight(124, true)).setHardness(0.3F).setStepSound(soundGlassFootstep).setUnlocalizedName("redstoneLight"); 234 public static final BlockHalfSlab woodDoubleSlab = (BlockHalfSlab)(new BlockWoodSlab(125, true)).setHardness(2.0F).setResistance(5.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("woodSlab"); 235 public static final BlockHalfSlab woodSingleSlab = (BlockHalfSlab)(new BlockWoodSlab(126, false)).setHardness(2.0F).setResistance(5.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("woodSlab"); 236 public static final Block cocoaPlant = (new BlockCocoa(127)).setHardness(0.2F).setResistance(5.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("cocoa"); 237 public static final Block stairsSandStone = (new BlockStairs(128, sandStone, 0)).setUnlocalizedName("stairsSandStone"); 238 public static final Block oreEmerald = (new BlockOre(129)).setHardness(3.0F).setResistance(5.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("oreEmerald"); 239 public static final Block enderChest = (new BlockEnderChest(130)).setHardness(22.5F).setResistance(1000.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("enderChest").setLightValue(0.5F); 240 public static final BlockTripWireSource tripWireSource = (BlockTripWireSource)(new BlockTripWireSource(131)).setUnlocalizedName("tripWireSource"); 241 public static final Block tripWire = (new BlockTripWire(132)).setUnlocalizedName("tripWire"); 242 public static final Block blockEmerald = (new BlockOreStorage(133)).setHardness(5.0F).setResistance(10.0F).setStepSound(soundMetalFootstep).setUnlocalizedName("blockEmerald"); 243 public static final Block stairsWoodSpruce = (new BlockStairs(134, planks, 1)).setUnlocalizedName("stairsWoodSpruce"); 244 public static final Block stairsWoodBirch = (new BlockStairs(135, planks, 2)).setUnlocalizedName("stairsWoodBirch"); 245 public static final Block stairsWoodJungle = (new BlockStairs(136, planks, 3)).setUnlocalizedName("stairsWoodJungle"); 246 public static final Block commandBlock = (new BlockCommandBlock(137)).setUnlocalizedName("commandBlock"); 247 public static final BlockBeacon beacon = (BlockBeacon)(new BlockBeacon(138)).setUnlocalizedName("beacon").setLightValue(1.0F); 248 public static final Block cobblestoneWall = (new BlockWall(139, cobblestone)).setUnlocalizedName("cobbleWall"); 249 public static final Block flowerPot = (new BlockFlowerPot(140)).setHardness(0.0F).setStepSound(soundPowderFootstep).setUnlocalizedName("flowerPot"); 250 public static final Block carrot = (new BlockCarrot(141)).setUnlocalizedName("carrots"); 251 public static final Block potato = (new BlockPotato(142)).setUnlocalizedName("potatoes"); 252 public static final Block woodenButton = (new BlockButtonWood(143)).setHardness(0.5F).setStepSound(soundWoodFootstep).setUnlocalizedName("button"); 253 public static final Block skull = (new BlockSkull(144)).setHardness(1.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("skull"); 254 public static final Block anvil = (new BlockAnvil(145)).setHardness(5.0F).setStepSound(soundAnvilFootstep).setResistance(2000.0F).setUnlocalizedName("anvil"); 255 public static final Block chestTrapped = (new BlockChest(146, 1)).setHardness(2.5F).setStepSound(soundWoodFootstep).setUnlocalizedName("chestTrap"); 256 public static final Block pressurePlateGold = (new BlockPressurePlateWeighted(147, "blockGold", Material.iron, 64)).setHardness(0.5F).setStepSound(soundWoodFootstep).setUnlocalizedName("weightedPlate_light"); 257 public static final Block pressurePlateIron = (new BlockPressurePlateWeighted(148, "blockIron", Material.iron, 640)).setHardness(0.5F).setStepSound(soundWoodFootstep).setUnlocalizedName("weightedPlate_heavy"); 258 public static final BlockComparator redstoneComparatorIdle = (BlockComparator)(new BlockComparator(149, false)).setHardness(0.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("comparator").disableStats(); 259 public static final BlockComparator redstoneComparatorActive = (BlockComparator)(new BlockComparator(150, true)).setHardness(0.0F).setLightValue(0.625F).setStepSound(soundWoodFootstep).setUnlocalizedName("comparator").disableStats(); 260 public static final BlockDaylightDetector daylightSensor = (BlockDaylightDetector)(new BlockDaylightDetector(151)).setHardness(0.2F).setStepSound(soundWoodFootstep).setUnlocalizedName("daylightDetector"); 261 public static final Block blockRedstone = (new BlockPoweredOre(152)).setHardness(5.0F).setResistance(10.0F).setStepSound(soundMetalFootstep).setUnlocalizedName("blockRedstone"); 262 public static final Block oreNetherQuartz = (new BlockOre(153)).setHardness(3.0F).setResistance(5.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("netherquartz"); 263 public static final BlockHopper hopperBlock = (BlockHopper)(new BlockHopper(154)).setHardness(3.0F).setResistance(8.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("hopper"); 264 public static final Block blockNetherQuartz = (new BlockQuartz(155)).setStepSound(soundStoneFootstep).setHardness(0.8F).setUnlocalizedName("quartzBlock"); 265 public static final Block stairsNetherQuartz = (new BlockStairs(156, blockNetherQuartz, 0)).setUnlocalizedName("stairsQuartz"); 266 public static final Block railActivator = (new BlockRailPowered(157)).setHardness(0.7F).setStepSound(soundMetalFootstep).setUnlocalizedName("activatorRail"); 267 public static final Block dropper = (new BlockDropper(158)).setHardness(3.5F).setStepSound(soundStoneFootstep).setUnlocalizedName("dropper"); 268 269 /** ID of the block. */ 270 public final int blockID; 271 272 /** Indicates how many hits it takes to break a block. */ 273 public float blockHardness; 274 275 /** Indicates the blocks resistance to explosions. */ 276 public float blockResistance; 277 278 /** 279 * set to true when Block's constructor is called through the chain of super()'s. Note: Never used 280 */ 281 protected boolean blockConstructorCalled = true; 282 283 /** 284 * If this field is true, the block is counted for statistics (mined or placed) 285 */ 286 protected boolean enableStats = true; 287 288 /** 289 * Flags whether or not this block is of a type that needs random ticking. Ref-counted by ExtendedBlockStorage in 290 * order to broadly cull a chunk from the random chunk update list for efficiency's sake. 291 */ 292 protected boolean needsRandomTick; 293 294 /** true if the Block contains a Tile Entity */ 295 protected boolean isBlockContainer; 296 297 /** minimum X for the block bounds (local coordinates) */ 298 protected double minX; 299 300 /** minimum Y for the block bounds (local coordinates) */ 301 protected double minY; 302 303 /** minimum Z for the block bounds (local coordinates) */ 304 protected double minZ; 305 306 /** maximum X for the block bounds (local coordinates) */ 307 protected double maxX; 308 309 /** maximum Y for the block bounds (local coordinates) */ 310 protected double maxY; 311 312 /** maximum Z for the block bounds (local coordinates) */ 313 protected double maxZ; 314 315 /** Sound of stepping on the block */ 316 public StepSound stepSound; 317 public float blockParticleGravity; 318 319 /** Block material definition. */ 320 public final Material blockMaterial; 321 322 /** 323 * Determines how much velocity is maintained while moving on top of this block 324 */ 325 public float slipperiness; 326 327 /** The unlocalized name of this block. */ 328 private String unlocalizedName; 329 @SideOnly(Side.CLIENT) 330 protected Icon blockIcon; 331 332 public Block(int par1, Material par2Material) 333 { 334 this.stepSound = soundPowderFootstep; 335 this.blockParticleGravity = 1.0F; 336 this.slipperiness = 0.6F; 337 338 if (blocksList[par1] != null) 339 { 340 throw new IllegalArgumentException("Slot " + par1 + " is already occupied by " + blocksList[par1] + " when adding " + this); 341 } 342 else 343 { 344 this.blockMaterial = par2Material; 345 blocksList[par1] = this; 346 this.blockID = par1; 347 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); 348 opaqueCubeLookup[par1] = this.isOpaqueCube(); 349 lightOpacity[par1] = this.isOpaqueCube() ? 255 : 0; 350 canBlockGrass[par1] = !par2Material.getCanBlockGrass(); 351 } 352 } 353 354 /** 355 * This method is called on a block after all other blocks gets already created. You can use it to reference and 356 * configure something on the block that needs the others ones. 357 */ 358 protected void initializeBlock() {} 359 360 /** 361 * Sets the footstep sound for the block. Returns the object for convenience in constructing. 362 */ 363 public Block setStepSound(StepSound par1StepSound) 364 { 365 this.stepSound = par1StepSound; 366 return this; 367 } 368 369 /** 370 * Sets how much light is blocked going through this block. Returns the object for convenience in constructing. 371 */ 372 public Block setLightOpacity(int par1) 373 { 374 lightOpacity[this.blockID] = par1; 375 return this; 376 } 377 378 /** 379 * Sets the amount of light emitted by a block from 0.0f to 1.0f (converts internally to 0-15). Returns the object 380 * for convenience in constructing. 381 */ 382 public Block setLightValue(float par1) 383 { 384 lightValue[this.blockID] = (int)(15.0F * par1); 385 return this; 386 } 387 388 /** 389 * Sets the the blocks resistance to explosions. Returns the object for convenience in constructing. 390 */ 391 public Block setResistance(float par1) 392 { 393 this.blockResistance = par1 * 3.0F; 394 return this; 395 } 396 397 public static boolean isNormalCube(int par0) 398 { 399 Block block = blocksList[par0]; 400 return block == null ? false : block.blockMaterial.isOpaque() && block.renderAsNormalBlock() && !block.canProvidePower(); 401 } 402 403 /** 404 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 405 */ 406 public boolean renderAsNormalBlock() 407 { 408 return true; 409 } 410 411 public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 412 { 413 return !this.blockMaterial.blocksMovement(); 414 } 415 416 /** 417 * The type of render function that is called for this block 418 */ 419 public int getRenderType() 420 { 421 return 0; 422 } 423 424 /** 425 * Sets how many hits it takes to break a block. 426 */ 427 public Block setHardness(float par1) 428 { 429 this.blockHardness = par1; 430 431 if (this.blockResistance < par1 * 5.0F) 432 { 433 this.blockResistance = par1 * 5.0F; 434 } 435 436 return this; 437 } 438 439 /** 440 * This method will make the hardness of the block equals to -1, and the block is indestructible. 441 */ 442 public Block setBlockUnbreakable() 443 { 444 this.setHardness(-1.0F); 445 return this; 446 } 447 448 /** 449 * Returns the block hardness at a location. Args: world, x, y, z 450 */ 451 public float getBlockHardness(World par1World, int par2, int par3, int par4) 452 { 453 return this.blockHardness; 454 } 455 456 /** 457 * Sets whether this block type will receive random update ticks 458 */ 459 public Block setTickRandomly(boolean par1) 460 { 461 this.needsRandomTick = par1; 462 return this; 463 } 464 465 /** 466 * Returns whether or not this block is of a type that needs random ticking. Called for ref-counting purposes by 467 * ExtendedBlockStorage in order to broadly cull a chunk from the random chunk update list for efficiency's sake. 468 */ 469 public boolean getTickRandomly() 470 { 471 return this.needsRandomTick; 472 } 473 474 @Deprecated //Forge: New Metadata sensitive version. 475 public boolean hasTileEntity() 476 { 477 return hasTileEntity(0); 478 } 479 480 /** 481 * Sets the bounds of the block. minX, minY, minZ, maxX, maxY, maxZ 482 */ 483 public final void setBlockBounds(float par1, float par2, float par3, float par4, float par5, float par6) 484 { 485 this.minX = (double)par1; 486 this.minY = (double)par2; 487 this.minZ = (double)par3; 488 this.maxX = (double)par4; 489 this.maxY = (double)par5; 490 this.maxZ = (double)par6; 491 } 492 493 @SideOnly(Side.CLIENT) 494 495 /** 496 * How bright to render this block based on the light its receiving. Args: iBlockAccess, x, y, z 497 */ 498 public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 499 { 500 return par1IBlockAccess.getBrightness(par2, par3, par4, getLightValue(par1IBlockAccess, par2, par3, par4)); 501 } 502 503 @SideOnly(Side.CLIENT) 504 505 /** 506 * Goes straight to getLightBrightnessForSkyBlocks for Blocks, does some fancy computing for Fluids 507 */ 508 public int getMixedBrightnessForBlock(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 509 { 510 return par1IBlockAccess.getLightBrightnessForSkyBlocks(par2, par3, par4, getLightValue(par1IBlockAccess, par2, par3, par4)); 511 } 512 513 @SideOnly(Side.CLIENT) 514 515 /** 516 * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given 517 * coordinates. Args: blockAccess, x, y, z, side 518 */ 519 public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 520 { 521 return par5 == 0 && this.minY > 0.0D ? true : (par5 == 1 && this.maxY < 1.0D ? true : (par5 == 2 && this.minZ > 0.0D ? true : (par5 == 3 && this.maxZ < 1.0D ? true : (par5 == 4 && this.minX > 0.0D ? true : (par5 == 5 && this.maxX < 1.0D ? true : !par1IBlockAccess.isBlockOpaqueCube(par2, par3, par4)))))); 522 } 523 524 /** 525 * Returns Returns true if the given side of this block type should be rendered (if it's solid or not), if the 526 * adjacent block is at the given coordinates. Args: blockAccess, x, y, z, side 527 */ 528 public boolean isBlockSolid(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 529 { 530 return par1IBlockAccess.getBlockMaterial(par2, par3, par4).isSolid(); 531 } 532 533 @SideOnly(Side.CLIENT) 534 535 /** 536 * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side 537 */ 538 public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 539 { 540 return this.getIcon(par5, par1IBlockAccess.getBlockMetadata(par2, par3, par4)); 541 } 542 543 @SideOnly(Side.CLIENT) 544 545 /** 546 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata 547 */ 548 public Icon getIcon(int par1, int par2) 549 { 550 return this.blockIcon; 551 } 552 553 /** 554 * Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if they intersect the 555 * mask.) Parameters: World, X, Y, Z, mask, list, colliding entity 556 */ 557 public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity) 558 { 559 AxisAlignedBB axisalignedbb1 = this.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4); 560 561 if (axisalignedbb1 != null && par5AxisAlignedBB.intersectsWith(axisalignedbb1)) 562 { 563 par6List.add(axisalignedbb1); 564 } 565 } 566 567 @SideOnly(Side.CLIENT) 568 569 /** 570 * Returns the block texture based on the side being looked at. Args: side 571 */ 572 public final Icon getBlockTextureFromSide(int par1) 573 { 574 return this.getIcon(par1, 0); 575 } 576 577 @SideOnly(Side.CLIENT) 578 579 /** 580 * Returns the bounding box of the wired rectangular prism to render. 581 */ 582 public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4) 583 { 584 return AxisAlignedBB.getAABBPool().getAABB((double)par2 + this.minX, (double)par3 + this.minY, (double)par4 + this.minZ, (double)par2 + this.maxX, (double)par3 + this.maxY, (double)par4 + this.maxZ); 585 } 586 587 /** 588 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been 589 * cleared to be reused) 590 */ 591 public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) 592 { 593 return AxisAlignedBB.getAABBPool().getAABB((double)par2 + this.minX, (double)par3 + this.minY, (double)par4 + this.minZ, (double)par2 + this.maxX, (double)par3 + this.maxY, (double)par4 + this.maxZ); 594 } 595 596 /** 597 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 598 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 599 */ 600 public boolean isOpaqueCube() 601 { 602 return true; 603 } 604 605 /** 606 * Returns whether this block is collideable based on the arguments passed in Args: blockMetaData, unknownFlag 607 */ 608 public boolean canCollideCheck(int par1, boolean par2) 609 { 610 return this.isCollidable(); 611 } 612 613 /** 614 * Returns if this block is collidable (only used by Fire). Args: x, y, z 615 */ 616 public boolean isCollidable() 617 { 618 return true; 619 } 620 621 /** 622 * Ticks the block if it's been scheduled 623 */ 624 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) {} 625 626 @SideOnly(Side.CLIENT) 627 628 /** 629 * A randomly called display update to be able to add particles or other items for display 630 */ 631 public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) {} 632 633 /** 634 * Called right before the block is destroyed by a player. Args: world, x, y, z, metaData 635 */ 636 public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {} 637 638 /** 639 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 640 * their own) Args: x, y, z, neighbor blockID 641 */ 642 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) {} 643 644 /** 645 * How many world ticks before ticking 646 */ 647 public int tickRate(World par1World) 648 { 649 return 10; 650 } 651 652 /** 653 * Called whenever the block is added into the world. Args: world, x, y, z 654 */ 655 public void onBlockAdded(World par1World, int par2, int par3, int par4) {} 656 657 /** 658 * ejects contained items into the world, and notifies neighbours of an update, as appropriate 659 */ 660 public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) 661 { 662 if (hasTileEntity(par6) && !(this instanceof BlockContainer)) 663 { 664 par1World.removeBlockTileEntity(par2, par3, par4); 665 } 666 } 667 668 /** 669 * Returns the quantity of items to drop on block destruction. 670 */ 671 public int quantityDropped(Random par1Random) 672 { 673 return 1; 674 } 675 676 /** 677 * Returns the ID of the items to drop on destruction. 678 */ 679 public int idDropped(int par1, Random par2Random, int par3) 680 { 681 return this.blockID; 682 } 683 684 /** 685 * Gets the hardness of block at the given coordinates in the given world, relative to the ability of the given 686 * EntityPlayer. 687 */ 688 public float getPlayerRelativeBlockHardness(EntityPlayer par1EntityPlayer, World par2World, int par3, int par4, int par5) 689 { 690 float f = this.getBlockHardness(par2World, par3, par4, par5); 691 return ForgeHooks.blockStrength(this, par1EntityPlayer, par2World, par3, par4, par5); 692 } 693 694 /** 695 * Drops the specified block items 696 */ 697 public final void dropBlockAsItem(World par1World, int par2, int par3, int par4, int par5, int par6) 698 { 699 this.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, 1.0F, par6); 700 } 701 702 /** 703 * Drops the block items with a specified chance of dropping the specified items 704 */ 705 public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) 706 { 707 if (!par1World.isRemote) 708 { 709 ArrayList<ItemStack> items = getBlockDropped(par1World, par2, par3, par4, par5, par7); 710 711 for (ItemStack item : items) 712 { 713 if (par1World.rand.nextFloat() <= par6) 714 { 715 this.dropBlockAsItem_do(par1World, par2, par3, par4, item); 716 } 717 } 718 } 719 } 720 721 /** 722 * Spawns EntityItem in the world for the given ItemStack if the world is not remote. 723 */ 724 protected void dropBlockAsItem_do(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack) 725 { 726 if (!par1World.isRemote && par1World.getGameRules().getGameRuleBooleanValue("doTileDrops")) 727 { 728 float f = 0.7F; 729 double d0 = (double)(par1World.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; 730 double d1 = (double)(par1World.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; 731 double d2 = (double)(par1World.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; 732 EntityItem entityitem = new EntityItem(par1World, (double)par2 + d0, (double)par3 + d1, (double)par4 + d2, par5ItemStack); 733 entityitem.delayBeforeCanPickup = 10; 734 par1World.spawnEntityInWorld(entityitem); 735 } 736 } 737 738 /** 739 * called by spawner, ore, redstoneOre blocks 740 */ 741 protected void dropXpOnBlockBreak(World par1World, int par2, int par3, int par4, int par5) 742 { 743 if (!par1World.isRemote) 744 { 745 while (par5 > 0) 746 { 747 int i1 = EntityXPOrb.getXPSplit(par5); 748 par5 -= i1; 749 par1World.spawnEntityInWorld(new EntityXPOrb(par1World, (double)par2 + 0.5D, (double)par3 + 0.5D, (double)par4 + 0.5D, i1)); 750 } 751 } 752 } 753 754 /** 755 * Determines the damage on the item the block drops. Used in cloth and wood. 756 */ 757 public int damageDropped(int par1) 758 { 759 return 0; 760 } 761 762 /** 763 * Returns how much this block can resist explosions from the passed in entity. 764 */ 765 public float getExplosionResistance(Entity par1Entity) 766 { 767 return this.blockResistance / 5.0F; 768 } 769 770 /** 771 * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world, 772 * x, y, z, startVec, endVec 773 */ 774 public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3) 775 { 776 this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); 777 par5Vec3 = par5Vec3.addVector((double)(-par2), (double)(-par3), (double)(-par4)); 778 par6Vec3 = par6Vec3.addVector((double)(-par2), (double)(-par3), (double)(-par4)); 779 Vec3 vec32 = par5Vec3.getIntermediateWithXValue(par6Vec3, this.minX); 780 Vec3 vec33 = par5Vec3.getIntermediateWithXValue(par6Vec3, this.maxX); 781 Vec3 vec34 = par5Vec3.getIntermediateWithYValue(par6Vec3, this.minY); 782 Vec3 vec35 = par5Vec3.getIntermediateWithYValue(par6Vec3, this.maxY); 783 Vec3 vec36 = par5Vec3.getIntermediateWithZValue(par6Vec3, this.minZ); 784 Vec3 vec37 = par5Vec3.getIntermediateWithZValue(par6Vec3, this.maxZ); 785 786 if (!this.isVecInsideYZBounds(vec32)) 787 { 788 vec32 = null; 789 } 790 791 if (!this.isVecInsideYZBounds(vec33)) 792 { 793 vec33 = null; 794 } 795 796 if (!this.isVecInsideXZBounds(vec34)) 797 { 798 vec34 = null; 799 } 800 801 if (!this.isVecInsideXZBounds(vec35)) 802 { 803 vec35 = null; 804 } 805 806 if (!this.isVecInsideXYBounds(vec36)) 807 { 808 vec36 = null; 809 } 810 811 if (!this.isVecInsideXYBounds(vec37)) 812 { 813 vec37 = null; 814 } 815 816 Vec3 vec38 = null; 817 818 if (vec32 != null && (vec38 == null || par5Vec3.squareDistanceTo(vec32) < par5Vec3.squareDistanceTo(vec38))) 819 { 820 vec38 = vec32; 821 } 822 823 if (vec33 != null && (vec38 == null || par5Vec3.squareDistanceTo(vec33) < par5Vec3.squareDistanceTo(vec38))) 824 { 825 vec38 = vec33; 826 } 827 828 if (vec34 != null && (vec38 == null || par5Vec3.squareDistanceTo(vec34) < par5Vec3.squareDistanceTo(vec38))) 829 { 830 vec38 = vec34; 831 } 832 833 if (vec35 != null && (vec38 == null || par5Vec3.squareDistanceTo(vec35) < par5Vec3.squareDistanceTo(vec38))) 834 { 835 vec38 = vec35; 836 } 837 838 if (vec36 != null && (vec38 == null || par5Vec3.squareDistanceTo(vec36) < par5Vec3.squareDistanceTo(vec38))) 839 { 840 vec38 = vec36; 841 } 842 843 if (vec37 != null && (vec38 == null || par5Vec3.squareDistanceTo(vec37) < par5Vec3.squareDistanceTo(vec38))) 844 { 845 vec38 = vec37; 846 } 847 848 if (vec38 == null) 849 { 850 return null; 851 } 852 else 853 { 854 byte b0 = -1; 855 856 if (vec38 == vec32) 857 { 858 b0 = 4; 859 } 860 861 if (vec38 == vec33) 862 { 863 b0 = 5; 864 } 865 866 if (vec38 == vec34) 867 { 868 b0 = 0; 869 } 870 871 if (vec38 == vec35) 872 { 873 b0 = 1; 874 } 875 876 if (vec38 == vec36) 877 { 878 b0 = 2; 879 } 880 881 if (vec38 == vec37) 882 { 883 b0 = 3; 884 } 885 886 return new MovingObjectPosition(par2, par3, par4, b0, vec38.addVector((double)par2, (double)par3, (double)par4)); 887 } 888 } 889 890 /** 891 * Checks if a vector is within the Y and Z bounds of the block. 892 */ 893 private boolean isVecInsideYZBounds(Vec3 par1Vec3) 894 { 895 return par1Vec3 == null ? false : par1Vec3.yCoord >= this.minY && par1Vec3.yCoord <= this.maxY && par1Vec3.zCoord >= this.minZ && par1Vec3.zCoord <= this.maxZ; 896 } 897 898 /** 899 * Checks if a vector is within the X and Z bounds of the block. 900 */ 901 private boolean isVecInsideXZBounds(Vec3 par1Vec3) 902 { 903 return par1Vec3 == null ? false : par1Vec3.xCoord >= this.minX && par1Vec3.xCoord <= this.maxX && par1Vec3.zCoord >= this.minZ && par1Vec3.zCoord <= this.maxZ; 904 } 905 906 /** 907 * Checks if a vector is within the X and Y bounds of the block. 908 */ 909 private boolean isVecInsideXYBounds(Vec3 par1Vec3) 910 { 911 return par1Vec3 == null ? false : par1Vec3.xCoord >= this.minX && par1Vec3.xCoord <= this.maxX && par1Vec3.yCoord >= this.minY && par1Vec3.yCoord <= this.maxY; 912 } 913 914 /** 915 * Called upon the block being destroyed by an explosion 916 */ 917 public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4, Explosion par5Explosion) {} 918 919 public boolean canPlaceBlockOnSide(World par1World, int par2, int par3, int par4, int par5, ItemStack par6ItemStack) 920 { 921 return this.canPlaceBlockOnSide(par1World, par2, par3, par4, par5); 922 } 923 924 @SideOnly(Side.CLIENT) 925 926 /** 927 * Returns which pass should this block be rendered on. 0 for solids and 1 for alpha 928 */ 929 public int getRenderBlockPass() 930 { 931 return 0; 932 } 933 934 /** 935 * checks to see if you can place this block can be placed on that side of a block: BlockLever overrides 936 */ 937 public boolean canPlaceBlockOnSide(World par1World, int par2, int par3, int par4, int par5) 938 { 939 return this.canPlaceBlockAt(par1World, par2, par3, par4); 940 } 941 942 /** 943 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z 944 */ 945 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) 946 { 947 int l = par1World.getBlockId(par2, par3, par4); 948 Block block = Block.blocksList[l]; 949 return block == null || block.isBlockReplaceable(par1World, par2, par3, par4); 950 } 951 952 /** 953 * Called upon block activation (right click on the block.) 954 */ 955 public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) 956 { 957 return false; 958 } 959 960 /** 961 * Called whenever an entity is walking on top of this block. Args: world, x, y, z, entity 962 */ 963 public void onEntityWalking(World par1World, int par2, int par3, int par4, Entity par5Entity) {} 964 965 /** 966 * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata 967 */ 968 public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9) 969 { 970 return par9; 971 } 972 973 /** 974 * Called when the block is clicked by a player. Args: x, y, z, entityPlayer 975 */ 976 public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) {} 977 978 /** 979 * Can add to the passed in vector for a movement vector to be applied to the entity. Args: x, y, z, entity, vec3d 980 */ 981 public void velocityToAddToEntity(World par1World, int par2, int par3, int par4, Entity par5Entity, Vec3 par6Vec3) {} 982 983 /** 984 * Updates the blocks bounds based on its current state. Args: world, x, y, z 985 */ 986 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {} 987 988 /** 989 * returns the block bounderies minX value 990 */ 991 public final double getBlockBoundsMinX() 992 { 993 return this.minX; 994 } 995 996 /** 997 * returns the block bounderies maxX value 998 */ 999 public final double getBlockBoundsMaxX() 1000 { 1001 return this.maxX; 1002 } 1003 1004 /** 1005 * returns the block bounderies minY value 1006 */ 1007 public final double getBlockBoundsMinY() 1008 { 1009 return this.minY; 1010 } 1011 1012 /** 1013 * returns the block bounderies maxY value 1014 */ 1015 public final double getBlockBoundsMaxY() 1016 { 1017 return this.maxY; 1018 } 1019 1020 /** 1021 * returns the block bounderies minZ value 1022 */ 1023 public final double getBlockBoundsMinZ() 1024 { 1025 return this.minZ; 1026 } 1027 1028 /** 1029 * returns the block bounderies maxZ value 1030 */ 1031 public final double getBlockBoundsMaxZ() 1032 { 1033 return this.maxZ; 1034 } 1035 1036 @SideOnly(Side.CLIENT) 1037 public int getBlockColor() 1038 { 1039 return 16777215; 1040 } 1041 1042 @SideOnly(Side.CLIENT) 1043 1044 /** 1045 * Returns the color this block should be rendered. Used by leaves. 1046 */ 1047 public int getRenderColor(int par1) 1048 { 1049 return 16777215; 1050 } 1051 1052 /** 1053 * Returns true if the block is emitting indirect/weak redstone power on the specified side. If isBlockNormalCube 1054 * returns true, standard redstone propagation rules will apply instead and this will not be called. Args: World, X, 1055 * Y, Z, side. Note that the side is reversed - eg it is 1 (up) when checking the bottom of the block. 1056 */ 1057 public int isProvidingWeakPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 1058 { 1059 return 0; 1060 } 1061 1062 @SideOnly(Side.CLIENT) 1063 1064 /** 1065 * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called 1066 * when first determining what to render. 1067 */ 1068 public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 1069 { 1070 return 16777215; 1071 } 1072 1073 /** 1074 * Can this block provide power. Only wire currently seems to have this change based on its state. 1075 */ 1076 public boolean canProvidePower() 1077 { 1078 return false; 1079 } 1080 1081 /** 1082 * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity 1083 */ 1084 public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) {} 1085 1086 /** 1087 * Returns true if the block is emitting direct/strong redstone power on the specified side. Args: World, X, Y, Z, 1088 * side. Note that the side is reversed - eg it is 1 (up) when checking the bottom of the block. 1089 */ 1090 public int isProvidingStrongPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 1091 { 1092 return 0; 1093 } 1094 1095 /** 1096 * Sets the block's bounds for rendering it as an item 1097 */ 1098 public void setBlockBoundsForItemRender() {} 1099 1100 /** 1101 * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the 1102 * block and l is the block's subtype/damage. 1103 */ 1104 public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) 1105 { 1106 par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1); 1107 par2EntityPlayer.addExhaustion(0.025F); 1108 1109 if (this.canSilkHarvest(par1World, par2EntityPlayer, par3, par4, par5, par6) && EnchantmentHelper.getSilkTouchModifier(par2EntityPlayer)) 1110 { 1111 ItemStack itemstack = this.createStackedBlock(par6); 1112 1113 if (itemstack != null) 1114 { 1115 this.dropBlockAsItem_do(par1World, par3, par4, par5, itemstack); 1116 } 1117 } 1118 else 1119 { 1120 int i1 = EnchantmentHelper.getFortuneModifier(par2EntityPlayer); 1121 this.dropBlockAsItem(par1World, par3, par4, par5, par6, i1); 1122 } 1123 } 1124 1125 private int silk_check_meta = -1; //Dirty hack to stop us from needing to special case the silk check hook. 1126 /** 1127 * Return true if a player with Silk Touch can harvest this block directly, and not its normal drops. 1128 */ 1129 protected boolean canSilkHarvest() 1130 { 1131 return this.renderAsNormalBlock() && !this.hasTileEntity(silk_check_meta); 1132 } 1133 1134 /** 1135 * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage 1136 * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null. 1137 */ 1138 protected ItemStack createStackedBlock(int par1) 1139 { 1140 int j = 0; 1141 1142 if (this.blockID >= 0 && this.blockID < Item.itemsList.length && Item.itemsList[this.blockID].getHasSubtypes()) 1143 { 1144 j = par1; 1145 } 1146 1147 return new ItemStack(this.blockID, 1, j); 1148 } 1149 1150 /** 1151 * Returns the usual quantity dropped by the block plus a bonus of 1 to 'i' (inclusive). 1152 */ 1153 public int quantityDroppedWithBonus(int par1, Random par2Random) 1154 { 1155 return this.quantityDropped(par2Random); 1156 } 1157 1158 /** 1159 * Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants. 1160 */ 1161 public boolean canBlockStay(World par1World, int par2, int par3, int par4) 1162 { 1163 return true; 1164 } 1165 1166 /** 1167 * Called when the block is placed in the world. 1168 */ 1169 public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack) {} 1170 1171 /** 1172 * Called after a block is placed 1173 */ 1174 public void onPostBlockPlaced(World par1World, int par2, int par3, int par4, int par5) {} 1175 1176 public Block setUnlocalizedName(String par1Str) 1177 { 1178 this.unlocalizedName = par1Str; 1179 return this; 1180 } 1181 1182 /** 1183 * Gets the localized name of this block. Used for the statistics page. 1184 */ 1185 public String getLocalizedName() 1186 { 1187 return StatCollector.translateToLocal(this.getUnlocalizedName() + ".name"); 1188 } 1189 1190 /** 1191 * Returns the unlocalized name of this block. 1192 */ 1193 public String getUnlocalizedName() 1194 { 1195 return "tile." + this.unlocalizedName; 1196 } 1197 1198 @SideOnly(Side.CLIENT) 1199 1200 /** 1201 * Returns the unlocalized name without the tile. prefix. Caution: client-only. 1202 */ 1203 public String getUnlocalizedName2() 1204 { 1205 return this.unlocalizedName; 1206 } 1207 1208 /** 1209 * Called when the block receives a BlockEvent - see World.addBlockEvent. By default, passes it on to the tile 1210 * entity at this location. Args: world, x, y, z, blockID, EventID, event parameter 1211 */ 1212 public boolean onBlockEventReceived(World par1World, int par2, int par3, int par4, int par5, int par6) 1213 { 1214 return false; 1215 } 1216 1217 /** 1218 * Return the state of blocks statistics flags - if the block is counted for mined and placed. 1219 */ 1220 public boolean getEnableStats() 1221 { 1222 return this.enableStats; 1223 } 1224 1225 /** 1226 * Disable statistics for the block, the block will no count for mined or placed. 1227 */ 1228 protected Block disableStats() 1229 { 1230 this.enableStats = false; 1231 return this; 1232 } 1233 1234 /** 1235 * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility 1236 * and stop pistons 1237 */ 1238 public int getMobilityFlag() 1239 { 1240 return this.blockMaterial.getMaterialMobility(); 1241 } 1242 1243 @SideOnly(Side.CLIENT) 1244 1245 /** 1246 * Returns the default ambient occlusion value based on block opacity 1247 */ 1248 public float getAmbientOcclusionLightValue(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 1249 { 1250 return par1IBlockAccess.isBlockNormalCube(par2, par3, par4) ? 0.2F : 1.0F; 1251 } 1252 1253 /** 1254 * Block's chance to react to an entity falling on it. 1255 */ 1256 public void onFallenUpon(World par1World, int par2, int par3, int par4, Entity par5Entity, float par6) {} 1257 1258 @SideOnly(Side.CLIENT) 1259 1260 /** 1261 * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) 1262 */ 1263 public int idPicked(World par1World, int par2, int par3, int par4) 1264 { 1265 return this.blockID; 1266 } 1267 1268 /** 1269 * Get the block's damage value (for use with pick block). 1270 */ 1271 public int getDamageValue(World par1World, int par2, int par3, int par4) 1272 { 1273 return this.damageDropped(par1World.getBlockMetadata(par2, par3, par4)); 1274 } 1275 1276 @SideOnly(Side.CLIENT) 1277 1278 /** 1279 * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) 1280 */ 1281 public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) 1282 { 1283 par3List.add(new ItemStack(par1, 1, 0)); 1284 } 1285 1286 /** 1287 * Sets the CreativeTab to display this block on. 1288 */ 1289 public Block setCreativeTab(CreativeTabs par1CreativeTabs) 1290 { 1291 this.displayOnCreativeTab = par1CreativeTabs; 1292 return this; 1293 } 1294 1295 /** 1296 * Called when the block is attempted to be harvested 1297 */ 1298 public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer) {} 1299 1300 @SideOnly(Side.CLIENT) 1301 1302 /** 1303 * Returns the CreativeTab to display the given block on. 1304 */ 1305 public CreativeTabs getCreativeTabToDisplayOn() 1306 { 1307 return this.displayOnCreativeTab; 1308 } 1309 1310 /** 1311 * Called when this block is set (with meta data). 1312 */ 1313 public void onSetBlockIDWithMetaData(World par1World, int par2, int par3, int par4, int par5) {} 1314 1315 /** 1316 * currently only used by BlockCauldron to incrament meta-data during rain 1317 */ 1318 public void fillWithRain(World par1World, int par2, int par3, int par4) {} 1319 1320 @SideOnly(Side.CLIENT) 1321 public boolean func_82505_u_() 1322 { 1323 return false; 1324 } 1325 1326 public boolean func_82506_l() 1327 { 1328 return true; 1329 } 1330 1331 /** 1332 * Return whether this block can drop from an explosion. 1333 */ 1334 public boolean canDropFromExplosion(Explosion par1Explosion) 1335 { 1336 return true; 1337 } 1338 1339 /** 1340 * Returns true if the given block ID is equivalent to this one. Example: redstoneTorchOn matches itself and 1341 * redstoneTorchOff, and vice versa. Most blocks only match themselves. 1342 */ 1343 public boolean isAssociatedBlockID(int par1) 1344 { 1345 return this.blockID == par1; 1346 } 1347 1348 /** 1349 * Static version of isAssociatedBlockID. 1350 */ 1351 public static boolean isAssociatedBlockID(int par0, int par1) 1352 { 1353 return par0 == par1 ? true : (par0 != 0 && par1 != 0 && blocksList[par0] != null && blocksList[par1] != null ? blocksList[par0].isAssociatedBlockID(par1) : false); 1354 } 1355 1356 /** 1357 * If this returns true, then comparators facing away from this block will use the value from 1358 * getComparatorInputOverride instead of the actual redstone signal strength. 1359 */ 1360 public boolean hasComparatorInputOverride() 1361 { 1362 return false; 1363 } 1364 1365 /** 1366 * If hasComparatorInputOverride returns true, the return value from this is used instead of the redstone signal 1367 * strength when this block inputs to a comparator. 1368 */ 1369 public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5) 1370 { 1371 return 0; 1372 } 1373 1374 @SideOnly(Side.CLIENT) 1375 1376 /** 1377 * When this method is called, your block should register all the icons it needs with the given IconRegister. This 1378 * is the only chance you get to register icons. 1379 */ 1380 public void registerIcons(IconRegister par1IconRegister) 1381 { 1382 this.blockIcon = par1IconRegister.registerIcon(this.unlocalizedName); 1383 } 1384 1385 @SideOnly(Side.CLIENT) 1386 1387 /** 1388 * Gets the icon name of the ItemBlock corresponding to this block. Used by hoppers. 1389 */ 1390 public String getItemIconName() 1391 { 1392 return null; 1393 } 1394 1395 static 1396 { 1397 Item.itemsList[cloth.blockID] = (new ItemCloth(cloth.blockID - 256)).setUnlocalizedName("cloth"); 1398 Item.itemsList[wood.blockID] = (new ItemMultiTextureTile(wood.blockID - 256, wood, BlockLog.woodType)).setUnlocalizedName("log"); 1399 Item.itemsList[planks.blockID] = (new ItemMultiTextureTile(planks.blockID - 256, planks, BlockWood.woodType)).setUnlocalizedName("wood"); 1400 Item.itemsList[silverfish.blockID] = (new ItemMultiTextureTile(silverfish.blockID - 256, silverfish, BlockSilverfish.silverfishStoneTypes)).setUnlocalizedName("monsterStoneEgg"); 1401 Item.itemsList[stoneBrick.blockID] = (new ItemMultiTextureTile(stoneBrick.blockID - 256, stoneBrick, BlockStoneBrick.STONE_BRICK_TYPES)).setUnlocalizedName("stonebricksmooth"); 1402 Item.itemsList[sandStone.blockID] = (new ItemMultiTextureTile(sandStone.blockID - 256, sandStone, BlockSandStone.SAND_STONE_TYPES)).setUnlocalizedName("sandStone"); 1403 Item.itemsList[blockNetherQuartz.blockID] = (new ItemMultiTextureTile(blockNetherQuartz.blockID - 256, blockNetherQuartz, BlockQuartz.quartzBlockTypes)).setUnlocalizedName("quartzBlock"); 1404 Item.itemsList[stoneSingleSlab.blockID] = (new ItemSlab(stoneSingleSlab.blockID - 256, stoneSingleSlab, stoneDoubleSlab, false)).setUnlocalizedName("stoneSlab"); 1405 Item.itemsList[stoneDoubleSlab.blockID] = (new ItemSlab(stoneDoubleSlab.blockID - 256, stoneSingleSlab, stoneDoubleSlab, true)).setUnlocalizedName("stoneSlab"); 1406 Item.itemsList[woodSingleSlab.blockID] = (new ItemSlab(woodSingleSlab.blockID - 256, woodSingleSlab, woodDoubleSlab, false)).setUnlocalizedName("woodSlab"); 1407 Item.itemsList[woodDoubleSlab.blockID] = (new ItemSlab(woodDoubleSlab.blockID - 256, woodSingleSlab, woodDoubleSlab, true)).setUnlocalizedName("woodSlab"); 1408 Item.itemsList[sapling.blockID] = (new ItemMultiTextureTile(sapling.blockID - 256, sapling, BlockSapling.WOOD_TYPES)).setUnlocalizedName("sapling"); 1409 Item.itemsList[leaves.blockID] = (new ItemLeaves(leaves.blockID - 256)).setUnlocalizedName("leaves"); 1410 Item.itemsList[vine.blockID] = new ItemColored(vine.blockID - 256, false); 1411 Item.itemsList[tallGrass.blockID] = (new ItemColored(tallGrass.blockID - 256, true)).setBlockNames(new String[] {"shrub", "grass", "fern"}); 1412 Item.itemsList[snow.blockID] = new ItemSnow(snow.blockID - 256, snow); 1413 Item.itemsList[waterlily.blockID] = new ItemLilyPad(waterlily.blockID - 256); 1414 Item.itemsList[pistonBase.blockID] = new ItemPiston(pistonBase.blockID - 256); 1415 Item.itemsList[pistonStickyBase.blockID] = new ItemPiston(pistonStickyBase.blockID - 256); 1416 Item.itemsList[cobblestoneWall.blockID] = (new ItemMultiTextureTile(cobblestoneWall.blockID - 256, cobblestoneWall, BlockWall.types)).setUnlocalizedName("cobbleWall"); 1417 Item.itemsList[anvil.blockID] = (new ItemAnvilBlock(anvil)).setUnlocalizedName("anvil"); 1418 1419 for (int i = 0; i < 256; ++i) 1420 { 1421 if (blocksList[i] != null) 1422 { 1423 if (Item.itemsList[i] == null) 1424 { 1425 Item.itemsList[i] = new ItemBlock(i - 256); 1426 blocksList[i].initializeBlock(); 1427 } 1428 1429 boolean flag = false; 1430 1431 if (i > 0 && blocksList[i].getRenderType() == 10) 1432 { 1433 flag = true; 1434 } 1435 1436 if (i > 0 && blocksList[i] instanceof BlockHalfSlab) 1437 { 1438 flag = true; 1439 } 1440 1441 if (i == tilledField.blockID) 1442 { 1443 flag = true; 1444 } 1445 1446 if (canBlockGrass[i]) 1447 { 1448 flag = true; 1449 } 1450 1451 if (lightOpacity[i] == 0) 1452 { 1453 flag = true; 1454 } 1455 1456 useNeighborBrightness[i] = flag; 1457 } 1458 } 1459 1460 canBlockGrass[0] = true; 1461 StatList.initBreakableStats(); 1462 } 1463 1464 /* =================================================== FORGE START =====================================*/ 1465 /** 1466 * Get a light value for the block at the specified coordinates, normal ranges are between 0 and 15 1467 * 1468 * @param world The current world 1469 * @param x X Position 1470 * @param y Y position 1471 * @param z Z position 1472 * @return The light value 1473 */ 1474 public int getLightValue(IBlockAccess world, int x, int y, int z) 1475 { 1476 Block block = blocksList[world.getBlockId(x, y, z)]; 1477 if (block != null && block != this) 1478 { 1479 return block.getLightValue(world, x, y, z); 1480 } 1481 return lightValue[blockID]; 1482 } 1483 1484 /** 1485 * Checks if a player or entity can use this block to 'climb' like a ladder. 1486 * 1487 * @param world The current world 1488 * @param x X Position 1489 * @param y Y position 1490 * @param z Z position 1491 * @return True if the block should act like a ladder 1492 */ 1493 public boolean isLadder(World world, int x, int y, int z) 1494 { 1495 return false; 1496 } 1497 1498 /** 1499 * Return true if the block is a normal, solid cube. This 1500 * determines indirect power state, entity ejection from blocks, and a few 1501 * others. 1502 * 1503 * @param world The current world 1504 * @param x X Position 1505 * @param y Y position 1506 * @param z Z position 1507 * @return True if the block is a full cube 1508 */ 1509 public boolean isBlockNormalCube(World world, int x, int y, int z) 1510 { 1511 return blockMaterial.isOpaque() && renderAsNormalBlock() && !canProvidePower(); 1512 } 1513 1514 /** 1515 * Checks if the block is a solid face on the given side, used by placement logic. 1516 * 1517 * @param world The current world 1518 * @param x X Position 1519 * @param y Y position 1520 * @param z Z position 1521 * @param side The side to check 1522 * @return True if the block is solid on the specified side. 1523 */ 1524 public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) 1525 { 1526 int meta = world.getBlockMetadata(x, y, z); 1527 if (this instanceof BlockHalfSlab) 1528 { 1529 return (((meta & 8) == 8 && (side == UP)) || isOpaqueCube()); 1530 } 1531 else if (this instanceof BlockFarmland) 1532 { 1533 return (side != DOWN && side != UP); 1534 } 1535 else if (this instanceof BlockStairs) 1536 { 1537 boolean flipped = ((meta & 4) != 0); 1538 return ((meta & 3) + side.ordinal() == 5) || (side == UP && flipped); 1539 } 1540 else if (this instanceof BlockHopper && side == UP) 1541 { 1542 return true; 1543 } 1544 else if (this instanceof BlockPoweredOre) 1545 { 1546 return true; 1547 } 1548 return isBlockNormalCube(world, x, y, z); 1549 } 1550 1551 /** 1552 * Determines if a new block can be replace the space occupied by this one, 1553 * Used in the player's placement code to make the block act like water, and lava. 1554 * 1555 * @param world The current world 1556 * @param x X Position 1557 * @param y Y position 1558 * @param z Z position 1559 * @return True if the block is replaceable by another block 1560 */ 1561 public boolean isBlockReplaceable(World world, int x, int y, int z) 1562 { 1563 return blockMaterial.isReplaceable(); 1564 } 1565 1566 /** 1567 * Determines if this block should set fire and deal fire damage 1568 * to entities coming into contact with it. 1569 * 1570 * @param world The current world 1571 * @param x X Position 1572 * @param y Y position 1573 * @param z Z position 1574 * @return True if the block should deal damage 1575 */ 1576 public boolean isBlockBurning(World world, int x, int y, int z) 1577 { 1578 return false; 1579 } 1580 1581 /** 1582 * Determines this block should be treated as an air block 1583 * by the rest of the code. This method is primarily 1584 * useful for creating pure logic-blocks that will be invisible 1585 * to the player and otherwise interact as air would. 1586 * 1587 * @param world The current world 1588 * @param x X Position 1589 * @param y Y position 1590 * @param z Z position 1591 * @return True if the block considered air 1592 */ 1593 public boolean isAirBlock(World world, int x, int y, int z) 1594 { 1595 return false; 1596 } 1597 1598 /** 1599 * Determines if the player can harvest this block, obtaining it's drops when the block is destroyed. 1600 * 1601 * @param player The player damaging the block, may be null 1602 * @param meta The block's current metadata 1603 * @return True to spawn the drops 1604 */ 1605 public boolean canHarvestBlock(EntityPlayer player, int meta) 1606 { 1607 return ForgeHooks.canHarvestBlock(this, player, meta); 1608 } 1609 1610 /** 1611 * Called when a player removes a block. This is responsible for 1612 * actually destroying the block, and the block is intact at time of call. 1613 * This is called regardless of whether the player can harvest the block or 1614 * not. 1615 * 1616 * Return true if the block is actually destroyed. 1617 * 1618 * Note: When used in multiplayer, this is called on both client and 1619 * server sides! 1620 * 1621 * @param world The current world 1622 * @param player The player damaging the block, may be null 1623 * @param x X Position 1624 * @param y Y position 1625 * @param z Z position 1626 * @return True if the block is actually destroyed. 1627 */ 1628 public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z) 1629 { 1630 return world.setBlockToAir(x, y, z); 1631 } 1632 1633 /** 1634 * Called when a new CreativeContainer is opened, populate the list 1635 * with all of the items for this block you want a player in creative mode 1636 * to have access to. 1637 * 1638 * @param itemList The list of items to display on the creative inventory. 1639 */ 1640 public void addCreativeItems(ArrayList itemList) 1641 { 1642 } 1643 1644 /** 1645 * Chance that fire will spread and consume this block. 1646 * 300 being a 100% chance, 0, being a 0% chance. 1647 * 1648 * @param world The current world 1649 * @param x The blocks X position 1650 * @param y The blocks Y position 1651 * @param z The blocks Z position 1652 * @param metadata The blocks current metadata 1653 * @param face The face that the fire is coming from 1654 * @return A number ranging from 0 to 300 relating used to determine if the block will be consumed by fire 1655 */ 1656 public int getFlammability(IBlockAccess world, int x, int y, int z, int metadata, ForgeDirection face) 1657 { 1658 return blockFlammability[blockID]; 1659 } 1660 1661 /** 1662 * Called when fire is updating, checks if a block face can catch fire. 1663 * 1664 * 1665 * @param world The current world 1666 * @param x The blocks X position 1667 * @param y The blocks Y position 1668 * @param z The blocks Z position 1669 * @param metadata The blocks current metadata 1670 * @param face The face that the fire is coming from 1671 * @return True if the face can be on fire, false otherwise. 1672 */ 1673 public boolean isFlammable(IBlockAccess world, int x, int y, int z, int metadata, ForgeDirection face) 1674 { 1675 return getFlammability(world, x, y, z, metadata, face) > 0; 1676 } 1677 1678 /** 1679 * Called when fire is updating on a neighbor block. 1680 * The higher the number returned, the faster fire will spread around this block. 1681 * 1682 * @param world The current world 1683 * @param x The blocks X position 1684 * @param y The blocks Y position 1685 * @param z The blocks Z position 1686 * @param metadata The blocks current metadata 1687 * @param face The face that the fire is coming from 1688 * @return A number that is used to determine the speed of fire growth around the block 1689 */ 1690 public int getFireSpreadSpeed(World world, int x, int y, int z, int metadata, ForgeDirection face) 1691 { 1692 return blockFireSpreadSpeed[blockID]; 1693 } 1694 1695 /** 1696 * Currently only called by fire when it is on top of this block. 1697 * Returning true will prevent the fire from naturally dying during updating. 1698 * Also prevents firing from dying from rain. 1699 * 1700 * @param world The current world 1701 * @param x The blocks X position 1702 * @param y The blocks Y position 1703 * @param z The blocks Z position 1704 * @param metadata The blocks current metadata 1705 * @param side The face that the fire is coming from 1706 * @return True if this block sustains fire, meaning it will never go out. 1707 */ 1708 public boolean isFireSource(World world, int x, int y, int z, int metadata, ForgeDirection side) 1709 { 1710 if (blockID == Block.netherrack.blockID && side == UP) 1711 { 1712 return true; 1713 } 1714 if ((world.provider instanceof WorldProviderEnd) && blockID == Block.bedrock.blockID && side == UP) 1715 { 1716 return true; 1717 } 1718 return false; 1719 } 1720 1721 /** 1722 * Called by BlockFire to setup the burn values of vanilla blocks. 1723 * @param id The block id 1724 * @param encouragement How much the block encourages fire to spread 1725 * @param flammability how easy a block is to catch fire 1726 */ 1727 public static void setBurnProperties(int id, int encouragement, int flammability) 1728 { 1729 blockFireSpreadSpeed[id] = encouragement; 1730 blockFlammability[id] = flammability; 1731 } 1732 1733 private boolean isTileProvider = this instanceof ITileEntityProvider; 1734 /** 1735 * Called throughout the code as a replacement for block instanceof BlockContainer 1736 * Moving this to the Block base class allows for mods that wish to extend vinella 1737 * blocks, and also want to have a tile entity on that block, may. 1738 * 1739 * Return true from this function to specify this block has a tile entity. 1740 * 1741 * @param metadata Metadata of the current block 1742 * @return True if block has a tile entity, false otherwise 1743 */ 1744 public boolean hasTileEntity(int metadata) 1745 { 1746 return isTileProvider; 1747 } 1748 1749 /** 1750 * Called throughout the code as a replacement for ITileEntityProvider.createNewTileEntity 1751 * Return the same thing you would from that function. 1752 * This will fall back to ITileEntityProvider.createNewTileEntity(World) if this block is a ITileEntityProvider 1753 * 1754 * @param metadata The Metadata of the current block 1755 * @return A instance of a class extending TileEntity 1756 */ 1757 public TileEntity createTileEntity(World world, int metadata) 1758 { 1759 if (isTileProvider) 1760 { 1761 return ((ITileEntityProvider)this).createNewTileEntity(world); 1762 } 1763 return null; 1764 } 1765 1766 /** 1767 * Metadata and fortune sensitive version, this replaces the old (int meta, Random rand) 1768 * version in 1.1. 1769 * 1770 * @param meta Blocks Metadata 1771 * @param fortune Current item fortune level 1772 * @param random Random number generator 1773 * @return The number of items to drop 1774 */ 1775 public int quantityDropped(int meta, int fortune, Random random) 1776 { 1777 return quantityDroppedWithBonus(fortune, random); 1778 } 1779 1780 /** 1781 * This returns a complete list of items dropped from this block. 1782 * 1783 * @param world The current world 1784 * @param x X Position 1785 * @param y Y Position 1786 * @param z Z Position 1787 * @param metadata Current metadata 1788 * @param fortune Breakers fortune level 1789 * @return A ArrayList containing all items this block drops 1790 */ 1791 public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune) 1792 { 1793 ArrayList<ItemStack> ret = new ArrayList<ItemStack>(); 1794 1795 int count = quantityDropped(metadata, fortune, world.rand); 1796 for(int i = 0; i < count; i++) 1797 { 1798 int id = idDropped(metadata, world.rand, fortune); 1799 if (id > 0) 1800 { 1801 ret.add(new ItemStack(id, 1, damageDropped(metadata))); 1802 } 1803 } 1804 return ret; 1805 } 1806 1807 /** 1808 * Return true from this function if the player with silk touch can harvest this block directly, and not it's normal drops. 1809 * 1810 * @param world The world 1811 * @param player The player doing the harvesting 1812 * @param x X Position 1813 * @param y Y Position 1814 * @param z Z Position 1815 * @param metadata The metadata 1816 * @return True if the block can be directly harvested using silk touch 1817 */ 1818 public boolean canSilkHarvest(World world, EntityPlayer player, int x, int y, int z, int metadata) 1819 { 1820 silk_check_meta = metadata; 1821 boolean ret = this.canSilkHarvest(); 1822 silk_check_meta = 0; 1823 return ret; 1824 } 1825 1826 /** 1827 * Determines if a specified mob type can spawn on this block, returning false will 1828 * prevent any mob from spawning on the block. 1829 * 1830 * @param type The Mob Category Type 1831 * @param world The current world 1832 * @param x The X Position 1833 * @param y The Y Position 1834 * @param z The Z Position 1835 * @return True to allow a mob of the specified category to spawn, false to prevent it. 1836 */ 1837 public boolean canCreatureSpawn(EnumCreatureType type, World world, int x, int y, int z) 1838 { 1839 int meta = world.getBlockMetadata(x, y, z); 1840 if (this instanceof BlockStep) 1841 { 1842 return (((meta & 8) == 8) || isOpaqueCube()); 1843 } 1844 else if (this instanceof BlockStairs) 1845 { 1846 return ((meta & 4) != 0); 1847 } 1848 return isBlockSolidOnSide(world, x, y, z, UP); 1849 } 1850 1851 /** 1852 * Determines if this block is classified as a Bed, Allowing 1853 * players to sleep in it, though the block has to specifically 1854 * perform the sleeping functionality in it's activated event. 1855 * 1856 * @param world The current world 1857 * @param x X Position 1858 * @param y Y Position 1859 * @param z Z Position 1860 * @param player The player or camera entity, null in some cases. 1861 * @return True to treat this as a bed 1862 */ 1863 public boolean isBed(World world, int x, int y, int z, EntityLiving player) 1864 { 1865 return blockID == Block.bed.blockID; 1866 } 1867 1868 /** 1869 * Returns the position that the player is moved to upon 1870 * waking up, or respawning at the bed. 1871 * 1872 * @param world The current world 1873 * @param x X Position 1874 * @param y Y Position 1875 * @param z Z Position 1876 * @param player The player or camera entity, null in some cases. 1877 * @return The spawn position 1878 */ 1879 public ChunkCoordinates getBedSpawnPosition(World world, int x, int y, int z, EntityPlayer player) 1880 { 1881 return BlockBed.getNearestEmptyChunkCoordinates(world, x, y, z, 0); 1882 } 1883 1884 /** 1885 * Called when a user either starts or stops sleeping in the bed. 1886 * 1887 * @param world The current world 1888 * @param x X Position 1889 * @param y Y Position 1890 * @param z Z Position 1891 * @param player The player or camera entity, null in some cases. 1892 * @param occupied True if we are occupying the bed, or false if they are stopping use of the bed 1893 */ 1894 public void setBedOccupied(World world, int x, int y, int z, EntityPlayer player, boolean occupied) 1895 { 1896 BlockBed.setBedOccupied(world, x, y, z, occupied); 1897 } 1898 1899 /** 1900 * Returns the direction of the block. Same values that 1901 * are returned by BlockDirectional 1902 * 1903 * @param world The current world 1904 * @param x X Position 1905 * @param y Y Position 1906 * @param z Z Position 1907 * @return Bed direction 1908 */ 1909 public int getBedDirection(IBlockAccess world, int x, int y, int z) 1910 { 1911 return BlockBed.getDirection(world.getBlockMetadata(x, y, z)); 1912 } 1913 1914 /** 1915 * Determines if the current block is the foot half of the bed. 1916 * 1917 * @param world The current world 1918 * @param x X Position 1919 * @param y Y Position 1920 * @param z Z Position 1921 * @return True if the current block is the foot side of a bed. 1922 */ 1923 public boolean isBedFoot(IBlockAccess world, int x, int y, int z) 1924 { 1925 return BlockBed.isBlockHeadOfBed(world.getBlockMetadata(x, y, z)); 1926 } 1927 1928 /** 1929 * Called when a leaf should start its decay process. 1930 * 1931 * @param world The current world 1932 * @param x X Position 1933 * @param y Y Position 1934 * @param z Z Position 1935 */ 1936 public void beginLeavesDecay(World world, int x, int y, int z){} 1937 1938 /** 1939 * Determines if this block can prevent leaves connected to it from decaying. 1940 * 1941 * @param world The current world 1942 * @param x X Position 1943 * @param y Y Position 1944 * @param z Z Position 1945 * @return true if the presence this block can prevent leaves from decaying. 1946 */ 1947 public boolean canSustainLeaves(World world, int x, int y, int z) 1948 { 1949 return false; 1950 } 1951 1952 /** 1953 * Determines if this block is considered a leaf block, used to apply the leaf decay and generation system. 1954 * 1955 * @param world The current world 1956 * @param x X Position 1957 * @param y Y Position 1958 * @param z Z Position 1959 * @return true if this block is considered leaves. 1960 */ 1961 public boolean isLeaves(World world, int x, int y, int z) 1962 { 1963 return false; 1964 } 1965 1966 /** 1967 * Used during tree growth to determine if newly generated leaves can replace this block. 1968 * 1969 * @param world The current world 1970 * @param x X Position 1971 * @param y Y Position 1972 * @param z Z Position 1973 * @return true if this block can be replaced by growing leaves. 1974 */ 1975 public boolean canBeReplacedByLeaves(World world, int x, int y, int z) 1976 { 1977 return !Block.opaqueCubeLookup[this.blockID]; 1978 } 1979 1980 /** 1981 * 1982 * @param world The current world 1983 * @param x X Position 1984 * @param y Y Position 1985 * @param z Z Position 1986 * @return true if the block is wood (logs) 1987 */ 1988 public boolean isWood(World world, int x, int y, int z) 1989 { 1990 return false; 1991 } 1992 1993 /** 1994 * Determines if the current block is replaceable by Ore veins during world generation. 1995 * 1996 * @param world The current world 1997 * @param x X Position 1998 * @param y Y Position 1999 * @param z Z Position 2000 * @param target The generic target block the gen is looking for, Standards define stone 2001 * for overworld generation, and neatherack for the nether. 2002 * @return True to allow this block to be replaced by a ore 2003 */ 2004 public boolean isGenMineableReplaceable(World world, int x, int y, int z, int target) 2005 { 2006 return blockID == target; 2007 } 2008 2009 /** 2010 * Location sensitive version of getExplosionRestance 2011 * 2012 * @param par1Entity The entity that caused the explosion 2013 * @param world The current world 2014 * @param x X Position 2015 * @param y Y Position 2016 * @param z Z Position 2017 * @param explosionX Explosion source X Position 2018 * @param explosionY Explosion source X Position 2019 * @param explosionZ Explosion source X Position 2020 * @return The amount of the explosion absorbed. 2021 */ 2022 public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) 2023 { 2024 return getExplosionResistance(par1Entity); 2025 } 2026 2027 /** 2028 * Called when the block is destroyed by an explosion. 2029 * Useful for allowing the block to take into account tile entities, 2030 * metadata, etc. when exploded, before it is removed. 2031 * 2032 * @param world The current world 2033 * @param x X Position 2034 * @param y Y Position 2035 * @param z Z Position 2036 * @param Explosion The explosion instance affecting the block 2037 */ 2038 public void onBlockExploded(World world, int x, int y, int z, Explosion explosion) 2039 { 2040 world.setBlockToAir(x, y, z); 2041 onBlockDestroyedByExplosion(world, x, y, z, explosion); 2042 } 2043 2044 /** 2045 * Determine if this block can make a redstone connection on the side provided, 2046 * Useful to control which sides are inputs and outputs for redstone wires. 2047 * 2048 * Side: 2049 * -1: UP 2050 * 0: NORTH 2051 * 1: EAST 2052 * 2: SOUTH 2053 * 3: WEST 2054 * 2055 * @param world The current world 2056 * @param x X Position 2057 * @param y Y Position 2058 * @param z Z Position 2059 * @param side The side that is trying to make the connection 2060 * @return True to make the connection 2061 */ 2062 public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) 2063 { 2064 return Block.blocksList[blockID].canProvidePower() && side != -1; 2065 } 2066 2067 /** 2068 * Determines if a torch can be placed on the top surface of this block. 2069 * Useful for creating your own block that torches can be on, such as fences. 2070 * 2071 * @param world The current world 2072 * @param x X Position 2073 * @param y Y Position 2074 * @param z Z Position 2075 * @return True to allow the torch to be placed 2076 */ 2077 public boolean canPlaceTorchOnTop(World world, int x, int y, int z) 2078 { 2079 if (world.doesBlockHaveSolidTopSurface(x, y, z)) 2080 { 2081 return true; 2082 } 2083 else 2084 { 2085 int id = world.getBlockId(x, y, z); 2086 return id == Block.fence.blockID || id == Block.netherFence.blockID || id == Block.glass.blockID || id == Block.cobblestoneWall.blockID; 2087 } 2088 } 2089 2090 2091 /** 2092 * Determines if this block should render in this pass. 2093 * 2094 * @param pass The pass in question 2095 * @return True to render 2096 */ 2097 public boolean canRenderInPass(int pass) 2098 { 2099 return pass == getRenderBlockPass(); 2100 } 2101 2102 /** 2103 * Called when a user uses the creative pick block button on this block 2104 * 2105 * @param target The full target the player is looking at 2106 * @return A ItemStack to add to the player's inventory, Null if nothing should be added. 2107 */ 2108 public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) 2109 { 2110 int id = idPicked(world, x, y, z); 2111 2112 if (id == 0) 2113 { 2114 return null; 2115 } 2116 2117 Item item = Item.itemsList[id]; 2118 if (item == null) 2119 { 2120 return null; 2121 } 2122 2123 return new ItemStack(id, 1, getDamageValue(world, x, y, z)); 2124 } 2125 2126 /** 2127 * Used by getTopSolidOrLiquidBlock while placing biome decorations, villages, etc 2128 * Also used to determine if the player can spawn on this block. 2129 * 2130 * @return False to disallow spawning 2131 */ 2132 public boolean isBlockFoliage(World world, int x, int y, int z) 2133 { 2134 return false; 2135 } 2136 2137 /** 2138 * Spawn a digging particle effect in the world, this is a wrapper 2139 * around EffectRenderer.addBlockHitEffects to allow the block more 2140 * control over the particles. Useful when you have entirely different 2141 * texture sheets for different sides/locations in the world. 2142 * 2143 * @param world The current world 2144 * @param target The target the player is looking at {x/y/z/side/sub} 2145 * @param effectRenderer A reference to the current effect renderer. 2146 * @return True to prevent vanilla digging particles form spawning. 2147 */ 2148 @SideOnly(Side.CLIENT) 2149 public boolean addBlockHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) 2150 { 2151 return false; 2152 } 2153 2154 /** 2155 * Spawn particles for when the block is destroyed. Due to the nature 2156 * of how this is invoked, the x/y/z locations are not always guaranteed 2157 * to host your block. So be sure to do proper sanity checks before assuming 2158 * that the location is this block. 2159 * 2160 * @param world The current world 2161 * @param x X position to spawn the particle 2162 * @param y Y position to spawn the particle 2163 * @param z Z position to spawn the particle 2164 * @param meta The metadata for the block before it was destroyed. 2165 * @param effectRenderer A reference to the current effect renderer. 2166 * @return True to prevent vanilla break particles from spawning. 2167 */ 2168 @SideOnly(Side.CLIENT) 2169 public boolean addBlockDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) 2170 { 2171 return false; 2172 } 2173 2174 /** 2175 * Determines if this block can support the passed in plant, allowing it to be planted and grow. 2176 * Some examples: 2177 * Reeds check if its a reed, or if its sand/dirt/grass and adjacent to water 2178 * Cacti checks if its a cacti, or if its sand 2179 * Nether types check for soul sand 2180 * Crops check for tilled soil 2181 * Caves check if it's a colid surface 2182 * Plains check if its grass or dirt 2183 * Water check if its still water 2184 * 2185 * @param world The current world 2186 * @param x X Position 2187 * @param y Y Position 2188 * @param z Z position 2189 * @param direction The direction relative to the given position the plant wants to be, typically its UP 2190 * @param plant The plant that wants to check 2191 * @return True to allow the plant to be planted/stay. 2192 */ 2193 public boolean canSustainPlant(World world, int x, int y, int z, ForgeDirection direction, IPlantable plant) 2194 { 2195 int plantID = plant.getPlantID(world, x, y + 1, z); 2196 EnumPlantType plantType = plant.getPlantType(world, x, y + 1, z); 2197 2198 if (plantID == cactus.blockID && blockID == cactus.blockID) 2199 { 2200 return true; 2201 } 2202 2203 if (plantID == reed.blockID && blockID == reed.blockID) 2204 { 2205 return true; 2206 } 2207 2208 if (plant instanceof BlockFlower && ((BlockFlower)plant).canThisPlantGrowOnThisBlockID(blockID)) 2209 { 2210 return true; 2211 } 2212 2213 switch (plantType) 2214 { 2215 case Desert: return blockID == sand.blockID; 2216 case Nether: return blockID == slowSand.blockID; 2217 case Crop: return blockID == tilledField.blockID; 2218 case Cave: return isBlockSolidOnSide(world, x, y, z, UP); 2219 case Plains: return blockID == grass.blockID || blockID == dirt.blockID; 2220 case Water: return world.getBlockMaterial(x, y, z) == Material.water && world.getBlockMetadata(x, y, z) == 0; 2221 case Beach: 2222 boolean isBeach = (blockID == Block.grass.blockID || blockID == Block.dirt.blockID || blockID == Block.sand.blockID); 2223 boolean hasWater = (world.getBlockMaterial(x - 1, y, z ) == Material.water || 2224 world.getBlockMaterial(x + 1, y, z ) == Material.water || 2225 world.getBlockMaterial(x, y, z - 1) == Material.water || 2226 world.getBlockMaterial(x, y, z + 1) == Material.water); 2227 return isBeach && hasWater; 2228 } 2229 2230 return false; 2231 } 2232 2233 /** 2234 * Called when a plant grows on this block, only implemented for saplings using the WorldGen*Trees classes right now. 2235 * Modder may implement this for custom plants. 2236 * This does not use ForgeDirection, because large/huge trees can be located in non-representable direction, 2237 * so the source location is specified. 2238 * Currently this just changes the block to dirt if it was grass. 2239 * 2240 * Note: This happens DURING the generation, the generation may not be complete when this is called. 2241 * 2242 * @param world Current world 2243 * @param x Soil X 2244 * @param y Soil Y 2245 * @param z Soil Z 2246 * @param sourceX Plant growth location X 2247 * @param sourceY Plant growth location Y 2248 * @param sourceZ Plant growth location Z 2249 */ 2250 public void onPlantGrow(World world, int x, int y, int z, int sourceX, int sourceY, int sourceZ) 2251 { 2252 if (blockID == grass.blockID) 2253 { 2254 world.setBlock(x, y, z, dirt.blockID, 0, 2); 2255 } 2256 } 2257 2258 /** 2259 * Checks if this soil is fertile, typically this means that growth rates 2260 * of plants on this soil will be slightly sped up. 2261 * Only vanilla case is tilledField when it is within range of water. 2262 * 2263 * @param world The current world 2264 * @param x X Position 2265 * @param y Y Position 2266 * @param z Z position 2267 * @return True if the soil should be considered fertile. 2268 */ 2269 public boolean isFertile(World world, int x, int y, int z) 2270 { 2271 if (blockID == tilledField.blockID) 2272 { 2273 return world.getBlockMetadata(x, y, z) > 0; 2274 } 2275 2276 return false; 2277 } 2278 2279 /** 2280 * Location aware and overrideable version of the lightOpacity array, 2281 * return the number to subtract from the light value when it passes through this block. 2282 * 2283 * This is not guaranteed to have the tile entity in place before this is called, so it is 2284 * Recommended that you have your tile entity call relight after being placed if you 2285 * rely on it for light info. 2286 * 2287 * @param world The current world 2288 * @param x X Position 2289 * @param y Y Position 2290 * @param z Z position 2291 * @return The amount of light to block, 0 for air, 255 for fully opaque. 2292 */ 2293 public int getLightOpacity(World world, int x, int y, int z) 2294 { 2295 return lightOpacity[blockID]; 2296 } 2297 2298 /** 2299 * Determines if this block is destroyed when a ender dragon tries to fly through it. 2300 * The block will be set to 0, nothing will drop. 2301 * 2302 * @param world The current world 2303 * @param x X Position 2304 * @param y Y Position 2305 * @param z Z position 2306 * @return True to allow the ender dragon to destroy this block 2307 */ 2308 public boolean canDragonDestroy(World world, int x, int y, int z) 2309 { 2310 return blockID != obsidian.blockID && blockID != whiteStone.blockID && blockID != bedrock.blockID; 2311 } 2312 2313 /** 2314 * Determines if this block can be used as the base of a beacon. 2315 * 2316 * @param world The current world 2317 * @param x X Position 2318 * @param y Y Position 2319 * @param z Z position 2320 * @param beaconX Beacons X Position 2321 * @param beaconY Beacons Y Position 2322 * @param beaconZ Beacons Z Position 2323 * @return True, to support the beacon, and make it active with this block. 2324 */ 2325 public boolean isBeaconBase(World worldObj, int x, int y, int z, int beaconX, int beaconY, int beaconZ) 2326 { 2327 return (blockID == blockEmerald.blockID || blockID == blockGold.blockID || blockID == blockDiamond.blockID || blockID == blockIron.blockID); 2328 } 2329 2330 /** 2331 * Rotate the block. For vanilla blocks this rotates around the axis passed in (generally, it should be the "face" that was hit). 2332 * Note: for mod blocks, this is up to the block and modder to decide. It is not mandated that it be a rotation around the 2333 * face, but could be a rotation to orient *to* that face, or a visiting of possible rotations. 2334 * The method should return true if the rotation was successful though. 2335 * 2336 * @param worldObj The world 2337 * @param x X position 2338 * @param y Y position 2339 * @param z Z position 2340 * @param axis The axis to rotate around 2341 * @return True if the rotation was successful, False if the rotation failed, or is not possible 2342 */ 2343 public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis) 2344 { 2345 return RotationHelper.rotateVanillaBlock(this, worldObj, x, y, z, axis); 2346 } 2347 2348 /** 2349 * Get the rotations that can apply to the block at the specified coordinates. Null means no rotations are possible. 2350 * Note, this is up to the block to decide. It may not be accurate or representative. 2351 * @param worldObj The world 2352 * @param x X position 2353 * @param y Y position 2354 * @param z Z position 2355 * @return An array of valid axes to rotate around, or null for none or unknown 2356 */ 2357 public ForgeDirection[] getValidRotations(World worldObj, int x, int y, int z) 2358 { 2359 return RotationHelper.getValidVanillaBlockRotations(this); 2360 } 2361 2362 /** 2363 * Determines the amount of enchanting power this block can provide to an enchanting table. 2364 * @param world The World 2365 * @param x X position 2366 * @param y Y position 2367 * @param z Z position 2368 * @return The amount of enchanting power this block produces. 2369 */ 2370 public float getEnchantPowerBonus(World world, int x, int y, int z) 2371 { 2372 return getEnchantPower(world, x, y, z); 2373 } 2374 2375 @Deprecated //Changed return to float, see above. 2376 public int getEnchantPower(World world, int x, int y, int z) 2377 { 2378 return blockID == bookShelf.blockID ? 1 : 0; 2379 } 2380 /** 2381 * Common way to recolour a block with an external tool 2382 * @param world The world 2383 * @param x X 2384 * @param y Y 2385 * @param z Z 2386 * @param side The side hit with the colouring tool 2387 * @param colour The colour to change to 2388 * @return If the recolouring was successful 2389 */ 2390 public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour) 2391 { 2392 if (blockID == cloth.blockID) 2393 { 2394 int meta = world.getBlockMetadata(x, y, z); 2395 if (meta != colour) 2396 { 2397 world.setBlockMetadataWithNotify(x, y, z, colour, 3); 2398 return true; 2399 } 2400 } 2401 return false; 2402 } 2403}