mirror of
https://github.com/PurpurMC/Purpur.git
synced 2025-02-17 13:00:04 +08:00
148 lines
7.5 KiB
Diff
148 lines
7.5 KiB
Diff
From 0000000000000000000000000000000000000000 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] Giants AI settings
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/Giant.java b/src/main/java/net/minecraft/world/entity/monster/Giant.java
|
|
index c1c5e884f00398032196ee71b55b348fcfce21ce..ed032918fb33d60c2d60d4db9275dddf88dd72d9 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Giant.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Giant.java
|
|
@@ -1,13 +1,36 @@
|
|
package net.minecraft.world.entity.monster;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
+import net.minecraft.nbt.CompoundTag;
|
|
+import net.minecraft.world.Difficulty;
|
|
+import net.minecraft.world.DifficultyInstance;
|
|
import net.minecraft.world.entity.EntityDimensions;
|
|
import net.minecraft.world.entity.EntityType;
|
|
+import net.minecraft.world.entity.EquipmentSlot;
|
|
+import net.minecraft.world.entity.MobSpawnType;
|
|
import net.minecraft.world.entity.Pose;
|
|
+import net.minecraft.world.entity.SpawnGroupData;
|
|
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
|
+import net.minecraft.world.entity.ai.goal.FloatGoal;
|
|
+import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
|
|
+import net.minecraft.world.entity.ai.goal.MeleeAttackGoal;
|
|
+import net.minecraft.world.entity.ai.goal.MoveTowardsRestrictionGoal;
|
|
+import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
|
|
+import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal;
|
|
+import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
|
|
+import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
|
|
+import net.minecraft.world.entity.animal.IronGolem;
|
|
+import net.minecraft.world.entity.animal.Turtle;
|
|
+import net.minecraft.world.entity.npc.Villager;
|
|
+import net.minecraft.world.entity.player.Player;
|
|
+import net.minecraft.world.item.ItemStack;
|
|
+import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelReader;
|
|
+import net.minecraft.world.level.ServerLevelAccessor;
|
|
+
|
|
+import javax.annotation.Nullable;
|
|
|
|
public class Giant extends Monster {
|
|
public Giant(EntityType<? extends Giant> type, Level world) {
|
|
@@ -31,18 +54,59 @@ public class Giant extends Monster {
|
|
return level.purpurConfig.giantControllable;
|
|
}
|
|
|
|
- @Override
|
|
- protected void registerGoals() {
|
|
- this.goalSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this));
|
|
- this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this));
|
|
- }
|
|
-
|
|
@Override
|
|
protected void initAttributes() {
|
|
this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(this.level.purpurConfig.giantMaxHealth);
|
|
this.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(this.level.purpurConfig.giantMovementSpeed);
|
|
this.getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(this.level.purpurConfig.giantAttackDamage);
|
|
}
|
|
+
|
|
+ @Override
|
|
+ protected void registerGoals() {
|
|
+ if (level.purpurConfig.giantHaveAI) {
|
|
+ this.goalSelector.addGoal(0, new FloatGoal(this));
|
|
+ this.goalSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this));
|
|
+ this.goalSelector.addGoal(7, new WaterAvoidingRandomStrollGoal(this, 1.0D));
|
|
+ this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Player.class, 16.0F));
|
|
+ this.goalSelector.addGoal(8, new RandomLookAroundGoal(this));
|
|
+ this.goalSelector.addGoal(5, new MoveTowardsRestrictionGoal(this, 1.0D));
|
|
+ if (level.purpurConfig.giantHaveHostileAI) {
|
|
+ this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.0D, false));
|
|
+ this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this));
|
|
+ this.targetSelector.addGoal(1, new HurtByTargetGoal(this).setAlertOthers(ZombifiedPiglin.class));
|
|
+ this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true));
|
|
+ this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Villager.class, false));
|
|
+ this.targetSelector.addGoal(4, new NearestAttackableTargetGoal<>(this, IronGolem.class, true));
|
|
+ this.targetSelector.addGoal(5, new NearestAttackableTargetGoal<>(this, Turtle.class, true));
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public SpawnGroupData finalizeSpawn(ServerLevelAccessor world, DifficultyInstance difficulty, MobSpawnType spawnReason, @Nullable SpawnGroupData entityData, @Nullable CompoundTag entityNbt) {
|
|
+ SpawnGroupData groupData = super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityNbt);
|
|
+ if (groupData == null) {
|
|
+ populateDefaultEquipmentSlots(this.random, difficulty);
|
|
+ populateDefaultEquipmentEnchantments(this.random, difficulty);
|
|
+ }
|
|
+ return groupData;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ protected void populateDefaultEquipmentSlots(net.minecraft.util.RandomSource random, DifficultyInstance difficulty) {
|
|
+ super.populateDefaultEquipmentSlots(this.random, difficulty);
|
|
+ // TODO make configurable
|
|
+ if (random.nextFloat() < (level.getDifficulty() == Difficulty.HARD ? 0.1F : 0.05F)) {
|
|
+ this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SWORD));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public float getJumpPower() {
|
|
+ // 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 level.purpurConfig.giantJumpHeight;
|
|
+ }
|
|
// Purpur end
|
|
|
|
@Override
|
|
@@ -56,6 +120,6 @@ public class Giant extends Monster {
|
|
|
|
@Override
|
|
public float getWalkTargetValue(BlockPos pos, LevelReader world) {
|
|
- return world.getPathfindingCostFromLightLevels(pos);
|
|
+ return super.getWalkTargetValue(pos, world); // Purpur - fix light requirements for natural spawns
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
index b22e855393e5f3d3099db3bba60ad62c1163ca2b..2cf4bab37d7789f9d22ae1d9edbdabbe8fa79ab5 100644
|
|
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
@@ -534,6 +534,10 @@ public class PurpurWorldConfig {
|
|
public double giantMovementSpeed = 0.5D;
|
|
public double giantAttackDamage = 50.0D;
|
|
public double giantMaxHealth = 100.0D;
|
|
+ public float giantStepHeight = 2.0F;
|
|
+ public float giantJumpHeight = 1.0F;
|
|
+ public boolean giantHaveAI = false;
|
|
+ public boolean giantHaveHostileAI = false;
|
|
private void giantSettings() {
|
|
giantRidable = getBoolean("mobs.giant.ridable", giantRidable);
|
|
giantRidableInWater = getBoolean("mobs.giant.ridable-in-water", giantRidableInWater);
|
|
@@ -550,6 +554,10 @@ public class PurpurWorldConfig {
|
|
set("mobs.giant.attributes.max_health", oldValue);
|
|
}
|
|
giantMaxHealth = getDouble("mobs.giant.attributes.max_health", giantMaxHealth);
|
|
+ giantStepHeight = (float) getDouble("mobs.giant.step-height", giantStepHeight);
|
|
+ giantJumpHeight = (float) getDouble("mobs.giant.jump-height", giantJumpHeight);
|
|
+ giantHaveAI = getBoolean("mobs.giant.have-ai", giantHaveAI);
|
|
+ giantHaveHostileAI = getBoolean("mobs.giant.have-hostile-ai", giantHaveHostileAI);
|
|
}
|
|
|
|
public boolean glowSquidRidable = false;
|