Files
Purpur/patches/server/0013-Make-giants-naturally-spawn-and-have-AI.patch
2019-07-28 09:45:50 -05:00

145 lines
9.1 KiB
Diff

From 4f0ade4ca03aa897cb0667065159ac29297453fb 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 | 30 +++++++++++++++++--
.../net/minecraft/server/SpawnerCreature.java | 8 +++++
.../java/net/pl3x/purpur/PurpurConfig.java | 7 +++++
5 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/src/main/java/net/minecraft/server/BiomeBase.java b/src/main/java/net/minecraft/server/BiomeBase.java
index a86ece8344..fbbb3b7c51 100644
--- a/src/main/java/net/minecraft/server/BiomeBase.java
+++ b/src/main/java/net/minecraft/server/BiomeBase.java
@@ -108,6 +108,7 @@ public abstract class BiomeBase {
return this.m != null;
}
+ protected void addMobSpawn(EnumCreatureType creaturetype, BiomeBase.BiomeMeta biomemeta) { a(creaturetype, biomemeta); } // Purpur - OBFHELPER
protected void a(EnumCreatureType enumcreaturetype, BiomeBase.BiomeMeta biomebase_biomemeta) {
((List) this.u.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 f4698a6809..3f7f7a2de8 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, 2);
+ addSpawn("savanna_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 2);
+ addSpawn("shattered_savanna", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 2);
+ addSpawn("shattered_savanna_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 5, 1, 2);
+ addSpawn("badlands", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 1, 2);
+ addSpawn("badlands_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 1, 2);
+ addSpawn("eroded_badlands", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 1, 2);
+ addSpawn("modified_badlands_plateau", EnumCreatureType.MONSTER, EntityTypes.GIANT, 10, 2, 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 29e7639ad6..e69e7a456d 100644
--- a/src/main/java/net/minecraft/server/EntityGiantZombie.java
+++ b/src/main/java/net/minecraft/server/EntityGiantZombie.java
@@ -21,11 +21,37 @@ 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 cX() { // 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;
+ }
+ // Purpur end
+
@Override
public float a(BlockPosition blockposition, IWorldReader iworldreader) {
- return iworldreader.v(blockposition) - 0.5F;
+ return super.a(blockposition, iworldreader); // Purpur - fix light requirements for natural spawns
}
}
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
index 5e6559df0b..2d4ea99f16 100644
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
@@ -78,6 +78,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 amountSpawned;
+ }
+ }
+ // 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 2b67041f45..ad807268c9 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.20.1