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)
This commit is contained in:
William Blake Galbreath
2025-01-11 22:55:10 -08:00
committed by granny
parent d760f5436f
commit e09623ae80
4 changed files with 68 additions and 97 deletions

View File

@@ -0,0 +1,45 @@
--- a/net/minecraft/world/entity/monster/Shulker.java
+++ b/net/minecraft/world/entity/monster/Shulker.java
@@ -50,6 +_,7 @@
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
@@ -459,11 +_,21 @@
private void hitByShulkerBullet() {
Vec3 vec3 = this.position();
AABB boundingBox = this.getBoundingBox();
- if (!this.isClosed() && this.teleportSomewhere()) {
- int size = this.level().getEntities(EntityType.SHULKER, boundingBox.inflate(8.0), Entity::isAlive).size();
- float f = (size - 1) / 5.0F;
- if (!(this.level().random.nextFloat() < f)) {
+ // Purpur start - Shulker spawn from bullet options
+ if ((!this.level().purpurConfig.shulkerSpawnFromBulletRequireOpenLid || !this.isClosed()) && this.teleportSomewhere()) {
+ float chance = this.level().purpurConfig.shulkerSpawnFromBulletBaseChance;
+ if (!this.level().purpurConfig.shulkerSpawnFromBulletNearbyEquation.isBlank()) {
+ int nearby = this.level().getEntities((EntityTypeTest) EntityType.SHULKER, boundingBox.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 shulker = EntityType.SHULKER.create(this.level(), EntitySpawnReason.BREEDING);
+ // Purpur end - Shulker spawn from bullet options
if (shulker != null) {
shulker.setVariant(this.getVariant());
shulker.moveTo(vec3);
@@ -573,7 +_,7 @@
@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 - Shulker spawn from bullet options
}
@Nullable

View File

@@ -0,0 +1,13 @@
--- a/net/minecraft/world/item/DyeColor.java
+++ b/net/minecraft/world/item/DyeColor.java
@@ -123,4 +_,10 @@
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 - Shulker spawn from bullet options
+ public static DyeColor random(net.minecraft.util.RandomSource random) {
+ return values()[random.nextInt(values().length)];
+ }
+ // Purpur end - Shulker spawn from bullet options
}