From 85447fb6c7cfdeed316c74c7f337dd08935b7aae Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Sat, 25 Jul 2015 18:04:49 +0100 Subject: [PATCH] Added the ability to add Emeralds to the Cocoon of Caprice to influence the outcome. --- .../botania/common/block/BlockCocoon.java | 14 ++++ .../botania/common/block/tile/TileCocoon.java | 80 +++++++++++-------- .../botania/common/lexicon/LexiconData.java | 2 +- .../resources/assets/botania/lang/en_US.lang | 5 +- 4 files changed, 66 insertions(+), 35 deletions(-) diff --git a/src/main/java/vazkii/botania/common/block/BlockCocoon.java b/src/main/java/vazkii/botania/common/block/BlockCocoon.java index f2d031715..a6791552a 100644 --- a/src/main/java/vazkii/botania/common/block/BlockCocoon.java +++ b/src/main/java/vazkii/botania/common/block/BlockCocoon.java @@ -23,6 +23,7 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; @@ -66,6 +67,19 @@ public class BlockCocoon extends BlockModContainer implements ILexiconable { return LibRenderIDs.idCocoon; } + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int s, float xs, float ys, float zs) { + TileCocoon cocoon = (TileCocoon) world.getTileEntity(x, y, z); + ItemStack item = player.getCurrentEquippedItem(); + if(cocoon.emeraldsGiven < TileCocoon.MAX_EMERALDS && item != null && item.getItem() == Items.emerald) { + if(!player.capabilities.isCreativeMode) + item.stackSize--; + cocoon.emeraldsGiven++; + world.playAuxSFX(2005, x, y, z, 6 + world.rand.nextInt(4)); + } + return false; + } + @Override public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { return new ArrayList(); diff --git a/src/main/java/vazkii/botania/common/block/tile/TileCocoon.java b/src/main/java/vazkii/botania/common/block/tile/TileCocoon.java index 41b1b3669..d7c51b964 100644 --- a/src/main/java/vazkii/botania/common/block/tile/TileCocoon.java +++ b/src/main/java/vazkii/botania/common/block/tile/TileCocoon.java @@ -10,7 +10,9 @@ */ package vazkii.botania.common.block.tile; +import cpw.mods.fml.common.registry.VillagerRegistry; import net.minecraft.block.Block; +import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityChicken; @@ -20,16 +22,20 @@ import net.minecraft.entity.passive.EntityMooshroom; import net.minecraft.entity.passive.EntityOcelot; import net.minecraft.entity.passive.EntityPig; import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.passive.EntityWolf; import net.minecraft.nbt.NBTTagCompound; public class TileCocoon extends TileMod { private static final String TAG_TIME_PASSED = "timePassed"; - + private static final String TAG_EMERALDS_GIVEN = "timePassed"; + public static final int TOTAL_TIME = 2400; + public static final int MAX_EMERALDS = 20; public int timePassed; + public int emeraldsGiven; @Override public void updateEntity() { @@ -43,39 +49,47 @@ public class TileCocoon extends TileMod { worldObj.playAuxSFX(2001, xCoord, yCoord, zCoord, Block.getIdFromBlock(getBlockType())); worldObj.setBlockToAir(xCoord, yCoord, zCoord); - EntityAnimal entity = null; + EntityAgeable entity = null; - float specialChance = 0.05F; - if(Math.random() < specialChance) { - int entityType = worldObj.rand.nextInt(3); - switch(entityType) { - case 0: - entity = new EntityHorse(worldObj); - break; - case 1: - entity = new EntityWolf(worldObj); - break; - case 2: - entity = new EntityOcelot(worldObj); - break; - } + float villagerChance = Math.min(1F, (float) emeraldsGiven / (float) MAX_EMERALDS); + + if(Math.random() < villagerChance) { + EntityVillager villager = new EntityVillager(worldObj); + VillagerRegistry.applyRandomTrade(villager, worldObj.rand); + entity = villager; } else { - int entityType = worldObj.rand.nextInt(4); - switch(entityType) { - case 0: - entity = new EntitySheep(worldObj); - break; - case 1: - if(Math.random() < 0.01) - entity = new EntityMooshroom(worldObj); - else entity = new EntityCow(worldObj); - break; - case 2: - entity = new EntityPig(worldObj); - break; - case 3: - entity = new EntityChicken(worldObj); - break; + float specialChance = 0.05F; + if(Math.random() < specialChance) { + int entityType = worldObj.rand.nextInt(3); + switch(entityType) { + case 0: + entity = new EntityHorse(worldObj); + break; + case 1: + entity = new EntityWolf(worldObj); + break; + case 2: + entity = new EntityOcelot(worldObj); + break; + } + } else { + int entityType = worldObj.rand.nextInt(4); + switch(entityType) { + case 0: + entity = new EntitySheep(worldObj); + break; + case 1: + if(Math.random() < 0.01) + entity = new EntityMooshroom(worldObj); + else entity = new EntityCow(worldObj); + break; + case 2: + entity = new EntityPig(worldObj); + break; + case 3: + entity = new EntityChicken(worldObj); + break; + } } } @@ -91,11 +105,13 @@ public class TileCocoon extends TileMod { @Override public void writeCustomNBT(NBTTagCompound cmp) { cmp.setInteger(TAG_TIME_PASSED, timePassed); + cmp.setInteger(TAG_EMERALDS_GIVEN, emeraldsGiven); } @Override public void readCustomNBT(NBTTagCompound cmp) { timePassed = cmp.getInteger(TAG_TIME_PASSED); + emeraldsGiven = cmp.getInteger(TAG_EMERALDS_GIVEN); } } diff --git a/src/main/java/vazkii/botania/common/lexicon/LexiconData.java b/src/main/java/vazkii/botania/common/lexicon/LexiconData.java index f87e2b00a..2e2ecac26 100644 --- a/src/main/java/vazkii/botania/common/lexicon/LexiconData.java +++ b/src/main/java/vazkii/botania/common/lexicon/LexiconData.java @@ -619,7 +619,7 @@ public final class LexiconData { canopyDrum.setLexiconPages(new PageText("0"), new PageCraftingRecipe("1", ModCraftingRecipes.recipeCanopyDrum)); cocoon = Botania.gardenOfGlassLoaded ? new BLexiconEntry(LibLexicon.DEVICE_COCOON, categoryDevices) : new ALexiconEntry(LibLexicon.DEVICE_COCOON, categoryDevices); - cocoon.setLexiconPages(new PageText("0"), new PageCraftingRecipe("1", ModCraftingRecipes.recipeCocoon)); + cocoon.setLexiconPages(new PageText("0"), new PageText("1"), new PageCraftingRecipe("2", ModCraftingRecipes.recipeCocoon)); manaBomb = new ALexiconEntry(LibLexicon.DEVICE_MANA_BOMB, categoryDevices); manaBomb.setLexiconPages(new PageText("0"), new PageCraftingRecipe("1", ModCraftingRecipes.recipeManaBomb)); diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index 2ef333789..25c592e5b 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -2224,8 +2224,9 @@ botania.page.canopyDrum1=The Pinking Drum # -- COCOON OF CAPRICE botania.entry.cocoon=Cocoon of Caprice -botania.page.cocoon0=A cocoon is usually a symbol of change, of evolution.
Creating a &1Cocoon of Carpice&0 and placing it down will slowly evolve the rudimentary contents inside it into a &1Baby Animal&0. More often than not the animal hatched will be a farm animal, but on rare ocasions, different animals such as &1Wolves&0 or &1Horses&0 may be created. -botania.page.cocoon1=New World, Perfect World +botania.page.cocoon0=A cocoon is usually a symbol of change, of evolution.
Creating a &1Cocoon of Carpice&0 and placing it down will slowly evolve the rudimentary contents inside it into a &1Baby Animal&0. More often than not the animal hatched will be a farm animal, but on rare ocasions, different animals such as &1Wolves&0 or &1Horses&0 may be created. +botania.page.cocoon1=Speculation says that giving the cocoon &1Emeralds&0 influences the outcome towards something a bit different.
What could come out of such experiment is anyone's guess, really. +botania.page.cocoon2=New World, Perfect World # -- MANASTORM CHARGE botania.entry.manaBomb=Manastorm Charge