Cocoon may now spawn something else

This commit is contained in:
Vincent Lee committed 2017-01-23 12:56:26 -06:00
1 parent 4e9109f9bd
commit 888a8fd19b
3 files changed
+44 -13

No files matched your search

@@ -15,20 +15,24 @@ import java.util.List;
import javax.annotation.Nonnull;
import mezz.jei.util.FakeClientWorld;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import vazkii.botania.api.lexicon.ILexiconable;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.common.block.tile.TileCocoon;
@@ -71,13 +75,27 @@ public class BlockCocoon extends BlockMod implements ILexiconable {
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing s, float xs, float ys, float zs) {
TileCocoon cocoon = (TileCocoon) world.getTileEntity(pos);
ItemStack item = player.getHeldItem(hand);
if(cocoon.emeraldsGiven < TileCocoon.MAX_EMERALDS && !item.isEmpty() && item.getItem() == Items.EMERALD) {
if(!player.capabilities.isCreativeMode)
item.shrink(1);
cocoon.emeraldsGiven++;
world.playEvent(2005, pos, 6 + world.rand.nextInt(4));
ItemStack stack = player.getHeldItem(hand);
Item item = stack.getItem();
if(cocoon != null && (item == Items.EMERALD || item == Items.CHORUS_FRUIT)) {
if(!world.isRemote) {
if(item == Items.EMERALD && cocoon.emeraldsGiven < TileCocoon.MAX_EMERALDS) {
if(!player.capabilities.isCreativeMode)
stack.shrink(1);
cocoon.emeraldsGiven++;
world.playEvent(2005, pos, 6 + world.rand.nextInt(4));
} else if(item == Items.CHORUS_FRUIT && cocoon.chorusFruitGiven < TileCocoon.MAX_CHORUS_FRUITS) {
if(!player.capabilities.isCreativeMode)
stack.shrink(1);
cocoon.chorusFruitGiven++;
((WorldServer) world).spawnParticle(EnumParticleTypes.PORTAL, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 32, 0, 0, 0, 0.5);
}
}
return true;
}
return false;
}
@@ -10,8 +10,9 @@
*/
package vazkii.botania.common.block.tile;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.monster.EntityShulker;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.passive.EntityHorse;
@@ -22,19 +23,26 @@ import net.minecraft.entity.passive.EntityRabbit;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraftforge.fml.common.registry.VillagerRegistry;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import vazkii.botania.common.lib.LibObfuscation;
public class TileCocoon extends TileMod {
private static final String TAG_TIME_PASSED = "timePassed";
private static final String TAG_EMERALDS_GIVEN = "emeraldsGiven";
private static final String TAG_CHORUS_FRUIT_GIVEN = "chorusFruitGiven";
public static final int TOTAL_TIME = 2400;
public static final int MAX_EMERALDS = 20;
public static final int MAX_CHORUS_FRUITS = 20;
public int timePassed;
public int emeraldsGiven;
public int chorusFruitGiven;
@Override
public void update() {
@@ -45,14 +53,16 @@ public class TileCocoon extends TileMod {
private void hatch() {
if(!world.isRemote) {
world.playEvent(2001, pos, Block.getStateId(getBlockType().getStateFromMeta(getBlockMetadata())));
world.setBlockToAir(pos);
world.destroyBlock(pos, false);
EntityAgeable entity = null;
EntityLiving entity = null;
float villagerChance = Math.min(1F, (float) emeraldsGiven / (float) MAX_EMERALDS);
float shulkerChance = Math.min(1F, (float) chorusFruitGiven / (float) MAX_CHORUS_FRUITS);
if(Math.random() < villagerChance) {
if(Math.random() < shulkerChance) {
entity = new EntityShulker(world);
} else if(Math.random() < villagerChance) {
EntityVillager villager = new EntityVillager(world);
VillagerRegistry.setRandomProfession(villager, world.rand);
entity = villager;
@@ -97,7 +107,8 @@ public class TileCocoon extends TileMod {
if(entity != null) {
entity.setPosition(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
entity.setGrowingAge(-24000);
if(entity instanceof EntityAgeable)
((EntityAgeable) entity).setGrowingAge(-24000);
world.spawnEntity(entity);
entity.spawnExplosionParticle();
}
@@ -108,12 +119,14 @@ public class TileCocoon extends TileMod {
public void writePacketNBT(NBTTagCompound cmp) {
cmp.setInteger(TAG_TIME_PASSED, timePassed);
cmp.setInteger(TAG_EMERALDS_GIVEN, emeraldsGiven);
cmp.setInteger(TAG_CHORUS_FRUIT_GIVEN, chorusFruitGiven);
}
@Override
public void readPacketNBT(NBTTagCompound cmp) {
timePassed = cmp.getInteger(TAG_TIME_PASSED);
emeraldsGiven = cmp.getInteger(TAG_EMERALDS_GIVEN);
chorusFruitGiven = cmp.getInteger(TAG_CHORUS_FRUIT_GIVEN);
}
}