mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-25 22:44:44 +00:00
Move fish to spawn if the cocoon is next to water, add other water mobs
This commit is contained in:
1 parent
0840478c2a
commit
3090006d5e
2 files changed
+39
-16
No files matched your search
@@ -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<EntityType<?>> 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<EntityType<? extends MobEntity>> 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<EntityType<?>> NORMALS = ImmutableList.of(
|
||||
EntityType.PIG, EntityType.COW, EntityType.CHICKEN, EntityType.RABBIT,
|
||||
EntityType.SHEEP, EntityType.COD, EntityType.SALMON, EntityType.TROPICAL_FISH
|
||||
private static final List<EntityType<? extends MobEntity>> NORMALS = ImmutableList.of(
|
||||
EntityType.PIG, EntityType.COW, EntityType.CHICKEN, EntityType.RABBIT, EntityType.SHEEP
|
||||
);
|
||||
private static final List<EntityType<? extends MobEntity>> 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<BlockPos> 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<? extends MobEntity> 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);
|
||||
|
||||
Reference in new issue
Block a user