Files
Purpur/patches/server/0175-Shulker-spawn-from-bullet-options.patch
granny ffeb49da1e ignore item_model component for don't run with scissors feature alongside custom_model_data component
by default, the "don't run with scissors" feature will not activate for shears that have an `item_model` component or `custom_model_data` component.

adds a new world config option at `gameplay-mechanics.item.shears.damage-if-sprinting-item-model` that allows specifying a custom item model ResourceLocation (`purpurmc:scissors` by default) for use with this feature.
2024-12-06 06:05:14 -08:00

98 lines
6.2 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 ef44ab79cba3778111c9f27f77219b384761d9e4..8464a8288f7ec7ae14e44b93607ebb0617790c46 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Shulker.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Shulker.java
@@ -512,12 +512,21 @@ public class Shulker extends AbstractGolem implements VariantHolder<Optional<Dye
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 {
+ chance -= ((Number) scriptEngine.eval("let nearby = " + nearby + "; " + this.level().purpurConfig.shulkerSpawnFromBulletNearbyEquation)).floatValue();
+ } catch (javax.script.ScriptException e) {
+ e.printStackTrace();
+ chance -= (nearby - 1) / 5.0F;
+ }
+ }
+ if (this.level().random.nextFloat() <= chance) {
Shulker entityshulker = (Shulker) EntityType.SHULKER.create(this.level(), EntitySpawnReason.BREEDING);
+ // Purpur end
if (entityshulker != null) {
entityshulker.setVariant(this.getVariant());
@@ -631,7 +640,7 @@ public class Shulker extends AbstractGolem implements VariantHolder<Optional<Dye
@Override
public Optional<DyeColor> getVariant() {
- return Optional.ofNullable(this.getColor());
+ return Optional.ofNullable(this.level().purpurConfig.shulkerSpawnFromBulletRandomColor ? DyeColor.random(this.level().random) : this.getColor()); // Purpur
}
@Nullable
diff --git a/src/main/java/net/minecraft/world/item/DyeColor.java b/src/main/java/net/minecraft/world/item/DyeColor.java
index 648e6979aa72b9d1e1ea3b40d5a876e3c690b934..d9cd4f47e9990bdd85e30f68ca3b755a953332a1 100644
--- a/src/main/java/net/minecraft/world/item/DyeColor.java
+++ b/src/main/java/net/minecraft/world/item/DyeColor.java
@@ -123,4 +123,10 @@ public enum DyeColor implements StringRepresentable {
private static CraftingInput makeCraftColorInput(DyeColor first, DyeColor second) {
return CraftingInput.of(2, 1, List.of(new ItemStack(DyeItem.byColor(first)), new ItemStack(DyeItem.byColor(second))));
}
+
+ // Purpur start
+ public static DyeColor random(net.minecraft.util.RandomSource random) {
+ return values()[random.nextInt(values().length)];
+ }
+ // Purpur end
}
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index 849532c99cfad2870fd22be6e759e153e8fae10b..51609ddc3890b5a6a9106b6d2960697723651ec2 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -1993,6 +1993,11 @@ public class PurpurWorldConfig {
public double shulkerMaxHealth = 30.0D;
public double shulkerScale = 1.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);
@@ -2005,6 +2010,11 @@ public class PurpurWorldConfig {
shulkerMaxHealth = getDouble("mobs.shulker.attributes.max_health", shulkerMaxHealth);
shulkerScale = Mth.clamp(getDouble("mobs.shulker.attributes.scale", shulkerScale), 0.0625D, Shulker.MAX_SCALE);
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;