From 3090006d5e6cfdad9a9055f05c3987a54a0bba1a Mon Sep 17 00:00:00 2001 From: Hubry Date: Sat, 18 Jan 2020 23:32:59 +0100 Subject: [PATCH] Move fish to spawn if the cocoon is next to water, add other water mobs --- .../botania/common/block/tile/TileCocoon.java | 53 +++++++++++++------ .../resources/assets/botania/lang/en_us.json | 2 +- 2 files changed, 39 insertions(+), 16 deletions(-) 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 f1675ce02..c2d8cb51c 100644 --- a/src/main/java/vazkii/botania/common/block/tile/TileCocoon.java +++ b/src/main/java/vazkii/botania/common/block/tile/TileCocoon.java @@ -11,6 +11,7 @@ package vazkii.botania.common.block.tile; import com.google.common.collect.ImmutableList; +import net.minecraft.block.Blocks; import net.minecraft.entity.AgeableEntity; import net.minecraft.entity.EntityType; import net.minecraft.entity.MobEntity; @@ -20,10 +21,13 @@ import net.minecraft.entity.villager.IVillagerType; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; import net.minecraftforge.registries.ObjectHolder; import vazkii.botania.common.lib.LibBlockNames; import vazkii.botania.common.lib.LibMisc; +import java.util.ArrayList; import java.util.List; public class TileCocoon extends TileMod implements ITickableTileEntity{ @@ -34,20 +38,22 @@ public class TileCocoon extends TileMod implements ITickableTileEntity{ 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"; - private static final List> SPECIALS = ImmutableList.of( - EntityType.HORSE, EntityType.MULE, EntityType.DONKEY, - EntityType.WOLF, EntityType.OCELOT, EntityType.CAT, - EntityType.PARROT, EntityType.LLAMA, EntityType.FOX, EntityType.PANDA, - EntityType.TURTLE + private static final List> SPECIALS = ImmutableList.of( + EntityType.HORSE, EntityType.DONKEY, EntityType.WOLF, EntityType.OCELOT, + EntityType.CAT, EntityType.PARROT, EntityType.LLAMA, EntityType.FOX, + EntityType.PANDA, EntityType.TURTLE ); - private static final List> NORMALS = ImmutableList.of( - EntityType.PIG, EntityType.COW, EntityType.CHICKEN, EntityType.RABBIT, - EntityType.SHEEP, EntityType.COD, EntityType.SALMON, EntityType.TROPICAL_FISH + private static final List> NORMALS = ImmutableList.of( + EntityType.PIG, EntityType.COW, EntityType.CHICKEN, EntityType.RABBIT, EntityType.SHEEP + ); + private static final List> AQUATIC = ImmutableList.of( + EntityType.COD, EntityType.SALMON, EntityType.TROPICAL_FISH, EntityType.PUFFERFISH, EntityType.SQUID ); public static final int TOTAL_TIME = 2400; public static final int MAX_EMERALDS = 20; public static final int MAX_CHORUS_FRUITS = 20; + private static final float SPECIAL_CHANCE = 0.075F; public int timePassed; public int emeraldsGiven; @@ -70,10 +76,21 @@ public class TileCocoon extends TileMod implements ITickableTileEntity{ world.destroyBlock(pos, false); MobEntity entity = null; + BlockPos placePos = pos; float villagerChance = Math.min(1F, (float) emeraldsGiven / (float) MAX_EMERALDS); float shulkerChance = Math.min(1F, (float) chorusFruitGiven / (float) MAX_CHORUS_FRUITS); + List validWater = new ArrayList<>(); + for (Direction d : Direction.values()) { + if (d != Direction.UP) { + BlockPos blockPos = pos.offset(d); + if (world.getBlockState(blockPos).getBlock() == Blocks.WATER) { + validWater.add(blockPos); + } + } + } + if(Math.random() < shulkerChance) { entity = EntityType.SHULKER.create(world); } else if(Math.random() < villagerChance) { @@ -83,20 +100,26 @@ public class TileCocoon extends TileMod implements ITickableTileEntity{ villager.setVillagerData(villager.getVillagerData().withType(type)); } entity = villager; - } else { - float specialChance = 0.075F; - if(Math.random() < specialChance) { - entity = (MobEntity) SPECIALS.get(world.rand.nextInt(SPECIALS.size())).create(world); + } else if (!validWater.isEmpty()) { + placePos = validWater.get(world.rand.nextInt(validWater.size())); + if (Math.random() < SPECIAL_CHANCE) { + entity = EntityType.DOLPHIN.create(world); } else { - EntityType type = NORMALS.get(world.rand.nextInt(NORMALS.size())); + entity = AQUATIC.get(world.rand.nextInt(AQUATIC.size())).create(world); + } + } else { + if(Math.random() < SPECIAL_CHANCE) { + entity = SPECIALS.get(world.rand.nextInt(SPECIALS.size())).create(world); + } else { + EntityType type = NORMALS.get(world.rand.nextInt(NORMALS.size())); if (type == EntityType.COW && Math.random() < 0.01) type = EntityType.MOOSHROOM; - entity = (MobEntity) type.create(world); + entity = type.create(world); } } if(entity != null) { - entity.setPosition(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); + entity.setPosition(placePos.getX() + 0.5, placePos.getY() + 0.5, placePos.getZ() + 0.5); if(entity instanceof AgeableEntity) ((AgeableEntity) entity).setGrowingAge(-24000); entity.onInitialSpawn(world, world.getDifficultyForLocation(getPos()), SpawnReason.EVENT, null, null); diff --git a/src/main/resources/assets/botania/lang/en_us.json b/src/main/resources/assets/botania/lang/en_us.json index 07a71d2d3..0c882a181 100644 --- a/src/main/resources/assets/botania/lang/en_us.json +++ b/src/main/resources/assets/botania/lang/en_us.json @@ -2461,7 +2461,7 @@ "botania.entry.cocoon": "Cocoon of Caprice", "botania.tagline.cocoon": "Hatch your own animals", "botania.page.cocoon0": "A cocoon is a symbol of change, of evolution.$(p)Creating a $(item)Cocoon of Caprice$(0) and placing it will slowly evolve the rudimentary bits of life inside into a $(item)Baby Animal$(0). More often than not, the cocoon will hatch into a farm animal, but on rare occasions, different animals such as $(item)Wolves$(0) or $(item)Horses$(0) could be created.", - "botania.page.cocoon1": "Rumor has it that giving a cocoon $(item)Emeralds$(0) or $(item)Chorus Fruit$(0) will influence its outcome towards something... different. What such experiments would yield is anyone's guess, really.$(p)(Giving a cocoon an item can be done via right-click or by simply tossing the item.)", + "botania.page.cocoon1": "Placing a cocoon near water seems to create aquatic animals instead.$(p)Rumor has it that giving a cocoon $(item)Emeralds$(0) or $(item)Chorus Fruit$(0) will influence its outcome towards something... different. What such experiments would yield is anyone's guess, really.$(p)(Giving a cocoon an item can be done via right-click or by simply tossing the item.)", "botania.page.cocoon2": "New World, Perfect World", "botania.entry.manaBomb": "Manastorm Charge",