mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
91 lines
5.7 KiB
Diff
91 lines
5.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
|
Date: Fri, 25 Jun 2021 19:48:21 -0500
|
|
Subject: [PATCH] Shulker spawn from bullet options
|
|
|
|
(0 - 1) / 5.0 = -0.2 (can never happen because self is included in count)
|
|
(1 - 1) / 5.0 = 0.0 1.0 - 0.0 = 1.0 100% (just self)
|
|
(2 - 1) / 5.0 = 0.2 1.0 - 0.2 = 0.8 80% (1 other shulker)
|
|
(3 - 1) / 5.0 = 0.4 1.0 - 0.4 = 0.6 60% (2 other shulkers)
|
|
(4 - 1) / 5.0 = 0.6 1.0 - 0.6 = 0.4 40% (3 other shulkers)
|
|
(5 - 1) / 5.0 = 0.8 1.0 - 0.8 = 0.2 20% (4 other shulkers)
|
|
(6 - 1) / 5.0 = 1.0 1.0 - 1.0 = 0.0 0% (5 other shulkers)
|
|
(7 - 1) / 5.0 = 1.2 1.0 - 1.2 = -0.2 0% (6 other shulkers)
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/Shulker.java b/src/main/java/net/minecraft/world/entity/monster/Shulker.java
|
|
index 2abdeb351fbabec7490c1ce806cebf8886b6be61..ada070d8e1a2d328c02455eb9e5ad056046bcd0a 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Shulker.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Shulker.java
|
|
@@ -507,13 +507,22 @@ public class Shulker extends AbstractGolem implements Enemy {
|
|
Vec3 vec3d = this.position();
|
|
AABB axisalignedbb = this.getBoundingBox();
|
|
|
|
- if (!this.isClosed() && this.teleportSomewhere()) {
|
|
- int i = this.level.getEntities((EntityTypeTest) EntityType.SHULKER, axisalignedbb.inflate(8.0D), Entity::isAlive).size();
|
|
- float f = (float) (i - 1) / 5.0F;
|
|
-
|
|
- if (this.level.random.nextFloat() >= f) {
|
|
+ if ((!this.level.purpurConfig.shulkerSpawnFromBulletRequireOpenLid || !this.isClosed()) && this.teleportSomewhere()) {
|
|
+ // Purpur start
|
|
+ float chance = this.level.purpurConfig.shulkerSpawnFromBulletBaseChance;
|
|
+ if (!this.level.purpurConfig.shulkerSpawnFromBulletNearbyEquation.isBlank()) {
|
|
+ int nearby = this.level.getEntities((EntityTypeTest) EntityType.SHULKER, axisalignedbb.inflate(this.level.purpurConfig.shulkerSpawnFromBulletNearbyRange), Entity::isAlive).size();
|
|
+ try {
|
|
+ scriptEngine.eval("nearby = " + nearby);
|
|
+ chance -= (float) scriptEngine.eval(this.level.purpurConfig.shulkerSpawnFromBulletNearbyEquation);
|
|
+ } catch (Exception ignore) {
|
|
+ chance -= (float) (nearby - 1) / 5.0F;
|
|
+ }
|
|
+ }
|
|
+ if (this.level.random.nextFloat() <= chance) {
|
|
+ // Purpur end
|
|
Shulker entityshulker = (Shulker) EntityType.SHULKER.create(this.level);
|
|
- DyeColor enumcolor = this.getColor();
|
|
+ DyeColor enumcolor = this.level.purpurConfig.shulkerSpawnFromBulletRandomColor ? DyeColor.random(this.level.random) : this.getColor(); // Purpur
|
|
|
|
if (enumcolor != null) {
|
|
entityshulker.setColor(enumcolor);
|
|
diff --git a/src/main/java/net/minecraft/world/item/DyeColor.java b/src/main/java/net/minecraft/world/item/DyeColor.java
|
|
index 2d3dbc228a6a7b88167a36ba739d9eb2f03472ba..7621978ab3d90d58e8b7c6807e0e0519062654dc 100644
|
|
--- a/src/main/java/net/minecraft/world/item/DyeColor.java
|
|
+++ b/src/main/java/net/minecraft/world/item/DyeColor.java
|
|
@@ -112,4 +112,10 @@ public enum DyeColor implements StringRepresentable {
|
|
public String getSerializedName() {
|
|
return this.name;
|
|
}
|
|
+
|
|
+ // Purpur start
|
|
+ public static DyeColor random(net.minecraft.util.RandomSource random) {
|
|
+ return BY_ID[random.nextInt(BY_ID.length)];
|
|
+ }
|
|
+ // Purpur end
|
|
}
|
|
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
index 3f027244cc41ce2ab28425b92b15ba752d1d77e0..fd2d7270179fa111ea1dbf2f9f8447cd459b33e0 100644
|
|
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
@@ -1898,6 +1898,11 @@ public class PurpurWorldConfig {
|
|
public boolean shulkerControllable = true;
|
|
public double shulkerMaxHealth = 30.0D;
|
|
public boolean shulkerTakeDamageFromWater = false;
|
|
+ public float shulkerSpawnFromBulletBaseChance = 1.0F;
|
|
+ public boolean shulkerSpawnFromBulletRequireOpenLid = true;
|
|
+ public double shulkerSpawnFromBulletNearbyRange = 8.0D;
|
|
+ public String shulkerSpawnFromBulletNearbyEquation = "(nearby - 1) / 5.0";
|
|
+ public boolean shulkerSpawnFromBulletRandomColor = false;
|
|
private void shulkerSettings() {
|
|
shulkerRidable = getBoolean("mobs.shulker.ridable", shulkerRidable);
|
|
shulkerRidableInWater = getBoolean("mobs.shulker.ridable-in-water", shulkerRidableInWater);
|
|
@@ -1909,6 +1914,11 @@ public class PurpurWorldConfig {
|
|
}
|
|
shulkerMaxHealth = getDouble("mobs.shulker.attributes.max_health", shulkerMaxHealth);
|
|
shulkerTakeDamageFromWater = getBoolean("mobs.shulker.takes-damage-from-water", shulkerTakeDamageFromWater);
|
|
+ shulkerSpawnFromBulletBaseChance = (float) getDouble("mobs.shulker.spawn-from-bullet.base-chance", shulkerSpawnFromBulletBaseChance);
|
|
+ shulkerSpawnFromBulletRequireOpenLid = getBoolean("mobs.shulker.spawn-from-bullet.require-open-lid", shulkerSpawnFromBulletRequireOpenLid);
|
|
+ shulkerSpawnFromBulletNearbyRange = getDouble("mobs.shulker.spawn-from-bullet.nearby-range", shulkerSpawnFromBulletNearbyRange);
|
|
+ shulkerSpawnFromBulletNearbyEquation = getString("mobs.shulker.spawn-from-bullet.nearby-equation", shulkerSpawnFromBulletNearbyEquation);
|
|
+ shulkerSpawnFromBulletRandomColor = getBoolean("mobs.shulker.spawn-from-bullet.random-color", shulkerSpawnFromBulletRandomColor);
|
|
}
|
|
|
|
public boolean silverfishRidable = false;
|