mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-22 00:47:38 +01:00
Add sniffer egg api (#9288)
This commit is contained in:
parent
7d13b7066c
commit
0e622c79fa
@ -1480,10 +1480,10 @@ index 0000000000000000000000000000000000000000..f0d4ec73bc8872a85e34f5c6b4d342e7
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..4989f99c0d330da52aeaca5df08edfbd47b5bf3c
|
||||
index 0000000000000000000000000000000000000000..da7c899fbab162ee197a0593f455ebd9c5286d3c
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
|
||||
@@ -0,0 +1,523 @@
|
||||
@@ -0,0 +1,530 @@
|
||||
+package io.papermc.paper.configuration;
|
||||
+
|
||||
+import com.google.common.collect.HashBasedTable;
|
||||
@ -1616,6 +1616,13 @@ index 0000000000000000000000000000000000000000..4989f99c0d330da52aeaca5df08edfbd
|
||||
+ public boolean tick = true;
|
||||
+ }
|
||||
+
|
||||
+ public Sniffer sniffer;
|
||||
+
|
||||
+ public class Sniffer extends ConfigurationPart {
|
||||
+ public IntOr.Default hatchTime = IntOr.Default.USE_DEFAULT;
|
||||
+ public IntOr.Default boostedHatchTime = IntOr.Default.USE_DEFAULT;
|
||||
+ }
|
||||
+
|
||||
+ public Spawning spawning;
|
||||
+
|
||||
+ public class Spawning extends ConfigurationPart {
|
||||
|
@ -71,3 +71,18 @@ index a3a5dbaed7a7647249747154ac0c024bddd7eb13..c7b914cc0d702c6dd04add5247ec509d
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java b/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java
|
||||
index c0f19138c6a00ce6ae837c972ae4af522ddd2895..3de0424a18e0a3b0cd2f755adfa859e474d5c643 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java
|
||||
@@ -355,8 +355,9 @@ public class Sniffer extends Animal {
|
||||
|
||||
entityitem.setDefaultPickUpDelay();
|
||||
this.finalizeSpawnChildFromBreeding(world, other, (AgeableMob) null);
|
||||
+ if (this.spawnAtLocation(entityitem) != null) { // Paper - call EntityDropItemEvent
|
||||
this.playSound(SoundEvents.SNIFFER_EGG_PLOP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 0.5F);
|
||||
- world.addFreshEntity(entityitem);
|
||||
+ } // Paper
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,3 +20,34 @@ index 834c5e3fbff3819f3f72e95a1072d9b9e57f25b3..294d22b6b27e96b59c77527efcfefa94
|
||||
this.destroyBlock(world, pos);
|
||||
world.playSound((Player)null, pos, SoundEvents.FROGSPAWN_HATCH, SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
this.spawnTadpoles(world, pos, random);
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
index 1e115adfcfee518667559100d04050f5e71c8a23..8aaa3cb2248a02b5ee25251cc837a145edd34341 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
@@ -54,12 +54,26 @@ public class SnifferEggBlock extends Block {
|
||||
return this.getHatchLevel(state) == 2;
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ private void rescheduleTick(ServerLevel world, BlockPos pos) {
|
||||
+ int baseDelay = hatchBoost(world, pos) ? BOOSTED_HATCH_TIME_TICKS : REGULAR_HATCH_TIME_TICKS;
|
||||
+ world.scheduleTick(pos, this, (baseDelay / 3) + world.random.nextInt(RANDOM_HATCH_OFFSET_TICKS));
|
||||
+ // reschedule to avoid being stuck here and behave like the other calls (see #onPlace)
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
@Override
|
||||
public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
|
||||
if (!this.isReadyToHatch(state)) {
|
||||
world.playSound((Player)null, pos, SoundEvents.SNIFFER_EGG_CRACK, SoundSource.BLOCKS, 0.7F, 0.9F + random.nextFloat() * 0.2F);
|
||||
world.setBlock(pos, state.setValue(HATCH, Integer.valueOf(this.getHatchLevel(state) + 1)), 2);
|
||||
} else {
|
||||
+ // Paper start - Call BlockFadeEvent
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(world, pos, state.getFluidState().createLegacyBlock()).isCancelled()) {
|
||||
+ rescheduleTick(world, pos);
|
||||
+ return;
|
||||
+ }
|
||||
+ // Paper end
|
||||
world.playSound((Player)null, pos, SoundEvents.SNIFFER_EGG_HATCH, SoundSource.BLOCKS, 0.7F, 0.9F + random.nextFloat() * 0.2F);
|
||||
world.destroyBlock(pos, false);
|
||||
Sniffer sniffer = EntityType.SNIFFER.create(world);
|
||||
|
@ -69,3 +69,16 @@ index 294d22b6b27e96b59c77527efcfefa9410b756e4..bebcdc70c4cb01764428836fff76f03b
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
index 8f08a977f7433b8237aff26c6d03d821a843c261..b8e536c89b00b8f5a853d3b83512d4f0987c08fd 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
@@ -81,7 +81,7 @@ public class SnifferEggBlock extends Block {
|
||||
Vec3 vec3 = pos.getCenter();
|
||||
sniffer.setBaby(true);
|
||||
sniffer.moveTo(vec3.x(), vec3.y(), vec3.z(), Mth.wrapDegrees(world.random.nextFloat() * 360.0F), 0.0F);
|
||||
- world.addFreshEntity(sniffer);
|
||||
+ world.addFreshEntity(sniffer, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // Paper
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ index 22eb0a8fc35baa04b34265b62aa29a71f3cc7343..203691417e208b9e023e5f8c3b76993d
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java b/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java
|
||||
index c0f19138c6a00ce6ae837c972ae4af522ddd2895..a6d98f64910c816a5c11867d12698f5cd63c751a 100644
|
||||
index 3de0424a18e0a3b0cd2f755adfa859e474d5c643..94965855233509cbe48cebd690a83ef29cd0c27a 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java
|
||||
@@ -350,11 +350,16 @@ public class Sniffer extends Animal {
|
||||
@ -65,11 +65,11 @@ index c0f19138c6a00ce6ae837c972ae4af522ddd2895..a6d98f64910c816a5c11867d12698f5c
|
||||
entityitem.setDefaultPickUpDelay();
|
||||
- this.finalizeSpawnChildFromBreeding(world, other, (AgeableMob) null);
|
||||
+ this.finalizeSpawnChildFromBreeding(world, other, (AgeableMob) null, result.getExperience()); // Paper - Add EntityFertilizeEggEvent event
|
||||
if (this.spawnAtLocation(entityitem) != null) { // Paper - call EntityDropItemEvent
|
||||
this.playSound(SoundEvents.SNIFFER_EGG_PLOP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 0.5F);
|
||||
world.addFreshEntity(entityitem);
|
||||
}
|
||||
} // Paper
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
index ee382cae3feca1de40d95faf6af023c8a7df05b9..3362ded586f723ef1f89ad6dfa872ae468f92933 100644
|
||||
index a4653a660e74f5d65489ddbb7b0e46134f2472c0..eb310003414000d76a150a7acbedc08e9b1d7180 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
@@ -2047,4 +2047,29 @@ public class CraftEventFactory {
|
||||
|
@ -0,0 +1,39 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
|
||||
Date: Fri, 9 Jun 2023 13:04:42 +0200
|
||||
Subject: [PATCH] Call BlockGrowEvent for missing blocks
|
||||
|
||||
Call the event for pitcher crops and sniffer egg
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java b/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java
|
||||
index 849c0ae6ca30691134f51e5d4d5da372e0e728bd..d2e8aafb8db17f2426dd83353c0cfdeaf0d372aa 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java
|
||||
@@ -126,7 +126,7 @@ public class PitcherCropBlock extends DoublePlantBlock implements BonemealableBl
|
||||
private void grow(ServerLevel world, BlockState state, BlockPos pos, int amount) {
|
||||
int i = Math.min(state.getValue(AGE) + amount, 4);
|
||||
if (this.canGrow(world, pos, state, i)) {
|
||||
- world.setBlock(pos, state.setValue(AGE, Integer.valueOf(i)), 2);
|
||||
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, pos, state.setValue(AGE, Integer.valueOf(i)), 2)) return; // Paper
|
||||
if (i >= 3) {
|
||||
BlockPos blockPos = pos.above();
|
||||
world.setBlock(blockPos, copyWaterloggedFrom(world, pos, this.defaultBlockState().setValue(AGE, Integer.valueOf(i)).setValue(HALF, DoubleBlockHalf.UPPER)), 3);
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
index ecb8224beb0ee65855c7529b69ea56b7b6674664..fab44502b3e22eb8d1311068f88290ce31adb437 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
@@ -65,8 +65,13 @@ public class SnifferEggBlock extends Block {
|
||||
@Override
|
||||
public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
|
||||
if (!this.isReadyToHatch(state)) {
|
||||
+ // Paper start
|
||||
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, pos, state.setValue(HATCH, Integer.valueOf(this.getHatchLevel(state) + 1)), 2)) {
|
||||
+ rescheduleTick(world, pos);
|
||||
+ return;
|
||||
+ }
|
||||
+ // Paper end
|
||||
world.playSound((Player)null, pos, SoundEvents.SNIFFER_EGG_CRACK, SoundSource.BLOCKS, 0.7F, 0.9F + random.nextFloat() * 0.2F);
|
||||
- world.setBlock(pos, state.setValue(HATCH, Integer.valueOf(this.getHatchLevel(state) + 1)), 2);
|
||||
} else {
|
||||
// Paper start - Call BlockFadeEvent
|
||||
if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(world, pos, state.getFluidState().createLegacyBlock()).isCancelled()) {
|
@ -1,19 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
|
||||
Date: Fri, 9 Jun 2023 13:04:42 +0200
|
||||
Subject: [PATCH] Call BlockGrowEvent for the pitcher crop
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java b/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java
|
||||
index 849c0ae6ca30691134f51e5d4d5da372e0e728bd..d2e8aafb8db17f2426dd83353c0cfdeaf0d372aa 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java
|
||||
@@ -126,7 +126,7 @@ public class PitcherCropBlock extends DoublePlantBlock implements BonemealableBl
|
||||
private void grow(ServerLevel world, BlockState state, BlockPos pos, int amount) {
|
||||
int i = Math.min(state.getValue(AGE) + amount, 4);
|
||||
if (this.canGrow(world, pos, state, i)) {
|
||||
- world.setBlock(pos, state.setValue(AGE, Integer.valueOf(i)), 2);
|
||||
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, pos, state.setValue(AGE, Integer.valueOf(i)), 2)) return; // Paper
|
||||
if (i >= 3) {
|
||||
BlockPos blockPos = pos.above();
|
||||
world.setBlock(blockPos, copyWaterloggedFrom(world, pos, this.defaultBlockState().setValue(AGE, Integer.valueOf(i)).setValue(HALF, DoubleBlockHalf.UPPER)), 3);
|
28
patches/server/1028-Configure-sniffer-egg-hatch-time.patch
Normal file
28
patches/server/1028-Configure-sniffer-egg-hatch-time.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
|
||||
Date: Tue, 27 Jun 2023 13:26:06 +0200
|
||||
Subject: [PATCH] Configure sniffer egg hatch time
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
index fab44502b3e22eb8d1311068f88290ce31adb437..16c5be04658a66ff94f2aad8782e34f450e9a729 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java
|
||||
@@ -56,7 +56,7 @@ public class SnifferEggBlock extends Block {
|
||||
|
||||
// Paper start
|
||||
private void rescheduleTick(ServerLevel world, BlockPos pos) {
|
||||
- int baseDelay = hatchBoost(world, pos) ? BOOSTED_HATCH_TIME_TICKS : REGULAR_HATCH_TIME_TICKS;
|
||||
+ int baseDelay = hatchBoost(world, pos) ? world.paperConfig().entities.sniffer.boostedHatchTime.or(BOOSTED_HATCH_TIME_TICKS) : world.paperConfig().entities.sniffer.hatchTime.or(REGULAR_HATCH_TIME_TICKS);
|
||||
world.scheduleTick(pos, this, (baseDelay / 3) + world.random.nextInt(RANDOM_HATCH_OFFSET_TICKS));
|
||||
// reschedule to avoid being stuck here and behave like the other calls (see #onPlace)
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public class SnifferEggBlock extends Block {
|
||||
world.levelEvent(3009, pos, 0);
|
||||
}
|
||||
|
||||
- int i = bl ? 12000 : 24000;
|
||||
+ int i = bl ? world.paperConfig().entities.sniffer.boostedHatchTime.or(BOOSTED_HATCH_TIME_TICKS) : world.paperConfig().entities.sniffer.hatchTime.or(REGULAR_HATCH_TIME_TICKS); // Paper
|
||||
int j = i / 3;
|
||||
world.gameEvent(GameEvent.BLOCK_PLACE, pos, GameEvent.Context.of(state));
|
||||
world.scheduleTick(pos, this, j + world.random.nextInt(300));
|
Loading…
Reference in New Issue
Block a user