Files
Purpur/patches/server/0011-Make-giants-naturally-spawn-and-have-AI.patch
William Blake Galbreath 18ebfc0366 Update to 1.15
2019-12-13 15:11:37 -06:00

184 lines
11 KiB
Diff

From 9c583298f7a57968d72cdc8d772610fb58bc456b Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Sun, 12 May 2019 00:43:12 -0500
Subject: [PATCH] Make giants naturally spawn and have AI
---
.../java/net/minecraft/server/BiomeBase.java | 1 +
.../java/net/minecraft/server/Biomes.java | 25 ++++++++++
.../minecraft/server/EntityGiantZombie.java | 48 ++++++++++++++++++-
.../minecraft/server/EntityInsentient.java | 2 +
.../net/minecraft/server/SpawnerCreature.java | 8 ++++
.../java/net/pl3x/purpur/PurpurConfig.java | 7 +++
6 files changed, 89 insertions(+), 2 deletions(-)
diff --git a/src/main/java/net/minecraft/server/BiomeBase.java b/src/main/java/net/minecraft/server/BiomeBase.java
index 0102a170dc..9637098462 100644
--- a/src/main/java/net/minecraft/server/BiomeBase.java
+++ b/src/main/java/net/minecraft/server/BiomeBase.java
@@ -112,6 +112,7 @@ public abstract class BiomeBase {
return MathHelper.f(0.62222224F - f * 0.05F, 0.5F + f * 0.1F, 1.0F);
}
+ protected void addMobSpawn(EnumCreatureType creaturetype, BiomeBase.BiomeMeta biomemeta) { a(creaturetype, biomemeta); } // Purpur - OBFHELPER
protected void a(EnumCreatureType enumcreaturetype, BiomeBase.BiomeMeta biomebase_biomemeta) {
((List) this.v.get(enumcreaturetype)).add(biomebase_biomemeta);
}
diff --git a/src/main/java/net/minecraft/server/Biomes.java b/src/main/java/net/minecraft/server/Biomes.java
index 12742870ca..d1f8695fee 100644
--- a/src/main/java/net/minecraft/server/Biomes.java
+++ b/src/main/java/net/minecraft/server/Biomes.java
@@ -92,5 +92,30 @@ public abstract class Biomes {
static {
Collections.addAll(BiomeBase.b, new BiomeBase[]{Biomes.OCEAN, Biomes.PLAINS, Biomes.DESERT, Biomes.MOUNTAINS, Biomes.FOREST, Biomes.TAIGA, Biomes.SWAMP, Biomes.RIVER, Biomes.FROZEN_RIVER, Biomes.SNOWY_TUNDRA, Biomes.SNOWY_MOUNTAINS, Biomes.MUSHROOM_FIELDS, Biomes.MUSHROOM_FIELD_SHORE, Biomes.BEACH, Biomes.DESERT_HILLS, Biomes.WOODED_HILLS, Biomes.TAIGA_HILLS, Biomes.JUNGLE, Biomes.JUNGLE_HILLS, Biomes.JUNGLE_EDGE, Biomes.DEEP_OCEAN, Biomes.STONE_SHORE, Biomes.SNOWY_BEACH, Biomes.BIRCH_FOREST, Biomes.BIRCH_FOREST_HILLS, Biomes.DARK_FOREST, Biomes.SNOWY_TAIGA, Biomes.SNOWY_TAIGA_HILLS, Biomes.GIANT_TREE_TAIGA, Biomes.GIANT_TREE_TAIGA_HILLS, Biomes.WOODED_MOUNTAINS, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.BADLANDS, Biomes.WOODED_BADLANDS_PLATEAU, Biomes.BADLANDS_PLATEAU});
+
+ // Purpur start - add natural mob spawns (maybe find a better place for this?)
+ if (net.pl3x.purpur.PurpurConfig.giantsNaturallySpawn) {
+ addSpawn("plains", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1);
+ addSpawn("sunflower_plains", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1);
+ addSpawn("desert", EnumCreatureType.MONSTER, EntityTypes.GIANT, 2, 1, 1);
+ addSpawn("desert_hills", EnumCreatureType.MONSTER, EntityTypes.GIANT, 2, 1, 1);
+ addSpawn("desert_lakes", EnumCreatureType.MONSTER, EntityTypes.GIANT, 2, 1, 1);
+ addSpawn("mountains", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1);
+ addSpawn("gravelly_mountains", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1);
+ addSpawn("modified_gravelly_mountains", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1);
+ addSpawn("savanna", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1);
+ addSpawn("savanna_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1);
+ addSpawn("shattered_savanna", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1);
+ addSpawn("shattered_savanna_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 1);
+ addSpawn("badlands", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 1, 1);
+ addSpawn("badlands_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 1, 1);
+ addSpawn("eroded_badlands", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 1, 1);
+ addSpawn("modified_badlands_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 1, 1);
+ }
+ }
+
+ private static void addSpawn(String biome, EnumCreatureType ct, EntityTypes et, int weight, int min_group, int max_group) {
+ IRegistry.BIOME.get(new MinecraftKey(biome)).addMobSpawn(ct, new BiomeBase.BiomeMeta(et, weight, min_group, max_group));
}
+ // Purpur end
}
diff --git a/src/main/java/net/minecraft/server/EntityGiantZombie.java b/src/main/java/net/minecraft/server/EntityGiantZombie.java
index b7e2022b19..c2408e7211 100644
--- a/src/main/java/net/minecraft/server/EntityGiantZombie.java
+++ b/src/main/java/net/minecraft/server/EntityGiantZombie.java
@@ -21,11 +21,55 @@ public class EntityGiantZombie extends EntityMonster {
super.initAttributes();
this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(100.0D);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.5D);
- this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(50.0D);
+ this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(12.0D); // Purpur - match ravager damage
}
+ // Purpur start
+ @Override
+ protected void initPathfinder() {
+ if (net.pl3x.purpur.PurpurConfig.giantsHaveAI) {
+ this.goalSelector.a(0, new PathfinderGoalFloat(this));
+ this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, 1.0D, false));
+ this.goalSelector.a(7, new PathfinderGoalRandomStrollLand(this, 1.0D));
+ this.goalSelector.a(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 16.0F));
+ this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
+ this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
+ this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this).a(EntityPigZombie.class));
+ this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<>(this, EntityHuman.class, true));
+ this.targetSelector.a(3, new PathfinderGoalNearestAttackableTarget<>(this, EntityVillager.class, false));
+ this.targetSelector.a(4, new PathfinderGoalNearestAttackableTarget<>(this, EntityIronGolem.class, true));
+ this.targetSelector.a(5, new PathfinderGoalNearestAttackableTarget<>(this, EntityTurtle.class, true));
+ }
+ }
+
+ @Override
+ public float dp() { // jump height
+ // make giants jump as high as everything else relative to their size
+ // 1.0 makes bottom of feet about as high as their waist when they jump
+ return 1.0F;
+ }
+
+ @Override
+ public GroupDataEntity prepare(GeneratorAccess world, DifficultyDamageScaler difficulty, EnumMobSpawn enummobspawn, GroupDataEntity groupDataEntity, NBTTagCompound nbt) {
+ GroupDataEntity groupData = super.prepare(world, difficulty, enummobspawn, groupDataEntity, nbt);
+ if (groupData == null) {
+ setEquipmentBasedOnDifficulty(difficulty);
+ setEnchantmentBasedOnDifficulty(difficulty);
+ }
+ return groupData;
+ }
+
+ @Override
+ protected void setEquipmentBasedOnDifficulty(DifficultyDamageScaler difficulty) {
+ super.setEquipmentBasedOnDifficulty(difficulty);
+ if (random.nextFloat() < (world.getDifficulty() == EnumDifficulty.HARD ? 0.1F : 0.05F)) {
+ setSlot(EnumItemSlot.MAINHAND, new ItemStack(Items.IRON_SWORD));
+ }
+ }
+ // Purpur end
+
@Override
public float a(BlockPosition blockposition, IWorldReader iworldreader) {
- return iworldreader.w(blockposition) - 0.5F;
+ return super.a(blockposition, iworldreader); // Purpur - fix light requirements for natural spawns
}
}
diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
index 90587f4c82..53fffb3dc3 100644
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
@@ -856,6 +856,7 @@ public abstract class EntityInsentient extends EntityLiving {
return f;
}
+ protected void setEquipmentBasedOnDifficulty(DifficultyDamageScaler difficultydamagescaler) { a(difficultydamagescaler); } // Purpur - OBFHELPER
protected void a(DifficultyDamageScaler difficultydamagescaler) {
if (this.random.nextFloat() < 0.15F * difficultydamagescaler.d()) {
int i = this.random.nextInt(2);
@@ -963,6 +964,7 @@ public abstract class EntityInsentient extends EntityLiving {
}
}
+ protected void setEnchantmentBasedOnDifficulty(DifficultyDamageScaler difficultydamagescaler) { b(difficultydamagescaler); } // Purpur - OBFHELPER
protected void b(DifficultyDamageScaler difficultydamagescaler) {
float f = difficultydamagescaler.d();
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
index 58bbf2f9d2..53d5900411 100644
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
@@ -77,6 +77,14 @@ public final class SpawnerCreature {
if (biomebase_biomemeta.b.e() != EnumCreatureType.MISC && (biomebase_biomemeta.b.d() || d0 <= 16384.0D)) {
EntityTypes<?> entitytypes = biomebase_biomemeta.b;
+ // Purpur start
+ if (entitytypes == EntityTypes.GIANT) {
+ if (!net.pl3x.purpur.PurpurConfig.giantsNaturallySpawn) {
+ return i;
+ }
+ }
+ // Purpur end
+
if (entitytypes.b() && a(chunkgenerator, enumcreaturetype, biomebase_biomemeta, (BlockPosition) blockposition_mutableblockposition)) {
EntityPositionTypes.Surface entitypositiontypes_surface = EntityPositionTypes.a(entitytypes);
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
index d3409155ed..1c89125300 100644
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
@@ -141,6 +141,13 @@ public class PurpurConfig {
feedMushroomsToCows = getInt("settings.mobs.cow.feed-mushrooms-for-mooshroom", feedMushroomsToCows);
}
+ public static boolean giantsNaturallySpawn = true;
+ public static boolean giantsHaveAI = true;
+ private static void giantsSettings() {
+ giantsNaturallySpawn = getBoolean("settings.mobs.giant.naturally-spawn", giantsNaturallySpawn);
+ giantsHaveAI = getBoolean("settings.mobs.giant.have-ai", giantsHaveAI);
+ }
+
public static double crystalsAttackPhantomsRadius = 0.0D;
public static float crystalsAttackPhantomDamage = 1.0F;
public static double phantomsOrbitCrystalsRadius = 0.0D;
--
2.24.0.rc1