From 1364d489f92a49d7072d352d2c92c3154e767281 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Mon, 30 Jun 2014 05:00:56 +0100 Subject: [PATCH] The Terra Firma Rod now uses ore dictionary names rather than block references. --- .../botania/common/block/ModBlocks.java | 10 + .../botania/common/item/ItemTerraformRod.java | 215 +++++++++--------- 2 files changed, 120 insertions(+), 105 deletions(-) diff --git a/MODSRC/vazkii/botania/common/block/ModBlocks.java b/MODSRC/vazkii/botania/common/block/ModBlocks.java index 777437504..b1fd646a3 100644 --- a/MODSRC/vazkii/botania/common/block/ModBlocks.java +++ b/MODSRC/vazkii/botania/common/block/ModBlocks.java @@ -13,6 +13,7 @@ package vazkii.botania.common.block; import net.minecraft.block.Block; import net.minecraft.block.BlockDispenser; +import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -322,6 +323,15 @@ public final class ModBlocks { OreDictionary.registerOre(LibOreDict.LIVING_WOOD, livingwood); OreDictionary.registerOre(LibOreDict.DREAM_WOOD, dreamwood); + // Vanilla OreDict entries + OreDictionary.registerOre("dirt", Blocks.dirt); + OreDictionary.registerOre("grass", Blocks.grass); + OreDictionary.registerOre("sand", Blocks.sand); + OreDictionary.registerOre("gravel", Blocks.gravel); + OreDictionary.registerOre("hardenedClay", new ItemStack(Blocks.hardened_clay, 1, OreDictionary.WILDCARD_VALUE)); + OreDictionary.registerOre("snowLayer", Blocks.snow_layer); + OreDictionary.registerOre("mycelium", Blocks.mycelium); + initTileEntities(); } diff --git a/MODSRC/vazkii/botania/common/item/ItemTerraformRod.java b/MODSRC/vazkii/botania/common/item/ItemTerraformRod.java index 6fedb29c0..bed4f0ca8 100644 --- a/MODSRC/vazkii/botania/common/item/ItemTerraformRod.java +++ b/MODSRC/vazkii/botania/common/item/ItemTerraformRod.java @@ -23,6 +23,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.oredict.OreDictionary; import vazkii.botania.api.mana.IManaUsingItem; import vazkii.botania.api.mana.ManaItemHandler; import vazkii.botania.api.subtile.ISpecialFlower; @@ -34,136 +35,140 @@ public class ItemTerraformRod extends ItemMod implements IManaUsingItem { private static final int COST_PER = 55; - static final List validBlocks = new ArrayList() {private static final long serialVersionUID = 1378413169035169782L; + static final List validBlocks = new ArrayList() { + { + add("stone"); + add("dirt"); + add("grass"); + add("sand"); + add("gravel"); + add("hardenedClay"); + add("snowLayer"); + add("mycelium"); + add("sandstone"); + }}; - { - add(Blocks.stone); - add(Blocks.dirt); - add(Blocks.grass); - add(Blocks.sand); - add(Blocks.gravel); - add(Blocks.hardened_clay); - add(Blocks.snow_layer); - add(Blocks.mycelium); - add(Blocks.sandstone); - }}; + public ItemTerraformRod() { + super(); + setMaxStackSize(1); + setUnlocalizedName(LibItemNames.TERRAFORM_ROD); + } - public ItemTerraformRod() { - super(); - setMaxStackSize(1); - setUnlocalizedName(LibItemNames.TERRAFORM_ROD); - } + @Override + public EnumAction getItemUseAction(ItemStack par1ItemStack) { + return EnumAction.bow; + } - @Override - public EnumAction getItemUseAction(ItemStack par1ItemStack) { - return EnumAction.bow; - } + @Override + public int getMaxItemUseDuration(ItemStack par1ItemStack) { + return 72000; + } - @Override - public int getMaxItemUseDuration(ItemStack par1ItemStack) { - return 72000; - } + @Override + public void onUsingTick(ItemStack stack, EntityPlayer player, int count) { + if(count != getMaxItemUseDuration(stack) && count % 10 == 0) + terraform(stack, player.worldObj, player); + } - @Override - public void onUsingTick(ItemStack stack, EntityPlayer player, int count) { - if(count != getMaxItemUseDuration(stack) && count % 10 == 0) - terraform(stack, player.worldObj, player); - } + @Override + public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { + par3EntityPlayer.setItemInUse(par1ItemStack, getMaxItemUseDuration(par1ItemStack)); + return par1ItemStack; + } - @Override - public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { - par3EntityPlayer.setItemInUse(par1ItemStack, getMaxItemUseDuration(par1ItemStack)); - return par1ItemStack; - } + public void terraform(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { + int range = 16; - public void terraform(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { - int range = 16; + int xCenter = (int) par3EntityPlayer.posX; + int yCenter = (int) par3EntityPlayer.posY - (par2World.isRemote ? 2 : 1); + int zCenter = (int) par3EntityPlayer.posZ; - int xCenter = (int) par3EntityPlayer.posX; - int yCenter = (int) par3EntityPlayer.posY - (par2World.isRemote ? 2 : 1); - int zCenter = (int) par3EntityPlayer.posZ; + int yStart = yCenter + range; - int yStart = yCenter + range; + List blocks = new ArrayList(); - List blocks = new ArrayList(); + for(int i = -range; i < range + 1; i++) + for(int j = -range; j < range + 1; j++) { + int k = 0; + while(true) { + if(yStart + k < 0) + break; - for(int i = -range; i < range + 1; i++) - for(int j = -range; j < range + 1; j++) { - int k = 0; - while(true) { - if(yStart + k < 0) - break; + int x = xCenter + i; + int y = yStart + k; + int z = zCenter + j; - int x = xCenter + i; - int y = yStart + k; - int z = zCenter + j; + Block block = par2World.getBlock(x, y, z); + int meta = par2World.getBlockMetadata(x, y, z); - Block block = par2World.getBlock(x, y, z); - if(validBlocks.contains(block)) { - boolean hasAir = false; - List airBlocks = new ArrayList(); + int[] ids = OreDictionary.getOreIDs(new ItemStack(block, 1, meta)); + for(int id : ids) + if(validBlocks.contains(OreDictionary.getOreName(id))) { - for(ForgeDirection dir : LibMisc.CARDINAL_DIRECTIONS) { - int x_ = x + dir.offsetX; - int y_ = y + dir.offsetY; - int z_ = z + dir.offsetZ; + boolean hasAir = false; + List airBlocks = new ArrayList(); - Block block_ = par2World.getBlock(x_, y_, z_); - if(block_.isAir(par2World, x_, y_, z_) || block_.isReplaceable(par2World, x_, y_, z_) || block_ instanceof BlockFlower && !(block_ instanceof ISpecialFlower) || block_ == Blocks.double_plant) { - airBlocks.add(new ChunkCoordinates(x_, y_, z_)); - hasAir = true; + for(ForgeDirection dir : LibMisc.CARDINAL_DIRECTIONS) { + int x_ = x + dir.offsetX; + int y_ = y + dir.offsetY; + int z_ = z + dir.offsetZ; + + Block block_ = par2World.getBlock(x_, y_, z_); + if(block_.isAir(par2World, x_, y_, z_) || block_.isReplaceable(par2World, x_, y_, z_) || block_ instanceof BlockFlower && !(block_ instanceof ISpecialFlower) || block_ == Blocks.double_plant) { + airBlocks.add(new ChunkCoordinates(x_, y_, z_)); + hasAir = true; + } + } + + if(hasAir) { + if(y > yCenter) + blocks.add(new CoordsWithBlock(x, y, z, Blocks.air)); + else for(ChunkCoordinates coords : airBlocks) { + if(par2World.getBlock(coords.posX, coords.posY - 1, coords.posZ) != Blocks.air) + blocks.add(new CoordsWithBlock(coords.posX, coords.posY, coords.posZ, Blocks.dirt)); + } + } + break; } - } - - if(hasAir) { - if(y > yCenter) - blocks.add(new CoordsWithBlock(x, y, z, Blocks.air)); - else for(ChunkCoordinates coords : airBlocks) { - if(par2World.getBlock(coords.posX, coords.posY - 1, coords.posZ) != Blocks.air) - blocks.add(new CoordsWithBlock(coords.posX, coords.posY, coords.posZ, Blocks.dirt)); - } - } - break; + --k; } - --k; + } + + int cost = COST_PER * blocks.size(); + + if(par2World.isRemote || ManaItemHandler.requestManaExact(par1ItemStack, par3EntityPlayer, cost, true)) { + if(!par2World.isRemote) + for(CoordsWithBlock block : blocks) + par2World.setBlock(block.posX, block.posY, block.posZ, block.block); + + if(!blocks.isEmpty()) { + for(int i = 0; i < 10; i++) + par2World.playSoundAtEntity(par3EntityPlayer, "step.sand", 1F, 0.4F); + for(int i = 0; i < 120; i++) + Botania.proxy.sparkleFX(par2World, xCenter - range + range * 2 * Math.random(), yCenter + 2 + (Math.random() - 0.5) * 2, zCenter - range + range * 2 * Math.random(), 0.35F, 0.2F, 0.05F, 2F, 5); } } + } - int cost = COST_PER * blocks.size(); + @Override + public boolean isFull3D() { + return true; + } - if(par2World.isRemote || ManaItemHandler.requestManaExact(par1ItemStack, par3EntityPlayer, cost, true)) { - if(!par2World.isRemote) - for(CoordsWithBlock block : blocks) - par2World.setBlock(block.posX, block.posY, block.posZ, block.block); + class CoordsWithBlock extends ChunkCoordinates { - if(!blocks.isEmpty()) { - for(int i = 0; i < 10; i++) - par2World.playSoundAtEntity(par3EntityPlayer, "step.sand", 1F, 0.4F); - for(int i = 0; i < 120; i++) - Botania.proxy.sparkleFX(par2World, xCenter - range + range * 2 * Math.random(), yCenter + 2 + (Math.random() - 0.5) * 2, zCenter - range + range * 2 * Math.random(), 0.35F, 0.2F, 0.05F, 2F, 5); + final Block block; + + public CoordsWithBlock(int x, int y, int z, Block block) { + super(x, y, z); + this.block = block; } - } - } - @Override - public boolean isFull3D() { - return true; - } - - class CoordsWithBlock extends ChunkCoordinates { - - final Block block; - - public CoordsWithBlock(int x, int y, int z, Block block) { - super(x, y, z); - this.block = block; } - } - - @Override - public boolean usesMana(ItemStack stack) { - return true; - } + @Override + public boolean usesMana(ItemStack stack) { + return true; + } }