Move CraftBukkit per-file patches

By: Initial <noreply+automated@papermc.io>
This commit is contained in:
CraftBukkit/Spigot
2024-12-11 22:26:36 +01:00
parent a4de181b77
commit a265d64138
583 changed files with 71 additions and 857 deletions

View File

@@ -0,0 +1,22 @@
--- a/net/minecraft/world/level/CommandBlockListenerAbstract.java
+++ b/net/minecraft/world/level/CommandBlockListenerAbstract.java
@@ -33,6 +33,10 @@
private String command = "";
@Nullable
private IChatBaseComponent customName;
+ // CraftBukkit start
+ @Override
+ public abstract org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper);
+ // CraftBukkit end
public CommandBlockListenerAbstract() {}
@@ -132,7 +136,7 @@
});
- minecraftserver.getCommands().performPrefixedCommand(commandlistenerwrapper, this.command);
+ minecraftserver.getCommands().dispatchServerCommand(commandlistenerwrapper, this.command); // CraftBukkit
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Executing command block");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Command to be executed");

View File

@@ -0,0 +1,212 @@
--- a/net/minecraft/world/level/GameRules.java
+++ b/net/minecraft/world/level/GameRules.java
@@ -58,7 +58,7 @@
public static final GameRules.GameRuleKey<GameRules.GameRuleBoolean> RULE_SENDCOMMANDFEEDBACK = register("sendCommandFeedback", GameRules.GameRuleCategory.CHAT, GameRules.GameRuleBoolean.create(true));
public static final GameRules.GameRuleKey<GameRules.GameRuleBoolean> RULE_REDUCEDDEBUGINFO = register("reducedDebugInfo", GameRules.GameRuleCategory.MISC, GameRules.GameRuleBoolean.create(false, (minecraftserver, gamerules_gameruleboolean) -> {
int i = gamerules_gameruleboolean.get() ? 22 : 23;
- Iterator iterator = minecraftserver.getPlayerList().getPlayers().iterator();
+ Iterator iterator = minecraftserver.players().iterator(); // CraftBukkit - per-world
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -74,7 +74,7 @@
public static final GameRules.GameRuleKey<GameRules.GameRuleInt> RULE_MAX_ENTITY_CRAMMING = register("maxEntityCramming", GameRules.GameRuleCategory.MOBS, GameRules.GameRuleInt.create(24));
public static final GameRules.GameRuleKey<GameRules.GameRuleBoolean> RULE_WEATHER_CYCLE = register("doWeatherCycle", GameRules.GameRuleCategory.UPDATES, GameRules.GameRuleBoolean.create(true));
public static final GameRules.GameRuleKey<GameRules.GameRuleBoolean> RULE_LIMITED_CRAFTING = register("doLimitedCrafting", GameRules.GameRuleCategory.PLAYER, GameRules.GameRuleBoolean.create(false, (minecraftserver, gamerules_gameruleboolean) -> {
- Iterator iterator = minecraftserver.getPlayerList().getPlayers().iterator();
+ Iterator iterator = minecraftserver.players().iterator(); // CraftBukkit - per-world
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -90,7 +90,7 @@
public static final GameRules.GameRuleKey<GameRules.GameRuleBoolean> RULE_DISABLE_RAIDS = register("disableRaids", GameRules.GameRuleCategory.MOBS, GameRules.GameRuleBoolean.create(false));
public static final GameRules.GameRuleKey<GameRules.GameRuleBoolean> RULE_DOINSOMNIA = register("doInsomnia", GameRules.GameRuleCategory.SPAWNING, GameRules.GameRuleBoolean.create(true));
public static final GameRules.GameRuleKey<GameRules.GameRuleBoolean> RULE_DO_IMMEDIATE_RESPAWN = register("doImmediateRespawn", GameRules.GameRuleCategory.PLAYER, GameRules.GameRuleBoolean.create(false, (minecraftserver, gamerules_gameruleboolean) -> {
- Iterator iterator = minecraftserver.getPlayerList().getPlayers().iterator();
+ Iterator iterator = minecraftserver.players().iterator(); // CraftBukkit - per-world
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -123,7 +123,7 @@
public static final GameRules.GameRuleKey<GameRules.GameRuleInt> RULE_MINECART_MAX_SPEED = register("minecartMaxSpeed", GameRules.GameRuleCategory.MISC, GameRules.GameRuleInt.create(8, 1, 1000, FeatureFlagSet.of(FeatureFlags.MINECART_IMPROVEMENTS), (minecraftserver, gamerules_gameruleint) -> {
}));
public static final GameRules.GameRuleKey<GameRules.GameRuleInt> RULE_SPAWN_CHUNK_RADIUS = register("spawnChunkRadius", GameRules.GameRuleCategory.MISC, GameRules.GameRuleInt.create(2, 0, 32, FeatureFlagSet.of(), (minecraftserver, gamerules_gameruleint) -> {
- WorldServer worldserver = minecraftserver.overworld();
+ WorldServer worldserver = minecraftserver; // CraftBukkit - per-world
worldserver.setDefaultSpawnPos(worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle());
}));
@@ -164,7 +164,7 @@
}
public <T extends GameRules.GameRuleValue<T>> T getRule(GameRules.GameRuleKey<T> gamerules_gamerulekey) {
- T t0 = (GameRules.GameRuleValue) this.rules.get(gamerules_gamerulekey);
+ T t0 = (T) this.rules.get(gamerules_gamerulekey); // CraftBukkit - decompile error
if (t0 == null) {
throw new IllegalArgumentException("Tried to access invalid game rule");
@@ -184,7 +184,7 @@
private void loadFromTag(DynamicLike<?> dynamiclike) {
this.rules.forEach((gamerules_gamerulekey, gamerules_gamerulevalue) -> {
- DataResult dataresult = dynamiclike.get(gamerules_gamerulekey.id).asString();
+ DataResult<String> dataresult = dynamiclike.get(gamerules_gamerulekey.id).asString(); // CraftBukkit - decompile error
Objects.requireNonNull(gamerules_gamerulevalue);
dataresult.ifSuccess(gamerules_gamerulevalue::deserialize);
@@ -205,19 +205,19 @@
private <T extends GameRules.GameRuleValue<T>> void callVisitorCap(GameRules.GameRuleVisitor gamerules_gamerulevisitor, GameRules.GameRuleKey<?> gamerules_gamerulekey, GameRules.GameRuleDefinition<?> gamerules_gameruledefinition) {
if (gamerules_gameruledefinition.requiredFeatures.isSubsetOf(this.enabledFeatures)) {
- gamerules_gamerulevisitor.visit(gamerules_gamerulekey, gamerules_gameruledefinition);
- gamerules_gameruledefinition.callVisitor(gamerules_gamerulevisitor, gamerules_gamerulekey);
+ gamerules_gamerulevisitor.visit((GameRules.GameRuleKey<T>) gamerules_gamerulekey, (GameRules.GameRuleDefinition<T>) gamerules_gameruledefinition); // CraftBukkit - decompile error
+ ((GameRules.GameRuleDefinition<T>) gamerules_gameruledefinition).callVisitor(gamerules_gamerulevisitor, (GameRules.GameRuleKey<T>) gamerules_gamerulekey); // CraftBukkit - decompile error
}
}
- public void assignFrom(GameRules gamerules, @Nullable MinecraftServer minecraftserver) {
+ public void assignFrom(GameRules gamerules, @Nullable WorldServer minecraftserver) { // CraftBukkit - per-world
gamerules.rules.keySet().forEach((gamerules_gamerulekey) -> {
this.assignCap(gamerules_gamerulekey, gamerules, minecraftserver);
});
}
- private <T extends GameRules.GameRuleValue<T>> void assignCap(GameRules.GameRuleKey<T> gamerules_gamerulekey, GameRules gamerules, @Nullable MinecraftServer minecraftserver) {
+ private <T extends GameRules.GameRuleValue<T>> void assignCap(GameRules.GameRuleKey<T> gamerules_gamerulekey, GameRules gamerules, @Nullable WorldServer minecraftserver) { // CraftBukkit - per-world
T t0 = gamerules.getRule(gamerules_gamerulekey);
this.getRule(gamerules_gamerulekey).setFrom(t0, minecraftserver);
@@ -285,11 +285,11 @@
final Supplier<ArgumentType<?>> argument;
private final Function<GameRules.GameRuleDefinition<T>, T> constructor;
- final BiConsumer<MinecraftServer, T> callback;
+ final BiConsumer<WorldServer, T> callback; // CraftBukkit - per-world
private final GameRules.h<T> visitorCaller;
final FeatureFlagSet requiredFeatures;
- GameRuleDefinition(Supplier<ArgumentType<?>> supplier, Function<GameRules.GameRuleDefinition<T>, T> function, BiConsumer<MinecraftServer, T> biconsumer, GameRules.h<T> gamerules_h, FeatureFlagSet featureflagset) {
+ GameRuleDefinition(Supplier<ArgumentType<?>> supplier, Function<GameRules.GameRuleDefinition<T>, T> function, BiConsumer<WorldServer, T> biconsumer, GameRules.h<T> gamerules_h, FeatureFlagSet featureflagset) { // CraftBukkit - per-world
this.argument = supplier;
this.constructor = function;
this.callback = biconsumer;
@@ -302,7 +302,7 @@
}
public T createRule() {
- return (GameRules.GameRuleValue) this.constructor.apply(this);
+ return this.constructor.apply(this); // CraftBukkit - decompile error
}
public void callVisitor(GameRules.GameRuleVisitor gamerules_gamerulevisitor, GameRules.GameRuleKey<T> gamerules_gamerulekey) {
@@ -326,17 +326,17 @@
public void setFromArgument(CommandContext<CommandListenerWrapper> commandcontext, String s) {
this.updateFromArgument(commandcontext, s);
- this.onChanged(((CommandListenerWrapper) commandcontext.getSource()).getServer());
+ this.onChanged(((CommandListenerWrapper) commandcontext.getSource()).getLevel()); // CraftBukkit - per-world
}
- public void onChanged(@Nullable MinecraftServer minecraftserver) {
+ public void onChanged(@Nullable WorldServer minecraftserver) { // CraftBukkit - per-world
if (minecraftserver != null) {
this.type.callback.accept(minecraftserver, this.getSelf());
}
}
- protected abstract void deserialize(String s);
+ public abstract void deserialize(String s); // PAIL - private->public
public abstract String serialize();
@@ -350,7 +350,7 @@
protected abstract T copy();
- public abstract void setFrom(T t0, @Nullable MinecraftServer minecraftserver);
+ public abstract void setFrom(T t0, @Nullable WorldServer minecraftserver); // CraftBukkit - per-world
}
public interface GameRuleVisitor {
@@ -366,7 +366,7 @@
private boolean value;
- static GameRules.GameRuleDefinition<GameRules.GameRuleBoolean> create(boolean flag, BiConsumer<MinecraftServer, GameRules.GameRuleBoolean> biconsumer) {
+ static GameRules.GameRuleDefinition<GameRules.GameRuleBoolean> create(boolean flag, BiConsumer<WorldServer, GameRules.GameRuleBoolean> biconsumer) { // CraftBukkit - per-world
return new GameRules.GameRuleDefinition<>(BoolArgumentType::bool, (gamerules_gameruledefinition) -> {
return new GameRules.GameRuleBoolean(gamerules_gameruledefinition, flag);
}, biconsumer, GameRules.GameRuleVisitor::visitBoolean, FeatureFlagSet.of());
@@ -391,7 +391,7 @@
return this.value;
}
- public void set(boolean flag, @Nullable MinecraftServer minecraftserver) {
+ public void set(boolean flag, @Nullable WorldServer minecraftserver) { // CraftBukkit - per-world
this.value = flag;
this.onChanged(minecraftserver);
}
@@ -402,7 +402,7 @@
}
@Override
- protected void deserialize(String s) {
+ public void deserialize(String s) { // PAIL - protected->public
this.value = Boolean.parseBoolean(s);
}
@@ -421,7 +421,7 @@
return new GameRules.GameRuleBoolean(this.type, this.value);
}
- public void setFrom(GameRules.GameRuleBoolean gamerules_gameruleboolean, @Nullable MinecraftServer minecraftserver) {
+ public void setFrom(GameRules.GameRuleBoolean gamerules_gameruleboolean, @Nullable WorldServer minecraftserver) { // CraftBukkit - per-world
this.value = gamerules_gameruleboolean.value;
this.onChanged(minecraftserver);
}
@@ -431,13 +431,13 @@
private int value;
- private static GameRules.GameRuleDefinition<GameRules.GameRuleInt> create(int i, BiConsumer<MinecraftServer, GameRules.GameRuleInt> biconsumer) {
+ private static GameRules.GameRuleDefinition<GameRules.GameRuleInt> create(int i, BiConsumer<WorldServer, GameRules.GameRuleInt> biconsumer) { // CraftBukkit - per-world
return new GameRules.GameRuleDefinition<>(IntegerArgumentType::integer, (gamerules_gameruledefinition) -> {
return new GameRules.GameRuleInt(gamerules_gameruledefinition, i);
}, biconsumer, GameRules.GameRuleVisitor::visitInteger, FeatureFlagSet.of());
}
- static GameRules.GameRuleDefinition<GameRules.GameRuleInt> create(int i, int j, int k, FeatureFlagSet featureflagset, BiConsumer<MinecraftServer, GameRules.GameRuleInt> biconsumer) {
+ static GameRules.GameRuleDefinition<GameRules.GameRuleInt> create(int i, int j, int k, FeatureFlagSet featureflagset, BiConsumer<WorldServer, GameRules.GameRuleInt> biconsumer) { // CraftBukkit - per-world
return new GameRules.GameRuleDefinition<>(() -> {
return IntegerArgumentType.integer(j, k);
}, (gamerules_gameruledefinition) -> {
@@ -464,7 +464,7 @@
return this.value;
}
- public void set(int i, @Nullable MinecraftServer minecraftserver) {
+ public void set(int i, @Nullable WorldServer minecraftserver) { // CraftBukkit - per-world
this.value = i;
this.onChanged(minecraftserver);
}
@@ -475,7 +475,7 @@
}
@Override
- protected void deserialize(String s) {
+ public void deserialize(String s) { // PAIL - protected->public
this.value = safeParse(s);
}
@@ -517,7 +517,7 @@
return new GameRules.GameRuleInt(this.type, this.value);
}
- public void setFrom(GameRules.GameRuleInt gamerules_gameruleint, @Nullable MinecraftServer minecraftserver) {
+ public void setFrom(GameRules.GameRuleInt gamerules_gameruleint, @Nullable WorldServer minecraftserver) { // CraftBukkit - per-world
this.value = gamerules_gameruleint.value;
this.onChanged(minecraftserver);
}

View File

@@ -0,0 +1,9 @@
--- a/net/minecraft/world/level/GeneratorAccess.java
+++ b/net/minecraft/world/level/GeneratorAccess.java
@@ -101,4 +101,6 @@
default void gameEvent(ResourceKey<GameEvent> resourcekey, BlockPosition blockposition, GameEvent.a gameevent_a) {
this.gameEvent((Holder) this.registryAccess().lookupOrThrow(Registries.GAME_EVENT).getOrThrow(resourcekey), blockposition, gameevent_a);
}
+
+ net.minecraft.server.level.WorldServer getMinecraftWorld(); // CraftBukkit
}

View File

@@ -0,0 +1,44 @@
--- a/net/minecraft/world/level/IBlockAccess.java
+++ b/net/minecraft/world/level/IBlockAccess.java
@@ -31,7 +31,7 @@
default <T extends TileEntity> Optional<T> getBlockEntity(BlockPosition blockposition, TileEntityTypes<T> tileentitytypes) {
TileEntity tileentity = this.getBlockEntity(blockposition);
- return tileentity != null && tileentity.getType() == tileentitytypes ? Optional.of(tileentity) : Optional.empty();
+ return tileentity != null && tileentity.getType() == tileentitytypes ? (Optional<T>) Optional.of(tileentity) : Optional.empty(); // CraftBukkit - decompile error
}
IBlockData getBlockState(BlockPosition blockposition);
@@ -59,8 +59,8 @@
});
}
- default MovingObjectPositionBlock clip(RayTrace raytrace) {
- return (MovingObjectPositionBlock) traverseBlocks(raytrace.getFrom(), raytrace.getTo(), raytrace, (raytrace1, blockposition) -> {
+ // CraftBukkit start - moved block handling into separate method for use by Block#rayTrace
+ default MovingObjectPositionBlock clip(RayTrace raytrace1, BlockPosition blockposition) {
IBlockData iblockdata = this.getBlockState(blockposition);
Fluid fluid = this.getFluidState(blockposition);
Vec3D vec3d = raytrace1.getFrom();
@@ -73,6 +73,12 @@
double d1 = movingobjectpositionblock1 == null ? Double.MAX_VALUE : raytrace1.getFrom().distanceToSqr(movingobjectpositionblock1.getLocation());
return d0 <= d1 ? movingobjectpositionblock : movingobjectpositionblock1;
+ }
+ // CraftBukkit end
+
+ default MovingObjectPositionBlock clip(RayTrace raytrace) {
+ return (MovingObjectPositionBlock) traverseBlocks(raytrace.getFrom(), raytrace.getTo(), raytrace, (raytrace1, blockposition) -> {
+ return this.clip(raytrace1, blockposition); // CraftBukkit - moved into separate method
}, (raytrace1) -> {
Vec3D vec3d = raytrace1.getFrom().subtract(raytrace1.getTo());
@@ -145,7 +151,7 @@
double d13 = d10 * (i1 > 0 ? 1.0D - MathHelper.frac(d4) : MathHelper.frac(d4));
double d14 = d11 * (j1 > 0 ? 1.0D - MathHelper.frac(d5) : MathHelper.frac(d5));
- Object object;
+ T object; // CraftBukkit - decompile error
do {
if (d12 > 1.0D && d13 > 1.0D && d14 > 1.0D) {

View File

@@ -0,0 +1,13 @@
--- a/net/minecraft/world/level/IWorldWriter.java
+++ b/net/minecraft/world/level/IWorldWriter.java
@@ -28,4 +28,10 @@
default boolean addFreshEntity(Entity entity) {
return false;
}
+
+ // CraftBukkit start
+ default boolean addFreshEntity(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ return false;
+ }
+ // CraftBukkit end
}

View File

@@ -0,0 +1,31 @@
--- a/net/minecraft/world/level/MobSpawnerAbstract.java
+++ b/net/minecraft/world/level/MobSpawnerAbstract.java
@@ -54,6 +54,7 @@
public void setEntityId(EntityTypes<?> entitytypes, @Nullable World world, RandomSource randomsource, BlockPosition blockposition) {
this.getOrCreateNextSpawnData(world, randomsource, blockposition).getEntityToSpawn().putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(entitytypes).toString());
+ this.spawnPotentials = SimpleWeightedRandomList.empty(); // CraftBukkit - SPIGOT-3496, MC-92282
}
private boolean isNearPlayer(World world, BlockPosition blockposition) {
@@ -157,13 +158,18 @@
((EntityInsentient) entity).finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.SPAWNER, (GroupDataEntity) null);
}
- Optional optional1 = mobspawnerdata.getEquipment();
+ Optional<net.minecraft.world.entity.EquipmentTable> optional1 = mobspawnerdata.getEquipment(); // CraftBukkit - decompile error
Objects.requireNonNull(entityinsentient);
optional1.ifPresent(entityinsentient::equip);
}
- if (!worldserver.tryAddFreshEntityWithPassengers(entity)) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callSpawnerSpawnEvent(entity, blockposition).isCancelled()) {
+ continue;
+ }
+ if (!worldserver.tryAddFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER)) {
+ // CraftBukkit end
this.delay(worldserver, blockposition);
return;
}

View File

@@ -0,0 +1,20 @@
--- a/net/minecraft/world/level/RayTrace.java
+++ b/net/minecraft/world/level/RayTrace.java
@@ -22,7 +22,7 @@
private final VoxelShapeCollision collisionContext;
public RayTrace(Vec3D vec3d, Vec3D vec3d1, RayTrace.BlockCollisionOption raytrace_blockcollisionoption, RayTrace.FluidCollisionOption raytrace_fluidcollisionoption, Entity entity) {
- this(vec3d, vec3d1, raytrace_blockcollisionoption, raytrace_fluidcollisionoption, VoxelShapeCollision.of(entity));
+ this(vec3d, vec3d1, raytrace_blockcollisionoption, raytrace_fluidcollisionoption, (entity == null) ? VoxelShapeCollision.empty() : VoxelShapeCollision.of(entity)); // CraftBukkit
}
public RayTrace(Vec3D vec3d, Vec3D vec3d1, RayTrace.BlockCollisionOption raytrace_blockcollisionoption, RayTrace.FluidCollisionOption raytrace_fluidcollisionoption, VoxelShapeCollision voxelshapecollision) {
@@ -79,7 +79,7 @@
private final Predicate<Fluid> canPick;
- private FluidCollisionOption(final Predicate predicate) {
+ private FluidCollisionOption(final Predicate<Fluid> predicate) { // CraftBukkit - decompile error
this.canPick = predicate;
}

View File

@@ -0,0 +1,193 @@
--- a/net/minecraft/world/level/ServerExplosion.java
+++ b/net/minecraft/world/level/ServerExplosion.java
@@ -35,6 +35,17 @@
import net.minecraft.world.phys.MovingObjectPosition;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import net.minecraft.world.entity.boss.EntityComplexPart;
+import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon;
+import net.minecraft.world.level.block.Blocks;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.event.entity.EntityExplodeEvent;
+import org.bukkit.Location;
+import org.bukkit.event.block.BlockExplodeEvent;
+// CraftBukkit end
+
public class ServerExplosion implements Explosion {
private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator();
@@ -50,16 +61,21 @@
private final DamageSource damageSource;
private final ExplosionDamageCalculator damageCalculator;
private final Map<EntityHuman, Vec3D> hitPlayers = new HashMap();
+ // CraftBukkit - add field
+ public boolean wasCanceled = false;
+ public float yield;
+ // CraftBukkit end
public ServerExplosion(WorldServer worldserver, @Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, Vec3D vec3d, float f, boolean flag, Explosion.Effect explosion_effect) {
this.level = worldserver;
this.source = entity;
- this.radius = f;
+ this.radius = (float) Math.max(f, 0.0); // CraftBukkit - clamp bad values
this.center = vec3d;
this.fire = flag;
this.blockInteraction = explosion_effect;
this.damageSource = damagesource == null ? worldserver.damageSources().explosion(this) : damagesource;
this.damageCalculator = explosiondamagecalculator == null ? this.makeDamageCalculator(entity) : explosiondamagecalculator;
+ this.yield = this.blockInteraction == Explosion.Effect.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F; // CraftBukkit
}
private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity entity) {
@@ -195,7 +211,35 @@
float f2 = !flag && f1 == 0.0F ? 0.0F : getSeenPercent(this.center, entity);
if (flag) {
- entity.hurtServer(this.level, this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, f2));
+ // CraftBukkit start
+
+ // Special case ender dragon only give knockback if no damage is cancelled
+ // Thinks to note:
+ // - Setting a velocity to a ComplexEntityPart is ignored (and therefore not needed)
+ // - Damaging ComplexEntityPart while forward the damage to EntityEnderDragon
+ // - Damaging EntityEnderDragon does nothing
+ // - EntityEnderDragon hitbock always covers the other parts and is therefore always present
+ if (entity instanceof EntityComplexPart) {
+ continue;
+ }
+
+ entity.lastDamageCancelled = false;
+
+ if (entity instanceof EntityEnderDragon) {
+ for (EntityComplexPart entityComplexPart : ((EntityEnderDragon) entity).subEntities) {
+ // Calculate damage separately for each EntityComplexPart
+ if (list.contains(entityComplexPart)) {
+ entityComplexPart.hurtServer(this.level, this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, f2));
+ }
+ }
+ } else {
+ entity.hurtServer(this.level, this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, f2));
+ }
+
+ if (entity.lastDamageCancelled) { // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Skip entity if damage event was cancelled
+ continue;
+ }
+ // CraftBukkit end
}
double d5 = (1.0D - d0) * (double) f2 * (double) f1;
@@ -214,6 +258,17 @@
d3 *= d6;
Vec3D vec3d = new Vec3D(d1, d2, d3);
+ // CraftBukkit start - Call EntityKnockbackEvent
+ if (entity instanceof EntityLiving) {
+ Vec3D result = entity.getDeltaMovement().add(vec3d);
+ org.bukkit.event.entity.EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) entity.getBukkitEntity(), source, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.EXPLOSION, d6, vec3d, result.x, result.y, result.z);
+
+ // SPIGOT-7640: Need to subtract entity movement from the event result,
+ // since the code below (the setDeltaMovement call as well as the hitPlayers map)
+ // want the vector to be the relative velocity will the event provides the absolute velocity
+ vec3d = (event.isCancelled()) ? Vec3D.ZERO : new Vec3D(event.getFinalKnockback().getX(), event.getFinalKnockback().getY(), event.getFinalKnockback().getZ()).subtract(entity.getDeltaMovement());
+ }
+ // CraftBukkit end
entity.push(vec3d);
if (entity instanceof EntityHuman) {
EntityHuman entityhuman = (EntityHuman) entity;
@@ -235,10 +290,62 @@
List<ServerExplosion.a> list1 = new ArrayList();
SystemUtils.shuffle(list, this.level.random);
+ // CraftBukkit start
+ org.bukkit.World bworld = this.level.getWorld();
+ Location location = CraftLocation.toBukkit(this.center, bworld);
+
+ List<org.bukkit.block.Block> blockList = new ObjectArrayList<>();
+ for (int i1 = list.size() - 1; i1 >= 0; i1--) {
+ BlockPosition cpos = list.get(i1);
+ org.bukkit.block.Block bblock = bworld.getBlockAt(cpos.getX(), cpos.getY(), cpos.getZ());
+ if (!bblock.getType().isAir()) {
+ blockList.add(bblock);
+ }
+ }
+
+ List<org.bukkit.block.Block> bukkitBlocks;
+
+ if (this.source != null) {
+ EntityExplodeEvent event = CraftEventFactory.callEntityExplodeEvent(this.source, blockList, this.yield, getBlockInteraction());
+ this.wasCanceled = event.isCancelled();
+ bukkitBlocks = event.blockList();
+ this.yield = event.getYield();
+ } else {
+ org.bukkit.block.Block block = location.getBlock();
+ org.bukkit.block.BlockState blockState = (damageSource.getDirectBlockState() != null) ? damageSource.getDirectBlockState() : block.getState();
+ BlockExplodeEvent event = CraftEventFactory.callBlockExplodeEvent(block, blockState, blockList, this.yield, getBlockInteraction());
+ this.wasCanceled = event.isCancelled();
+ bukkitBlocks = event.blockList();
+ this.yield = event.getYield();
+ }
+
+ list.clear();
+
+ for (org.bukkit.block.Block bblock : bukkitBlocks) {
+ BlockPosition coords = new BlockPosition(bblock.getX(), bblock.getY(), bblock.getZ());
+ list.add(coords);
+ }
+
+ if (this.wasCanceled) {
+ return;
+ }
+ // CraftBukkit end
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
BlockPosition blockposition = (BlockPosition) iterator.next();
+ // CraftBukkit start - TNTPrimeEvent
+ IBlockData iblockdata = this.level.getBlockState(blockposition);
+ Block block = iblockdata.getBlock();
+ if (block instanceof net.minecraft.world.level.block.BlockTNT) {
+ Entity sourceEntity = source == null ? null : source;
+ BlockPosition sourceBlock = sourceEntity == null ? BlockPosition.containing(this.center) : null;
+ if (!CraftEventFactory.callTNTPrimeEvent(this.level, blockposition, org.bukkit.event.block.TNTPrimeEvent.PrimeCause.EXPLOSION, sourceEntity, sourceBlock)) {
+ this.level.sendBlockUpdated(blockposition, Blocks.AIR.defaultBlockState(), iblockdata, 3); // Update the block on the client
+ continue;
+ }
+ }
+ // CraftBukkit end
this.level.getBlockState(blockposition).onExplosionHit(this.level, blockposition, this, (itemstack, blockposition1) -> {
addOrAppendStack(list1, itemstack, blockposition1);
@@ -262,13 +369,22 @@
BlockPosition blockposition = (BlockPosition) iterator.next();
if (this.level.random.nextInt(3) == 0 && this.level.getBlockState(blockposition).isAir() && this.level.getBlockState(blockposition.below()).isSolidRender()) {
- this.level.setBlockAndUpdate(blockposition, BlockFireAbstract.getState(this.level, blockposition));
+ // CraftBukkit start - Ignition by explosion
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(this.level, blockposition, this).isCancelled()) {
+ this.level.setBlockAndUpdate(blockposition, BlockFireAbstract.getState(this.level, blockposition));
+ }
+ // CraftBukkit end
}
}
}
public void explode() {
+ // CraftBukkit start
+ if (this.radius < 0.1F) {
+ return;
+ }
+ // CraftBukkit end
this.level.gameEvent(this.source, (Holder) GameEvent.EXPLODE, this.center);
List<BlockPosition> list = this.calculateExplodedPositions();
@@ -288,6 +404,7 @@
}
private static void addOrAppendStack(List<ServerExplosion.a> list, ItemStack itemstack, BlockPosition blockposition) {
+ if (itemstack.isEmpty()) return; // CraftBukkit - SPIGOT-5425
Iterator iterator = list.iterator();
do {

View File

@@ -0,0 +1,92 @@
--- a/net/minecraft/world/level/SpawnerCreature.java
+++ b/net/minecraft/world/level/SpawnerCreature.java
@@ -50,6 +50,13 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.level.storage.WorldData;
+import org.bukkit.craftbukkit.util.CraftSpawnCategory;
+import org.bukkit.entity.SpawnCategory;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+// CraftBukkit end
+
public final class SpawnerCreature {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -107,15 +114,31 @@
return (BiomeBase) ichunkaccess.getNoiseBiome(QuartPos.fromBlock(blockposition.getX()), QuartPos.fromBlock(blockposition.getY()), QuartPos.fromBlock(blockposition.getZ())).value();
}
- public static List<EnumCreatureType> getFilteredSpawningCategories(SpawnerCreature.d spawnercreature_d, boolean flag, boolean flag1, boolean flag2) {
+ // CraftBukkit start - add server
+ public static List<EnumCreatureType> getFilteredSpawningCategories(SpawnerCreature.d spawnercreature_d, boolean flag, boolean flag1, boolean flag2, WorldServer worldserver) {
+ WorldData worlddata = worldserver.getLevelData(); // CraftBukkit - Other mob type spawn tick rate
+ // CraftBukkit end
List<EnumCreatureType> list = new ArrayList(SpawnerCreature.SPAWNING_CATEGORIES.length);
EnumCreatureType[] aenumcreaturetype = SpawnerCreature.SPAWNING_CATEGORIES;
int i = aenumcreaturetype.length;
for (int j = 0; j < i; ++j) {
EnumCreatureType enumcreaturetype = aenumcreaturetype[j];
+ // CraftBukkit start - Use per-world spawn limits
+ boolean spawnThisTick = true;
+ int limit = enumcreaturetype.getMaxInstancesPerChunk();
+ SpawnCategory spawnCategory = CraftSpawnCategory.toBukkit(enumcreaturetype);
+ if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
+ spawnThisTick = worldserver.ticksPerSpawnCategory.getLong(spawnCategory) != 0 && worlddata.getGameTime() % worldserver.ticksPerSpawnCategory.getLong(spawnCategory) == 0;
+ limit = worldserver.getWorld().getSpawnLimit(spawnCategory);
+ }
- if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategoryGlobal(enumcreaturetype)) {
+ if (!spawnThisTick || limit == 0) {
+ continue;
+ }
+
+ if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategoryGlobal(enumcreaturetype, limit)) {
+ // CraftBukkit end
list.add(enumcreaturetype);
}
}
@@ -217,10 +240,15 @@
entityinsentient.moveTo(d0, (double) i, d1, worldserver.random.nextFloat() * 360.0F, 0.0F);
if (isValidPositionForMob(worldserver, entityinsentient, d2)) {
groupdataentity = entityinsentient.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.NATURAL, groupdataentity);
- ++j;
- ++k1;
- worldserver.addFreshEntityWithPassengers(entityinsentient);
- spawnercreature_a.run(entityinsentient, ichunkaccess);
+ // CraftBukkit start
+ // SPIGOT-7045: Give ocelot babies back their special spawn reason. Note: This is the only modification required as ocelots count as monsters which means they only spawn during normal chunk ticking and do not spawn during chunk generation as starter mobs.
+ worldserver.addFreshEntityWithPassengers(entityinsentient, (entityinsentient instanceof net.minecraft.world.entity.animal.EntityOcelot && !((org.bukkit.entity.Ageable) entityinsentient.getBukkitEntity()).isAdult()) ? SpawnReason.OCELOT_BABY : SpawnReason.NATURAL);
+ if (!entityinsentient.isRemoved()) {
+ ++j;
+ ++k1;
+ spawnercreature_a.run(entityinsentient, ichunkaccess);
+ }
+ // CraftBukkit end
if (j >= entityinsentient.getMaxSpawnClusterSize()) {
return;
}
@@ -369,7 +397,7 @@
if (entityinsentient.checkSpawnRules(worldaccess, EntitySpawnReason.CHUNK_GENERATION) && entityinsentient.checkSpawnObstruction(worldaccess)) {
groupdataentity = entityinsentient.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.CHUNK_GENERATION, groupdataentity);
- worldaccess.addFreshEntityWithPassengers(entityinsentient);
+ worldaccess.addFreshEntityWithPassengers(entityinsentient, SpawnReason.CHUNK_GEN); // CraftBukkit
flag = true;
}
}
@@ -482,8 +510,10 @@
return this.unmodifiableMobCategoryCounts;
}
- boolean canSpawnForCategoryGlobal(EnumCreatureType enumcreaturetype) {
- int i = enumcreaturetype.getMaxInstancesPerChunk() * this.spawnableChunkCount / SpawnerCreature.MAGIC_NUMBER;
+ // CraftBukkit start
+ boolean canSpawnForCategoryGlobal(EnumCreatureType enumcreaturetype, int limit) {
+ int i = limit * this.spawnableChunkCount / SpawnerCreature.MAGIC_NUMBER;
+ // CraftBukkit end
return this.mobCategoryCounts.getInt(enumcreaturetype) < i;
}

View File

@@ -0,0 +1,320 @@
--- a/net/minecraft/world/level/World.java
+++ b/net/minecraft/world/level/World.java
@@ -81,6 +81,28 @@
import net.minecraft.world.phys.Vec3D;
import net.minecraft.world.scores.Scoreboard;
+// CraftBukkit start
+import java.util.HashMap;
+import java.util.Map;
+import net.minecraft.network.protocol.game.ClientboundSetBorderCenterPacket;
+import net.minecraft.network.protocol.game.ClientboundSetBorderLerpSizePacket;
+import net.minecraft.network.protocol.game.ClientboundSetBorderSizePacket;
+import net.minecraft.network.protocol.game.ClientboundSetBorderWarningDelayPacket;
+import net.minecraft.network.protocol.game.ClientboundSetBorderWarningDistancePacket;
+import net.minecraft.server.level.WorldServer;
+import net.minecraft.world.entity.item.EntityItem;
+import net.minecraft.world.level.border.IWorldBorderListener;
+import net.minecraft.world.level.dimension.WorldDimension;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.block.CapturedBlockState;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
+import org.bukkit.craftbukkit.util.CraftSpawnCategory;
+import org.bukkit.entity.SpawnCategory;
+import org.bukkit.event.block.BlockPhysicsEvent;
+// CraftBukkit end
+
public abstract class World implements GeneratorAccess, AutoCloseable {
public static final Codec<ResourceKey<World>> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION);
@@ -121,7 +143,42 @@
private final DamageSources damageSources;
private long subTickCount;
- protected World(WorldDataMutable worlddatamutable, ResourceKey<World> resourcekey, IRegistryCustom iregistrycustom, Holder<DimensionManager> holder, boolean flag, boolean flag1, long i, int j) {
+ // CraftBukkit start Added the following
+ private final CraftWorld world;
+ public boolean pvpMode;
+ public org.bukkit.generator.ChunkGenerator generator;
+
+ public boolean preventPoiUpdated = false; // CraftBukkit - SPIGOT-5710
+ public boolean captureBlockStates = false;
+ public boolean captureTreeGeneration = false;
+ public Map<BlockPosition, CapturedBlockState> capturedBlockStates = new java.util.LinkedHashMap<>();
+ public Map<BlockPosition, TileEntity> capturedTileEntities = new HashMap<>();
+ public List<EntityItem> captureDrops;
+ public final it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<SpawnCategory> ticksPerSpawnCategory = new it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<>();
+ public boolean populating;
+
+ public CraftWorld getWorld() {
+ return this.world;
+ }
+
+ public CraftServer getCraftServer() {
+ return (CraftServer) Bukkit.getServer();
+ }
+
+ public abstract ResourceKey<WorldDimension> getTypeKey();
+
+ protected World(WorldDataMutable worlddatamutable, ResourceKey<World> resourcekey, IRegistryCustom iregistrycustom, Holder<DimensionManager> holder, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env) {
+ this.generator = gen;
+ this.world = new CraftWorld((WorldServer) this, gen, biomeProvider, env);
+
+ // CraftBukkit Ticks things
+ for (SpawnCategory spawnCategory : SpawnCategory.values()) {
+ if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
+ this.ticksPerSpawnCategory.put(spawnCategory, (long) this.getCraftServer().getTicksPerSpawns(spawnCategory));
+ }
+ }
+
+ // CraftBukkit end
this.levelData = worlddatamutable;
this.dimensionTypeRegistration = holder;
final DimensionManager dimensionmanager = (DimensionManager) holder.value();
@@ -129,15 +186,15 @@
this.dimension = resourcekey;
this.isClientSide = flag;
if (dimensionmanager.coordinateScale() != 1.0D) {
- this.worldBorder = new WorldBorder(this) {
+ this.worldBorder = new WorldBorder() { // CraftBukkit - decompile error
@Override
public double getCenterX() {
- return super.getCenterX() / dimensionmanager.coordinateScale();
+ return super.getCenterX(); // CraftBukkit
}
@Override
public double getCenterZ() {
- return super.getCenterZ() / dimensionmanager.coordinateScale();
+ return super.getCenterZ(); // CraftBukkit
}
};
} else {
@@ -150,6 +207,42 @@
this.neighborUpdater = new CollectingNeighborUpdater(this, j);
this.registryAccess = iregistrycustom;
this.damageSources = new DamageSources(iregistrycustom);
+ // CraftBukkit start
+ getWorldBorder().world = (WorldServer) this;
+ // From PlayerList.setPlayerFileData
+ getWorldBorder().addListener(new IWorldBorderListener() {
+ @Override
+ public void onBorderSizeSet(WorldBorder worldborder, double d0) {
+ getCraftServer().getHandle().broadcastAll(new ClientboundSetBorderSizePacket(worldborder), worldborder.world);
+ }
+
+ @Override
+ public void onBorderSizeLerping(WorldBorder worldborder, double d0, double d1, long i) {
+ getCraftServer().getHandle().broadcastAll(new ClientboundSetBorderLerpSizePacket(worldborder), worldborder.world);
+ }
+
+ @Override
+ public void onBorderCenterSet(WorldBorder worldborder, double d0, double d1) {
+ getCraftServer().getHandle().broadcastAll(new ClientboundSetBorderCenterPacket(worldborder), worldborder.world);
+ }
+
+ @Override
+ public void onBorderSetWarningTime(WorldBorder worldborder, int i) {
+ getCraftServer().getHandle().broadcastAll(new ClientboundSetBorderWarningDelayPacket(worldborder), worldborder.world);
+ }
+
+ @Override
+ public void onBorderSetWarningBlocks(WorldBorder worldborder, int i) {
+ getCraftServer().getHandle().broadcastAll(new ClientboundSetBorderWarningDistancePacket(worldborder), worldborder.world);
+ }
+
+ @Override
+ public void onBorderSetDamagePerBlock(WorldBorder worldborder, double d0) {}
+
+ @Override
+ public void onBorderSetDamageSafeZOne(WorldBorder worldborder, double d0) {}
+ });
+ // CraftBukkit end
}
@Override
@@ -207,6 +300,18 @@
@Override
public boolean setBlock(BlockPosition blockposition, IBlockData iblockdata, int i, int j) {
+ // CraftBukkit start - tree generation
+ if (this.captureTreeGeneration) {
+ CapturedBlockState blockstate = capturedBlockStates.get(blockposition);
+ if (blockstate == null) {
+ blockstate = CapturedBlockState.getTreeBlockState(this, blockposition, i);
+ this.capturedBlockStates.put(blockposition.immutable(), blockstate);
+ }
+ blockstate.setData(iblockdata);
+ blockstate.setFlag(i);
+ return true;
+ }
+ // CraftBukkit end
if (this.isOutsideBuildHeight(blockposition)) {
return false;
} else if (!this.isClientSide && this.isDebug()) {
@@ -214,13 +319,29 @@
} else {
Chunk chunk = this.getChunkAt(blockposition);
Block block = iblockdata.getBlock();
- IBlockData iblockdata1 = chunk.setBlockState(blockposition, iblockdata, (i & 64) != 0);
+
+ // CraftBukkit start - capture blockstates
+ boolean captured = false;
+ if (this.captureBlockStates && !this.capturedBlockStates.containsKey(blockposition)) {
+ CapturedBlockState blockstate = CapturedBlockState.getBlockState(this, blockposition, i);
+ this.capturedBlockStates.put(blockposition.immutable(), blockstate);
+ captured = true;
+ }
+ // CraftBukkit end
+
+ IBlockData iblockdata1 = chunk.setBlockState(blockposition, iblockdata, (i & 64) != 0, (i & 1024) == 0); // CraftBukkit custom NO_PLACE flag
if (iblockdata1 == null) {
+ // CraftBukkit start - remove blockstate if failed (or the same)
+ if (this.captureBlockStates && captured) {
+ this.capturedBlockStates.remove(blockposition);
+ }
+ // CraftBukkit end
return false;
} else {
IBlockData iblockdata2 = this.getBlockState(blockposition);
+ /*
if (iblockdata2 == iblockdata) {
if (iblockdata1 != iblockdata2) {
this.setBlocksDirty(blockposition, iblockdata1, iblockdata2);
@@ -247,12 +368,69 @@
this.onBlockStateChange(blockposition, iblockdata1, iblockdata2);
}
+ */
+
+ // CraftBukkit start
+ if (!this.captureBlockStates) { // Don't notify clients or update physics while capturing blockstates
+ // Modularize client and physic updates
+ notifyAndUpdatePhysics(blockposition, chunk, iblockdata1, iblockdata, iblockdata2, i, j);
+ }
+ // CraftBukkit end
return true;
}
}
}
+ // CraftBukkit start - Split off from above in order to directly send client and physic updates
+ public void notifyAndUpdatePhysics(BlockPosition blockposition, Chunk chunk, IBlockData oldBlock, IBlockData newBlock, IBlockData actualBlock, int i, int j) {
+ IBlockData iblockdata = newBlock;
+ IBlockData iblockdata1 = oldBlock;
+ IBlockData iblockdata2 = actualBlock;
+ if (iblockdata2 == iblockdata) {
+ if (iblockdata1 != iblockdata2) {
+ this.setBlocksDirty(blockposition, iblockdata1, iblockdata2);
+ }
+
+ if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || (chunk.getFullStatus() != null && chunk.getFullStatus().isOrAfter(FullChunkStatus.BLOCK_TICKING)))) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement
+ this.sendBlockUpdated(blockposition, iblockdata1, iblockdata, i);
+ }
+
+ if ((i & 1) != 0) {
+ this.blockUpdated(blockposition, iblockdata1.getBlock());
+ if (!this.isClientSide && iblockdata.hasAnalogOutputSignal()) {
+ this.updateNeighbourForOutputSignal(blockposition, newBlock.getBlock());
+ }
+ }
+
+ if ((i & 16) == 0 && j > 0) {
+ int k = i & -34;
+
+ // CraftBukkit start
+ iblockdata1.updateIndirectNeighbourShapes(this, blockposition, k, j - 1); // Don't call an event for the old block to limit event spam
+ CraftWorld world = ((WorldServer) this).getWorld();
+ if (world != null) {
+ BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftBlockData.fromData(iblockdata));
+ this.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
+ iblockdata.updateNeighbourShapes(this, blockposition, k, j - 1);
+ iblockdata.updateIndirectNeighbourShapes(this, blockposition, k, j - 1);
+ }
+
+ // CraftBukkit start - SPIGOT-5710
+ if (!preventPoiUpdated) {
+ this.onBlockStateChange(blockposition, iblockdata1, iblockdata2);
+ }
+ // CraftBukkit end
+ }
+ }
+ // CraftBukkit end
+
public void onBlockStateChange(BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {}
@Override
@@ -340,6 +518,14 @@
@Override
public IBlockData getBlockState(BlockPosition blockposition) {
+ // CraftBukkit start - tree generation
+ if (captureTreeGeneration) {
+ CapturedBlockState previous = capturedBlockStates.get(blockposition);
+ if (previous != null) {
+ return previous.getHandle();
+ }
+ }
+ // CraftBukkit end
if (this.isOutsideBuildHeight(blockposition)) {
return Blocks.VOID_AIR.defaultBlockState();
} else {
@@ -510,6 +696,16 @@
@Nullable
@Override
public TileEntity getBlockEntity(BlockPosition blockposition) {
+ // CraftBukkit start
+ return getBlockEntity(blockposition, true);
+ }
+
+ @Nullable
+ public TileEntity getBlockEntity(BlockPosition blockposition, boolean validate) {
+ if (capturedTileEntities.containsKey(blockposition)) {
+ return capturedTileEntities.get(blockposition);
+ }
+ // CraftBukkit end
return this.isOutsideBuildHeight(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAt(blockposition).getBlockEntity(blockposition, Chunk.EnumTileEntityState.IMMEDIATE));
}
@@ -517,6 +713,12 @@
BlockPosition blockposition = tileentity.getBlockPos();
if (!this.isOutsideBuildHeight(blockposition)) {
+ // CraftBukkit start
+ if (captureBlockStates) {
+ capturedTileEntities.put(blockposition.immutable(), tileentity);
+ return;
+ }
+ // CraftBukkit end
this.getChunkAt(blockposition).addAndRegisterBlockEntity(tileentity);
}
}
@@ -643,7 +845,7 @@
for (int k = 0; k < j; ++k) {
EntityComplexPart entitycomplexpart = aentitycomplexpart[k];
- T t0 = (Entity) entitytypetest.tryCast(entitycomplexpart);
+ T t0 = entitytypetest.tryCast(entitycomplexpart); // CraftBukkit - decompile error
if (t0 != null && predicate.test(t0)) {
list.add(t0);
@@ -912,7 +1114,7 @@
public static enum a implements INamable {
- NONE("none"), BLOCK("block"), MOB("mob"), TNT("tnt"), TRIGGER("trigger");
+ NONE("none"), BLOCK("block"), MOB("mob"), TNT("tnt"), TRIGGER("trigger"), STANDARD("standard"); // CraftBukkit - Add STANDARD which will always use Explosion.Effect.DESTROY
public static final Codec<World.a> CODEC = INamable.fromEnum(World.a::values);
private final String id;

View File

@@ -0,0 +1,21 @@
--- a/net/minecraft/world/level/WorldAccess.java
+++ b/net/minecraft/world/level/WorldAccess.java
@@ -8,6 +8,17 @@
WorldServer getLevel();
default void addFreshEntityWithPassengers(Entity entity) {
- entity.getSelfAndPassengers().forEach(this::addFreshEntity);
+ // CraftBukkit start
+ this.addFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ default void addFreshEntityWithPassengers(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ entity.getSelfAndPassengers().forEach((e) -> this.addFreshEntity(e, reason));
}
+
+ @Override
+ default WorldServer getMinecraftWorld() {
+ return getLevel();
+ }
+ // CraftBukkit end
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/AbstractCandleBlock.java
+++ b/net/minecraft/world/level/block/AbstractCandleBlock.java
@@ -47,6 +47,11 @@
@Override
protected void onProjectileHit(World world, IBlockData iblockdata, MovingObjectPositionBlock movingobjectpositionblock, IProjectile iprojectile) {
if (!world.isClientSide && iprojectile.isOnFire() && this.canBeLit(iblockdata)) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, movingobjectpositionblock.getBlockPos(), iprojectile).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
setLit(world, iblockdata, movingobjectpositionblock.getBlockPos(), true);
}

View File

@@ -0,0 +1,102 @@
--- a/net/minecraft/world/level/block/BigDripleafBlock.java
+++ b/net/minecraft/world/level/block/BigDripleafBlock.java
@@ -45,6 +45,11 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
+
public class BigDripleafBlock extends BlockFacingHorizontal implements IBlockFragilePlantElement, IBlockWaterlogged {
public static final MapCodec<BigDripleafBlock> CODEC = simpleCodec(BigDripleafBlock::new);
@@ -119,7 +124,7 @@
@Override
protected void onProjectileHit(World world, IBlockData iblockdata, MovingObjectPositionBlock movingobjectpositionblock, IProjectile iprojectile) {
- this.setTiltAndScheduleTick(iblockdata, world, movingobjectpositionblock.getBlockPos(), Tilt.FULL, SoundEffects.BIG_DRIPLEAF_TILT_DOWN);
+ this.setTiltAndScheduleTick(iblockdata, world, movingobjectpositionblock.getBlockPos(), Tilt.FULL, SoundEffects.BIG_DRIPLEAF_TILT_DOWN, iprojectile); // CraftBukkit
}
@Override
@@ -178,7 +183,20 @@
protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
if (!world.isClientSide) {
if (iblockdata.getValue(BigDripleafBlock.TILT) == Tilt.NONE && canEntityTilt(blockposition, entity) && !world.hasNeighborSignal(blockposition)) {
- this.setTiltAndScheduleTick(iblockdata, world, blockposition, Tilt.UNSTABLE, (SoundEffect) null);
+ // CraftBukkit start - tilt dripleaf
+ org.bukkit.event.Cancellable cancellable;
+ if (entity instanceof EntityHuman) {
+ cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ } else {
+ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ world.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
+ }
+
+ if (cancellable.isCancelled()) {
+ return;
+ }
+ this.setTiltAndScheduleTick(iblockdata, world, blockposition, Tilt.UNSTABLE, (SoundEffect) null, entity);
+ // CraftBukkit end
}
}
@@ -192,9 +210,9 @@
Tilt tilt = (Tilt) iblockdata.getValue(BigDripleafBlock.TILT);
if (tilt == Tilt.UNSTABLE) {
- this.setTiltAndScheduleTick(iblockdata, worldserver, blockposition, Tilt.PARTIAL, SoundEffects.BIG_DRIPLEAF_TILT_DOWN);
+ this.setTiltAndScheduleTick(iblockdata, worldserver, blockposition, Tilt.PARTIAL, SoundEffects.BIG_DRIPLEAF_TILT_DOWN, null); // CraftBukkit
} else if (tilt == Tilt.PARTIAL) {
- this.setTiltAndScheduleTick(iblockdata, worldserver, blockposition, Tilt.FULL, SoundEffects.BIG_DRIPLEAF_TILT_DOWN);
+ this.setTiltAndScheduleTick(iblockdata, worldserver, blockposition, Tilt.FULL, SoundEffects.BIG_DRIPLEAF_TILT_DOWN, null); // CraftBukkit
} else if (tilt == Tilt.FULL) {
resetTilt(iblockdata, worldserver, blockposition);
}
@@ -220,8 +238,10 @@
return entity.onGround() && entity.position().y > (double) ((float) blockposition.getY() + 0.6875F);
}
- private void setTiltAndScheduleTick(IBlockData iblockdata, World world, BlockPosition blockposition, Tilt tilt, @Nullable SoundEffect soundeffect) {
- setTilt(iblockdata, world, blockposition, tilt);
+ // CraftBukkit start
+ private void setTiltAndScheduleTick(IBlockData iblockdata, World world, BlockPosition blockposition, Tilt tilt, @Nullable SoundEffect soundeffect, @Nullable Entity entity) {
+ if (!setTilt(iblockdata, world, blockposition, tilt, entity)) return;
+ // CraftBukkit end
if (soundeffect != null) {
playTiltSound(world, blockposition, soundeffect);
}
@@ -235,14 +255,21 @@
}
private static void resetTilt(IBlockData iblockdata, World world, BlockPosition blockposition) {
- setTilt(iblockdata, world, blockposition, Tilt.NONE);
+ setTilt(iblockdata, world, blockposition, Tilt.NONE, null); // CraftBukkit
if (iblockdata.getValue(BigDripleafBlock.TILT) != Tilt.NONE) {
playTiltSound(world, blockposition, SoundEffects.BIG_DRIPLEAF_TILT_UP);
}
}
- private static void setTilt(IBlockData iblockdata, World world, BlockPosition blockposition, Tilt tilt) {
+ // CraftBukkit start
+ private static boolean setTilt(IBlockData iblockdata, World world, BlockPosition blockposition, Tilt tilt, @Nullable Entity entity) {
+ if (entity != null) {
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata.setValue(BigDripleafBlock.TILT, tilt))) {
+ return false;
+ }
+ }
+ // CraftBukkit end
Tilt tilt1 = (Tilt) iblockdata.getValue(BigDripleafBlock.TILT);
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BigDripleafBlock.TILT, tilt), 2);
@@ -250,6 +277,7 @@
world.gameEvent((Entity) null, (Holder) GameEvent.BLOCK_CHANGE, blockposition);
}
+ return true; // CraftBukkit
}
@Override

View File

@@ -0,0 +1,52 @@
--- a/net/minecraft/world/level/block/Block.java
+++ b/net/minecraft/world/level/block/Block.java
@@ -340,7 +340,13 @@
EntityItem entityitem = (EntityItem) supplier.get();
entityitem.setDefaultPickUpDelay();
- world.addFreshEntity(entityitem);
+ // CraftBukkit start
+ if (world.captureDrops != null) {
+ world.captureDrops.add(entityitem);
+ } else {
+ world.addFreshEntity(entityitem);
+ }
+ // CraftBukkit end
return;
}
}
@@ -369,7 +375,7 @@
public void playerDestroy(World world, EntityHuman entityhuman, BlockPosition blockposition, IBlockData iblockdata, @Nullable TileEntity tileentity, ItemStack itemstack) {
entityhuman.awardStat(StatisticList.BLOCK_MINED.get(this));
- entityhuman.causeFoodExhaustion(0.005F);
+ entityhuman.causeFoodExhaustion(0.005F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.BLOCK_MINED); // CraftBukkit - EntityExhaustionEvent
dropResources(iblockdata, world, blockposition, tileentity, entityhuman, itemstack);
}
@@ -490,15 +496,23 @@
return this.builtInRegistryHolder;
}
- protected void tryDropExperience(WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, IntProvider intprovider) {
+ // CraftBukkit start
+ protected int tryDropExperience(WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, IntProvider intprovider) {
int i = EnchantmentManager.processBlockExperience(worldserver, itemstack, intprovider.sample(worldserver.getRandom()));
if (i > 0) {
- this.popExperience(worldserver, blockposition, i);
+ // this.popExperience(worldserver, blockposition, i);
+ return i;
}
+ return 0;
}
+ public int getExpDrop(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) {
+ return 0;
+ }
+ // CraftBukkit end
+
private static record a(VoxelShape first, VoxelShape second) {
public boolean equals(Object object) {

View File

@@ -0,0 +1,48 @@
--- a/net/minecraft/world/level/block/BlockBamboo.java
+++ b/net/minecraft/world/level/block/BlockBamboo.java
@@ -183,7 +183,7 @@
BlockPosition blockposition1 = blockposition.above(i);
IBlockData iblockdata1 = worldserver.getBlockState(blockposition1);
- if (k >= 16 || (Integer) iblockdata1.getValue(BlockBamboo.STAGE) == 1 || !worldserver.isEmptyBlock(blockposition1.above())) {
+ if (k >= 16 || !iblockdata1.is(Blocks.BAMBOO) || (Integer) iblockdata1.getValue(BlockBamboo.STAGE) == 1 || !worldserver.isEmptyBlock(blockposition1.above())) { // CraftBukkit - If the BlockSpreadEvent was cancelled, we have no bamboo here
return;
}
@@ -204,14 +204,18 @@
BlockPosition blockposition1 = blockposition.below(2);
IBlockData iblockdata2 = world.getBlockState(blockposition1);
BlockPropertyBambooSize blockpropertybamboosize = BlockPropertyBambooSize.NONE;
+ boolean shouldUpdateOthers = false; // CraftBukkit
if (i >= 1) {
if (iblockdata1.is(Blocks.BAMBOO) && iblockdata1.getValue(BlockBamboo.LEAVES) != BlockPropertyBambooSize.NONE) {
if (iblockdata1.is(Blocks.BAMBOO) && iblockdata1.getValue(BlockBamboo.LEAVES) != BlockPropertyBambooSize.NONE) {
blockpropertybamboosize = BlockPropertyBambooSize.LARGE;
if (iblockdata2.is(Blocks.BAMBOO)) {
- world.setBlock(blockposition.below(), (IBlockData) iblockdata1.setValue(BlockBamboo.LEAVES, BlockPropertyBambooSize.SMALL), 3);
- world.setBlock(blockposition1, (IBlockData) iblockdata2.setValue(BlockBamboo.LEAVES, BlockPropertyBambooSize.NONE), 3);
+ // CraftBukkit start - moved down
+ // world.setBlock(blockposition.below(), (IBlockData) iblockdata1.setValue(BlockBamboo.LEAVES, BlockPropertyBambooSize.SMALL), 3);
+ // world.setBlock(blockposition1, (IBlockData) iblockdata2.setValue(BlockBamboo.LEAVES, BlockPropertyBambooSize.NONE), 3);
+ shouldUpdateOthers = true;
+ // CraftBukkit end
}
}
} else {
@@ -222,7 +226,14 @@
int j = (Integer) iblockdata.getValue(BlockBamboo.AGE) != 1 && !iblockdata2.is(Blocks.BAMBOO) ? 0 : 1;
int k = (i < 11 || randomsource.nextFloat() >= 0.25F) && i != 15 ? 0 : 1;
- world.setBlock(blockposition.above(), (IBlockData) ((IBlockData) ((IBlockData) this.defaultBlockState().setValue(BlockBamboo.AGE, j)).setValue(BlockBamboo.LEAVES, blockpropertybamboosize)).setValue(BlockBamboo.STAGE, k), 3);
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockSpreadEvent(world, blockposition, blockposition.above(), (IBlockData) ((IBlockData) ((IBlockData) this.defaultBlockState().setValue(BlockBamboo.AGE, j)).setValue(BlockBamboo.LEAVES, blockpropertybamboosize)).setValue(BlockBamboo.STAGE, k), 3)) {
+ if (shouldUpdateOthers) {
+ world.setBlock(blockposition.below(), (IBlockData) iblockdata1.setValue(BlockBamboo.LEAVES, BlockPropertyBambooSize.SMALL), 3);
+ world.setBlock(blockposition1, (IBlockData) iblockdata2.setValue(BlockBamboo.LEAVES, BlockPropertyBambooSize.NONE), 3);
+ }
+ }
+ // CraftBukkit end
}
protected int getHeightAboveUpToMax(IBlockAccess iblockaccess, BlockPosition blockposition) {

View File

@@ -0,0 +1,10 @@
--- a/net/minecraft/world/level/block/BlockBambooSapling.java
+++ b/net/minecraft/world/level/block/BlockBambooSapling.java
@@ -87,6 +87,6 @@
}
protected void growBamboo(World world, BlockPosition blockposition) {
- world.setBlock(blockposition.above(), (IBlockData) Blocks.BAMBOO.defaultBlockState().setValue(BlockBamboo.LEAVES, BlockPropertyBambooSize.SMALL), 3);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockSpreadEvent(world, blockposition, blockposition.above(), (IBlockData) Blocks.BAMBOO.defaultBlockState().setValue(BlockBamboo.LEAVES, BlockPropertyBambooSize.SMALL), 3); // CraftBukkit - BlockSpreadEvent
}
}

View File

@@ -0,0 +1,73 @@
--- a/net/minecraft/world/level/block/BlockBed.java
+++ b/net/minecraft/world/level/block/BlockBed.java
@@ -95,7 +95,8 @@
}
}
- if (!canSetSpawn(world)) {
+ // CraftBukkit - moved world and biome check into EntityHuman
+ if (false && !canSetSpawn(world)) {
world.removeBlock(blockposition, false);
BlockPosition blockposition1 = blockposition.relative(((EnumDirection) iblockdata.getValue(BlockBed.FACING)).getOpposite());
@@ -114,7 +115,16 @@
return EnumInteractionResult.SUCCESS_SERVER;
} else {
+ // CraftBukkit start
+ IBlockData finaliblockdata = iblockdata;
+ BlockPosition finalblockposition = blockposition;
+ // CraftBukkit end
entityhuman.startSleepInBed(blockposition).ifLeft((entityhuman_enumbedresult) -> {
+ // CraftBukkit start - handling bed explosion from below here
+ if (!world.dimensionType().bedWorks()) {
+ this.explodeBed(finaliblockdata, world, finalblockposition);
+ } else
+ // CraftBukkit end
if (entityhuman_enumbedresult.getMessage() != null) {
entityhuman.displayClientMessage(entityhuman_enumbedresult.getMessage(), true);
}
@@ -125,8 +135,30 @@
}
}
+ // CraftBukkit start
+ private EnumInteractionResult explodeBed(IBlockData iblockdata, World world, BlockPosition blockposition) {
+ {
+ {
+ org.bukkit.block.BlockState blockState = org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition).getState(); // CraftBukkit - capture BlockState before remove block
+ world.removeBlock(blockposition, false);
+ BlockPosition blockposition1 = blockposition.relative(((EnumDirection) iblockdata.getValue(BlockBed.FACING)).getOpposite());
+
+ if (world.getBlockState(blockposition1).getBlock() == this) {
+ world.removeBlock(blockposition1, false);
+ }
+
+ Vec3D vec3d = blockposition.getCenter();
+
+ world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d, blockState), (ExplosionDamageCalculator) null, vec3d, 5.0F, true, World.a.BLOCK); // CraftBukkit - add state
+ return EnumInteractionResult.SUCCESS;
+ }
+ }
+ }
+ // CraftBukkit end
+
public static boolean canSetSpawn(World world) {
- return world.dimensionType().bedWorks();
+ // CraftBukkit - moved world and biome check into EntityHuman
+ return true || world.dimensionType().bedWorks();
}
private boolean kickVillagerOutOfBed(World world, BlockPosition blockposition) {
@@ -320,6 +352,11 @@
BlockPosition blockposition1 = blockposition.relative((EnumDirection) iblockdata.getValue(BlockBed.FACING));
world.setBlock(blockposition1, (IBlockData) iblockdata.setValue(BlockBed.PART, BlockPropertyBedPart.HEAD), 3);
+ // CraftBukkit start - SPIGOT-7315: Don't updated if we capture block states
+ if (world.captureBlockStates) {
+ return;
+ }
+ // CraftBukkit end
world.blockUpdated(blockposition, Blocks.AIR);
iblockdata.updateNeighbourShapes(world, blockposition, 3);
}

View File

@@ -0,0 +1,29 @@
--- a/net/minecraft/world/level/block/BlockBeehive.java
+++ b/net/minecraft/world/level/block/BlockBeehive.java
@@ -133,7 +133,7 @@
if (entitybee.getTarget() == null) {
EntityHuman entityhuman = (EntityHuman) SystemUtils.getRandom(list1, world.random);
- entitybee.setTarget(entityhuman);
+ entitybee.setTarget(entityhuman, org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); // CraftBukkit
}
}
}
@@ -297,7 +297,7 @@
ItemStack itemstack = new ItemStack(this);
itemstack.applyComponents(tileentitybeehive.collectComponents());
- itemstack.set(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(BlockBeehive.HONEY_LEVEL, (Comparable) i));
+ itemstack.set(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(BlockBeehive.HONEY_LEVEL, i)); // CraftBukkit - decompile error
EntityItem entityitem = new EntityItem(world, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack);
entityitem.setDefaultPickUpDelay();
@@ -332,7 +332,7 @@
ItemStack itemstack = super.getCloneItemStack(iworldreader, blockposition, iblockdata, flag);
if (flag) {
- itemstack.set(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(BlockBeehive.HONEY_LEVEL, (Comparable) ((Integer) iblockdata.getValue(BlockBeehive.HONEY_LEVEL))));
+ itemstack.set(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(BlockBeehive.HONEY_LEVEL, ((Integer) iblockdata.getValue(BlockBeehive.HONEY_LEVEL)))); // CraftBukkit - decompile error
}
return itemstack;

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockBell.java
+++ b/net/minecraft/world/level/block/BlockBell.java
@@ -148,6 +148,11 @@
if (enumdirection == null) {
enumdirection = (EnumDirection) world.getBlockState(blockposition).getValue(BlockBell.FACING);
}
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBellRingEvent(world, blockposition, enumdirection, entity)) {
+ return false;
+ }
+ // CraftBukkit end
((TileEntityBell) tileentity).onHit(enumdirection);
world.playSound((EntityHuman) null, blockposition, SoundEffects.BELL_BLOCK, SoundCategory.BLOCKS, 2.0F, 1.0F);

View File

@@ -0,0 +1,72 @@
--- a/net/minecraft/world/level/block/BlockButtonAbstract.java
+++ b/net/minecraft/world/level/block/BlockButtonAbstract.java
@@ -35,6 +35,11 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import org.bukkit.event.block.BlockRedstoneEvent;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
+
public class BlockButtonAbstract extends BlockAttachable {
public static final MapCodec<BlockButtonAbstract> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -126,6 +131,19 @@
if ((Boolean) iblockdata.getValue(BlockButtonAbstract.POWERED)) {
return EnumInteractionResult.CONSUME;
} else {
+ // CraftBukkit start
+ boolean powered = ((Boolean) iblockdata.getValue(POWERED));
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ int old = (powered) ? 15 : 0;
+ int current = (!powered) ? 15 : 0;
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current);
+ world.getCraftServer().getPluginManager().callEvent(eventRedstone);
+
+ if ((eventRedstone.getNewCurrent() > 0) != (!powered)) {
+ return EnumInteractionResult.SUCCESS;
+ }
+ // CraftBukkit end
this.press(iblockdata, world, blockposition, entityhuman);
return EnumInteractionResult.SUCCESS;
}
@@ -197,11 +215,36 @@
}
protected void checkPressed(IBlockData iblockdata, World world, BlockPosition blockposition) {
- EntityArrow entityarrow = this.type.canButtonBeActivatedByArrows() ? (EntityArrow) world.getEntitiesOfClass(EntityArrow.class, iblockdata.getShape(world, blockposition).bounds().move(blockposition)).stream().findFirst().orElse((Object) null) : null;
+ EntityArrow entityarrow = this.type.canButtonBeActivatedByArrows() ? (EntityArrow) world.getEntitiesOfClass(EntityArrow.class, iblockdata.getShape(world, blockposition).bounds().move(blockposition)).stream().findFirst().orElse(null) : null; // CraftBukkit - decompile error
boolean flag = entityarrow != null;
boolean flag1 = (Boolean) iblockdata.getValue(BlockButtonAbstract.POWERED);
+ // CraftBukkit start - Call interact event when arrows turn on wooden buttons
+ if (flag1 != flag && flag) {
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ EntityInteractEvent event = new EntityInteractEvent(entityarrow.getBukkitEntity(), block);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
+
if (flag != flag1) {
+ // CraftBukkit start
+ boolean powered = flag1;
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ int old = (powered) ? 15 : 0;
+ int current = (!powered) ? 15 : 0;
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current);
+ world.getCraftServer().getPluginManager().callEvent(eventRedstone);
+
+ if ((flag && eventRedstone.getNewCurrent() <= 0) || (!flag && eventRedstone.getNewCurrent() > 0)) {
+ return;
+ }
+ // CraftBukkit end
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockButtonAbstract.POWERED, flag), 3);
this.updateNeighbours(iblockdata, world, blockposition);
this.playSound((EntityHuman) null, world, blockposition, flag);

View File

@@ -0,0 +1,29 @@
--- a/net/minecraft/world/level/block/BlockCactus.java
+++ b/net/minecraft/world/level/block/BlockCactus.java
@@ -23,6 +23,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class BlockCactus extends Block {
public static final MapCodec<BlockCactus> CODEC = simpleCodec(BlockCactus::new);
@@ -65,7 +67,7 @@
int j = (Integer) iblockdata.getValue(BlockCactus.AGE);
if (j == 15) {
- worldserver.setBlockAndUpdate(blockposition1, this.defaultBlockState());
+ CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition1, this.defaultBlockState()); // CraftBukkit
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockCactus.AGE, 0);
worldserver.setBlock(blockposition, iblockdata1, 4);
@@ -120,7 +122,7 @@
@Override
protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
- entity.hurt(world.damageSources().cactus(), 1.0F);
+ entity.hurt(world.damageSources().cactus().directBlock(world, blockposition), 1.0F); // CraftBukkit
}
@Override

View File

@@ -0,0 +1,22 @@
--- a/net/minecraft/world/level/block/BlockCake.java
+++ b/net/minecraft/world/level/block/BlockCake.java
@@ -98,7 +98,18 @@
return EnumInteractionResult.PASS;
} else {
entityhuman.awardStat(StatisticList.EAT_CAKE_SLICE);
- entityhuman.getFoodData().eat(2, 0.1F);
+ // CraftBukkit start
+ // entityhuman.getFoodData().eat(2, 0.1F);
+ int oldFoodLevel = entityhuman.getFoodData().foodLevel;
+
+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, 2 + oldFoodLevel);
+
+ if (!event.isCancelled()) {
+ entityhuman.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, 0.1F);
+ }
+
+ ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().sendHealthUpdate();
+ // CraftBukkit end
int i = (Integer) iblockdata.getValue(BlockCake.BITES);
generatoraccess.gameEvent((Entity) entityhuman, (Holder) GameEvent.EAT, blockposition);

View File

@@ -0,0 +1,23 @@
--- a/net/minecraft/world/level/block/BlockCampfire.java
+++ b/net/minecraft/world/level/block/BlockCampfire.java
@@ -113,7 +113,7 @@
@Override
protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
if ((Boolean) iblockdata.getValue(BlockCampfire.LIT) && entity instanceof EntityLiving) {
- entity.hurt(world.damageSources().campfire(), (float) this.fireDamage);
+ entity.hurt(world.damageSources().campfire().directBlock(world, blockposition), (float) this.fireDamage); // CraftBukkit
}
super.entityInside(iblockdata, world, blockposition, entity);
@@ -219,6 +219,11 @@
if (world instanceof WorldServer worldserver) {
if (iprojectile.isOnFire() && iprojectile.mayInteract(worldserver, blockposition) && !(Boolean) iblockdata.getValue(BlockCampfire.LIT) && !(Boolean) iblockdata.getValue(BlockCampfire.WATERLOGGED)) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, iprojectile).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockProperties.LIT, true), 11);
}
}

View File

@@ -0,0 +1,29 @@
--- a/net/minecraft/world/level/block/BlockCauldron.java
+++ b/net/minecraft/world/level/block/BlockCauldron.java
@@ -13,6 +13,10 @@
import net.minecraft.world.level.material.FluidType;
import net.minecraft.world.level.material.FluidTypes;
+// CraftBukkit start
+import org.bukkit.event.block.CauldronLevelChangeEvent;
+// CraftBukkit end
+
public class BlockCauldron extends AbstractCauldronBlock {
public static final MapCodec<BlockCauldron> CODEC = simpleCodec(BlockCauldron::new);
@@ -62,13 +66,11 @@
if (fluidtype == FluidTypes.WATER) {
iblockdata1 = Blocks.WATER_CAULDRON.defaultBlockState();
- world.setBlockAndUpdate(blockposition, iblockdata1);
- world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1));
+ LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, iblockdata1, null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL); // CraftBukkit
world.levelEvent(1047, blockposition, 0);
} else if (fluidtype == FluidTypes.LAVA) {
iblockdata1 = Blocks.LAVA_CAULDRON.defaultBlockState();
- world.setBlockAndUpdate(blockposition, iblockdata1);
- world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1));
+ LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, iblockdata1, null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL); // CraftBukkit
world.levelEvent(1046, blockposition, 0);
}

View File

@@ -0,0 +1,92 @@
--- a/net/minecraft/world/level/block/BlockChest.java
+++ b/net/minecraft/world/level/block/BlockChest.java
@@ -91,24 +91,7 @@
public Optional<ITileInventory> acceptDouble(final TileEntityChest tileentitychest, final TileEntityChest tileentitychest1) {
final InventoryLargeChest inventorylargechest = new InventoryLargeChest(tileentitychest, tileentitychest1);
- return Optional.of(new ITileInventory(this) {
- @Nullable
- @Override
- public Container createMenu(int i, PlayerInventory playerinventory, EntityHuman entityhuman) {
- if (tileentitychest.canOpen(entityhuman) && tileentitychest1.canOpen(entityhuman)) {
- tileentitychest.unpackLootTable(playerinventory.player);
- tileentitychest1.unpackLootTable(playerinventory.player);
- return ContainerChest.sixRows(i, playerinventory, inventorylargechest);
- } else {
- return null;
- }
- }
-
- @Override
- public IChatBaseComponent getDisplayName() {
- return (IChatBaseComponent) (tileentitychest.hasCustomName() ? tileentitychest.getDisplayName() : (tileentitychest1.hasCustomName() ? tileentitychest1.getDisplayName() : IChatBaseComponent.translatable("container.chestDouble")));
- }
- });
+ return Optional.of(new DoubleInventory(tileentitychest, tileentitychest1, inventorylargechest)); // CraftBukkit // CraftBukkit - decompile error
}
public Optional<ITileInventory> acceptSingle(TileEntityChest tileentitychest) {
@@ -121,6 +104,38 @@
}
};
+ // CraftBukkit start
+ public static class DoubleInventory implements ITileInventory {
+
+ private final TileEntityChest tileentitychest;
+ private final TileEntityChest tileentitychest1;
+ public final InventoryLargeChest inventorylargechest;
+
+ public DoubleInventory(TileEntityChest tileentitychest, TileEntityChest tileentitychest1, InventoryLargeChest inventorylargechest) {
+ this.tileentitychest = tileentitychest;
+ this.tileentitychest1 = tileentitychest1;
+ this.inventorylargechest = inventorylargechest;
+ }
+
+ @Nullable
+ @Override
+ public Container createMenu(int i, PlayerInventory playerinventory, EntityHuman entityhuman) {
+ if (tileentitychest.canOpen(entityhuman) && tileentitychest1.canOpen(entityhuman)) {
+ tileentitychest.unpackLootTable(playerinventory.player);
+ tileentitychest1.unpackLootTable(playerinventory.player);
+ return ContainerChest.sixRows(i, playerinventory, inventorylargechest);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public IChatBaseComponent getDisplayName() {
+ return (IChatBaseComponent) (tileentitychest.hasCustomName() ? tileentitychest.getDisplayName() : (tileentitychest1.hasCustomName() ? tileentitychest1.getDisplayName() : IChatBaseComponent.translatable("container.chestDouble")));
+ }
+ };
+ // CraftBukkit end
+
@Override
public MapCodec<? extends BlockChest> codec() {
return BlockChest.CODEC;
@@ -257,7 +272,7 @@
@Override
public DoubleBlockFinder.Result<? extends TileEntityChest> combine(IBlockData iblockdata, World world, BlockPosition blockposition, boolean flag) {
- BiPredicate bipredicate;
+ BiPredicate<GeneratorAccess, BlockPosition> bipredicate; // CraftBukkit - decompile error
if (flag) {
bipredicate = (generatoraccess, blockposition1) -> {
@@ -273,7 +288,14 @@
@Nullable
@Override
protected ITileInventory getMenuProvider(IBlockData iblockdata, World world, BlockPosition blockposition) {
- return (ITileInventory) ((Optional) this.combine(iblockdata, world, blockposition, false).apply(BlockChest.MENU_PROVIDER_COMBINER)).orElse((Object) null);
+ // CraftBukkit start
+ return getMenuProvider(iblockdata, world, blockposition, false);
+ }
+
+ @Nullable
+ public ITileInventory getMenuProvider(IBlockData iblockdata, World world, BlockPosition blockposition, boolean ignoreObstructions) {
+ return (ITileInventory) ((Optional) this.combine(iblockdata, world, blockposition, ignoreObstructions).apply(BlockChest.MENU_PROVIDER_COMBINER)).orElse((Object) null);
+ // CraftBukkit end
}
public static DoubleBlockFinder.Combiner<TileEntityChest, Float2FloatFunction> opennessCombiner(final LidBlockEntity lidblockentity) {

View File

@@ -0,0 +1,73 @@
--- a/net/minecraft/world/level/block/BlockChorusFlower.java
+++ b/net/minecraft/world/level/block/BlockChorusFlower.java
@@ -23,6 +23,8 @@
import net.minecraft.world.phys.MovingObjectPositionBlock;
import net.minecraft.world.phys.shapes.VoxelShape;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class BlockChorusFlower extends Block {
public static final MapCodec<BlockChorusFlower> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -103,8 +105,12 @@
}
if (flag && allNeighborsEmpty(worldserver, blockposition1, (EnumDirection) null) && worldserver.isEmptyBlock(blockposition.above(2))) {
- worldserver.setBlock(blockposition, BlockChorusFruit.getStateWithConnections(worldserver, blockposition, this.plant.defaultBlockState()), 2);
- this.placeGrownFlower(worldserver, blockposition1, i);
+ // CraftBukkit start - add event
+ if (CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition1, this.defaultBlockState().setValue(BlockChorusFlower.AGE, Integer.valueOf(i)), 2)) {
+ worldserver.setBlock(blockposition, BlockChorusFruit.getStateWithConnections(worldserver, blockposition, this.plant.defaultBlockState()), 2);
+ this.placeGrownFlower(worldserver, blockposition1, i);
+ }
+ // CraftBukkit end
} else if (i < 4) {
j = randomsource.nextInt(4);
if (flag1) {
@@ -118,18 +124,30 @@
BlockPosition blockposition2 = blockposition.relative(enumdirection);
if (worldserver.isEmptyBlock(blockposition2) && worldserver.isEmptyBlock(blockposition2.below()) && allNeighborsEmpty(worldserver, blockposition2, enumdirection.getOpposite())) {
- this.placeGrownFlower(worldserver, blockposition2, i + 1);
- flag2 = true;
+ // CraftBukkit start - add event
+ if (CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition2, this.defaultBlockState().setValue(BlockChorusFlower.AGE, Integer.valueOf(i + 1)), 2)) {
+ this.placeGrownFlower(worldserver, blockposition2, i + 1);
+ flag2 = true;
+ }
+ // CraftBukkit end
}
}
if (flag2) {
worldserver.setBlock(blockposition, BlockChorusFruit.getStateWithConnections(worldserver, blockposition, this.plant.defaultBlockState()), 2);
} else {
- this.placeDeadFlower(worldserver, blockposition);
+ // CraftBukkit start - add event
+ if (CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, this.defaultBlockState().setValue(BlockChorusFlower.AGE, Integer.valueOf(5)), 2)) {
+ this.placeDeadFlower(worldserver, blockposition);
+ }
+ // CraftBukkit end
}
} else {
- this.placeDeadFlower(worldserver, blockposition);
+ // CraftBukkit start - add event
+ if (CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, this.defaultBlockState().setValue(BlockChorusFlower.AGE, Integer.valueOf(5)), 2)) {
+ this.placeDeadFlower(worldserver, blockposition);
+ }
+ // CraftBukkit end
}
}
@@ -267,6 +285,11 @@
if (world instanceof WorldServer worldserver) {
if (iprojectile.mayInteract(worldserver, blockposition) && iprojectile.mayBreak(worldserver)) {
+ // CraftBukkit
+ if (!CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end
world.destroyBlock(blockposition, true, iprojectile);
}
}

View File

@@ -0,0 +1,29 @@
--- a/net/minecraft/world/level/block/BlockCocoa.java
+++ b/net/minecraft/world/level/block/BlockCocoa.java
@@ -21,6 +21,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class BlockCocoa extends BlockFacingHorizontal implements IBlockFragilePlantElement {
public static final MapCodec<BlockCocoa> CODEC = simpleCodec(BlockCocoa::new);
@@ -61,7 +63,7 @@
int i = (Integer) iblockdata.getValue(BlockCocoa.AGE);
if (i < 2) {
- worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockCocoa.AGE, i + 1), 2);
+ CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, (IBlockData) iblockdata.setValue(BlockCocoa.AGE, i + 1), 2); // CraftBukkkit
}
}
@@ -131,7 +133,7 @@
@Override
public void performBonemeal(WorldServer worldserver, RandomSource randomsource, BlockPosition blockposition, IBlockData iblockdata) {
- worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockCocoa.AGE, (Integer) iblockdata.getValue(BlockCocoa.AGE) + 1), 2);
+ CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, (IBlockData) iblockdata.setValue(BlockCocoa.AGE, (Integer) iblockdata.getValue(BlockCocoa.AGE) + 1), 2); // CraftBukkit
}
@Override

View File

@@ -0,0 +1,27 @@
--- a/net/minecraft/world/level/block/BlockCommand.java
+++ b/net/minecraft/world/level/block/BlockCommand.java
@@ -31,6 +31,8 @@
import net.minecraft.world.phys.MovingObjectPositionBlock;
import org.slf4j.Logger;
+import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
+
public class BlockCommand extends BlockTileEntity implements GameMasterBlock {
public static final MapCodec<BlockCommand> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -78,6 +80,15 @@
private void setPoweredAndUpdate(World world, BlockPosition blockposition, TileEntityCommand tileentitycommand, boolean flag) {
boolean flag1 = tileentitycommand.isPowered();
+ // CraftBukkit start
+ org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ int old = flag1 ? 15 : 0;
+ int current = flag ? 15 : 0;
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, old, current);
+ world.getCraftServer().getPluginManager().callEvent(eventRedstone);
+ flag = eventRedstone.getNewCurrent() > 0;
+ // CraftBukkit end
if (flag != flag1) {
tileentitycommand.setPowered(flag);

View File

@@ -0,0 +1,116 @@
--- a/net/minecraft/world/level/block/BlockComposter.java
+++ b/net/minecraft/world/level/block/BlockComposter.java
@@ -42,6 +42,11 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftBlockInventoryHolder;
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
+// CraftBukkit end
+
public class BlockComposter extends Block implements IInventoryHolder {
public static final MapCodec<BlockComposter> CODEC = simpleCodec(BlockComposter::new);
@@ -269,7 +274,14 @@
int i = (Integer) iblockdata.getValue(BlockComposter.LEVEL);
if (i < 7 && BlockComposter.COMPOSTABLES.containsKey(itemstack.getItem())) {
- IBlockData iblockdata1 = addItem(entity, iblockdata, worldserver, blockposition, itemstack);
+ // CraftBukkit start
+ double rand = worldserver.getRandom().nextDouble();
+ IBlockData iblockdata1 = addItem(entity, iblockdata, DummyGeneratorAccess.INSTANCE, blockposition, itemstack, rand);
+ if (iblockdata == iblockdata1 || !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1)) {
+ return iblockdata;
+ }
+ iblockdata1 = addItem(entity, iblockdata, worldserver, blockposition, itemstack, rand);
+ // CraftBukkit end
itemstack.shrink(1);
return iblockdata1;
@@ -279,6 +291,14 @@
}
public static IBlockData extractProduce(Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) {
+ // CraftBukkit start
+ if (entity != null && !(entity instanceof EntityHuman)) {
+ IBlockData iblockdata1 = empty(entity, iblockdata, DummyGeneratorAccess.INSTANCE, blockposition);
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1)) {
+ return iblockdata;
+ }
+ }
+ // CraftBukkit end
if (!world.isClientSide) {
Vec3D vec3d = Vec3D.atLowerCornerWithOffset(blockposition, 0.5D, 1.01D, 0.5D).offsetRandom(world.random, 0.7F);
EntityItem entityitem = new EntityItem(world, vec3d.x(), vec3d.y(), vec3d.z(), new ItemStack(Items.BONE_MEAL));
@@ -302,10 +322,16 @@
}
static IBlockData addItem(@Nullable Entity entity, IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack) {
+ // CraftBukkit start
+ return addItem(entity, iblockdata, generatoraccess, blockposition, itemstack, generatoraccess.getRandom().nextDouble());
+ }
+
+ static IBlockData addItem(@Nullable Entity entity, IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack, double rand) {
+ // CraftBukkit end
int i = (Integer) iblockdata.getValue(BlockComposter.LEVEL);
float f = BlockComposter.COMPOSTABLES.getFloat(itemstack.getItem());
- if ((i != 0 || f <= 0.0F) && generatoraccess.getRandom().nextDouble() >= (double) f) {
+ if ((i != 0 || f <= 0.0F) && rand >= (double) f) {
return iblockdata;
} else {
int j = i + 1;
@@ -354,7 +380,8 @@
public IWorldInventory getContainer(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) {
int i = (Integer) iblockdata.getValue(BlockComposter.LEVEL);
- return (IWorldInventory) (i == 8 ? new BlockComposter.ContainerOutput(iblockdata, generatoraccess, blockposition, new ItemStack(Items.BONE_MEAL)) : (i < 7 ? new BlockComposter.ContainerInput(iblockdata, generatoraccess, blockposition) : new BlockComposter.ContainerEmpty()));
+ // CraftBukkit - empty generatoraccess, blockposition
+ return (IWorldInventory) (i == 8 ? new BlockComposter.ContainerOutput(iblockdata, generatoraccess, blockposition, new ItemStack(Items.BONE_MEAL)) : (i < 7 ? new BlockComposter.ContainerInput(iblockdata, generatoraccess, blockposition) : new BlockComposter.ContainerEmpty(generatoraccess, blockposition)));
}
public static class ContainerOutput extends InventorySubcontainer implements IWorldInventory {
@@ -369,6 +396,7 @@
this.state = iblockdata;
this.level = generatoraccess;
this.pos = blockposition;
+ this.bukkitOwner = new CraftBlockInventoryHolder(generatoraccess, blockposition, this); // CraftBukkit
}
@Override
@@ -393,8 +421,15 @@
@Override
public void setChanged() {
+ // CraftBukkit start - allow putting items back (eg cancelled InventoryMoveItemEvent)
+ if (this.isEmpty()) {
BlockComposter.empty((Entity) null, this.state, this.level, this.pos);
this.changed = true;
+ } else {
+ this.level.setBlock(this.pos, this.state, 3);
+ this.changed = false;
+ }
+ // CraftBukkit end
}
}
@@ -407,6 +442,7 @@
public ContainerInput(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) {
super(1);
+ this.bukkitOwner = new CraftBlockInventoryHolder(generatoraccess, blockposition, this); // CraftBukkit
this.state = iblockdata;
this.level = generatoraccess;
this.pos = blockposition;
@@ -449,8 +485,9 @@
public static class ContainerEmpty extends InventorySubcontainer implements IWorldInventory {
- public ContainerEmpty() {
+ public ContainerEmpty(GeneratorAccess generatoraccess, BlockPosition blockposition) { // CraftBukkit
super(0);
+ this.bukkitOwner = new CraftBlockInventoryHolder(generatoraccess, blockposition, this); // CraftBukkit
}
@Override

View File

@@ -0,0 +1,77 @@
--- a/net/minecraft/world/level/block/BlockConcretePowder.java
+++ b/net/minecraft/world/level/block/BlockConcretePowder.java
@@ -16,6 +16,12 @@
import net.minecraft.world.level.block.state.BlockBase;
import net.minecraft.world.level.block.state.IBlockData;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.block.CraftBlockStates;
+import org.bukkit.event.block.BlockFormEvent;
+// CraftBukkit end
+
public class BlockConcretePowder extends BlockFalling {
public static final MapCodec<BlockConcretePowder> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -38,7 +44,7 @@
@Override
public void onLand(World world, BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1, EntityFallingBlock entityfallingblock) {
if (shouldSolidify(world, blockposition, iblockdata1)) {
- world.setBlock(blockposition, this.concrete.defaultBlockState(), 3);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(world, blockposition, this.concrete.defaultBlockState(), 3); // CraftBukkit
}
}
@@ -49,7 +55,24 @@
BlockPosition blockposition = blockactioncontext.getClickedPos();
IBlockData iblockdata = world.getBlockState(blockposition);
- return shouldSolidify(world, blockposition, iblockdata) ? this.concrete.defaultBlockState() : super.getStateForPlacement(blockactioncontext);
+ // CraftBukkit start
+ if (!shouldSolidify(world, blockposition, iblockdata)) {
+ return super.getStateForPlacement(blockactioncontext);
+ }
+
+ // TODO: An event factory call for methods like this
+ CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockposition);
+ blockState.setData(this.concrete.defaultBlockState());
+
+ BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);
+ world.getServer().server.getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ return blockState.getHandle();
+ }
+
+ return super.getStateForPlacement(blockactioncontext);
+ // CraftBukkit end
}
private static boolean shouldSolidify(IBlockAccess iblockaccess, BlockPosition blockposition, IBlockData iblockdata) {
@@ -85,7 +108,25 @@
@Override
protected IBlockData updateShape(IBlockData iblockdata, IWorldReader iworldreader, ScheduledTickAccess scheduledtickaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition blockposition1, IBlockData iblockdata1, RandomSource randomsource) {
- return touchesLiquid(iworldreader, blockposition) ? this.concrete.defaultBlockState() : super.updateShape(iblockdata, iworldreader, scheduledtickaccess, blockposition, enumdirection, blockposition1, iblockdata1, randomsource);
+ // CraftBukkit start
+ if (touchesLiquid(iworldreader, blockposition)) {
+ // Suppress during worldgen
+ if (!(iworldreader instanceof World world)) {
+ return this.concrete.defaultBlockState();
+ }
+ CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockposition);
+ blockState.setData(this.concrete.defaultBlockState());
+
+ BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ return blockState.getHandle();
+ }
+ }
+
+ return super.updateShape(iblockdata, iworldreader, scheduledtickaccess, blockposition, enumdirection, blockposition1, iblockdata1, randomsource);
+ // CraftBukkit end
}
@Override

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockCoral.java
+++ b/net/minecraft/world/level/block/BlockCoral.java
@@ -40,6 +40,11 @@
@Override
protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if (!this.scanForWater(worldserver, blockposition)) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, this.deadBlock.defaultBlockState()).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, this.deadBlock.defaultBlockState(), 2);
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockCoralFan.java
+++ b/net/minecraft/world/level/block/BlockCoralFan.java
@@ -41,6 +41,11 @@
@Override
protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if (!scanForWater(iblockdata, worldserver, blockposition)) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, this.deadBlock.defaultBlockState().setValue(BlockCoralFan.WATERLOGGED, false)).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) this.deadBlock.defaultBlockState().setValue(BlockCoralFan.WATERLOGGED, false), 2);
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockCoralFanWall.java
+++ b/net/minecraft/world/level/block/BlockCoralFanWall.java
@@ -41,6 +41,11 @@
@Override
protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if (!scanForWater(iblockdata, worldserver, blockposition)) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, this.deadBlock.defaultBlockState().setValue(BlockCoralFanWall.WATERLOGGED, false).setValue(BlockCoralFanWall.FACING, iblockdata.getValue(BlockCoralFanWall.FACING))).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) ((IBlockData) this.deadBlock.defaultBlockState().setValue(BlockCoralFanWall.WATERLOGGED, false)).setValue(BlockCoralFanWall.FACING, (EnumDirection) iblockdata.getValue(BlockCoralFanWall.FACING)), 2);
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockCoralPlant.java
+++ b/net/minecraft/world/level/block/BlockCoralPlant.java
@@ -46,6 +46,11 @@
@Override
protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if (!scanForWater(iblockdata, worldserver, blockposition)) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, this.deadBlock.defaultBlockState().setValue(BlockCoralPlant.WATERLOGGED, false)).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) this.deadBlock.defaultBlockState().setValue(BlockCoralPlant.WATERLOGGED, false), 2);
}

View File

@@ -0,0 +1,38 @@
--- a/net/minecraft/world/level/block/BlockCrops.java
+++ b/net/minecraft/world/level/block/BlockCrops.java
@@ -22,6 +22,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class BlockCrops extends BlockPlant implements IBlockFragilePlantElement {
public static final MapCodec<BlockCrops> CODEC = simpleCodec(BlockCrops::new);
@@ -83,7 +85,7 @@
float f = getGrowthSpeed(this, worldserver, blockposition);
if (randomsource.nextInt((int) (25.0F / f) + 1) == 0) {
- worldserver.setBlock(blockposition, this.getStateForAge(i + 1), 2);
+ CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, this.getStateForAge(i + 1), 2); // CraftBukkit
}
}
}
@@ -98,7 +100,7 @@
i = j;
}
- world.setBlock(blockposition, this.getStateForAge(i), 2);
+ CraftEventFactory.handleBlockGrowEvent(world, blockposition, this.getStateForAge(i), 2); // CraftBukkit
}
protected int getBonemealAgeIncrease(World world) {
@@ -161,7 +163,7 @@
@Override
protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
if (world instanceof WorldServer worldserver) {
- if (entity instanceof EntityRavager && worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
+ if (entity instanceof EntityRavager && CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState(), !worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit
worldserver.destroyBlock(blockposition, true, entity);
}
}

View File

@@ -0,0 +1,10 @@
--- a/net/minecraft/world/level/block/BlockDaylightDetector.java
+++ b/net/minecraft/world/level/block/BlockDaylightDetector.java
@@ -74,6 +74,7 @@
i = MathHelper.clamp(i, 0, 15);
if ((Integer) iblockdata.getValue(BlockDaylightDetector.POWER) != i) {
+ i = org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, blockposition, ((Integer) iblockdata.getValue(POWER)), i).getNewCurrent(); // CraftBukkit - Call BlockRedstoneEvent
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockDaylightDetector.POWER, i), 3);
}

View File

@@ -0,0 +1,30 @@
--- a/net/minecraft/world/level/block/BlockDiodeAbstract.java
+++ b/net/minecraft/world/level/block/BlockDiodeAbstract.java
@@ -24,6 +24,8 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.ticks.TickListPriority;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public abstract class BlockDiodeAbstract extends BlockFacingHorizontal {
protected static final VoxelShape SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D);
@@ -59,8 +61,18 @@
boolean flag1 = this.shouldTurnOn(worldserver, blockposition, iblockdata);
if (flag && !flag1) {
+ // CraftBukkit start
+ if (CraftEventFactory.callRedstoneChange(worldserver, blockposition, 15, 0).getNewCurrent() != 0) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockDiodeAbstract.POWERED, false), 2);
} else if (!flag) {
+ // CraftBukkit start
+ if (CraftEventFactory.callRedstoneChange(worldserver, blockposition, 0, 15).getNewCurrent() != 15) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockDiodeAbstract.POWERED, true), 2);
if (!flag1) {
worldserver.scheduleTick(blockposition, (Block) this, this.getDelay(iblockdata), TickListPriority.VERY_HIGH);

View File

@@ -0,0 +1,23 @@
--- a/net/minecraft/world/level/block/BlockDirtSnowSpreadable.java
+++ b/net/minecraft/world/level/block/BlockDirtSnowSpreadable.java
@@ -44,6 +44,11 @@
@Override
protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if (!canBeGrass(iblockdata, worldserver, blockposition)) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, Blocks.DIRT.defaultBlockState()).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlockAndUpdate(blockposition, Blocks.DIRT.defaultBlockState());
} else {
if (worldserver.getMaxLocalRawBrightness(blockposition.above()) >= 9) {
@@ -53,7 +58,7 @@
BlockPosition blockposition1 = blockposition.offset(randomsource.nextInt(3) - 1, randomsource.nextInt(5) - 3, randomsource.nextInt(3) - 1);
if (worldserver.getBlockState(blockposition1).is(Blocks.DIRT) && canPropagate(iblockdata1, worldserver, blockposition1)) {
- worldserver.setBlockAndUpdate(blockposition1, (IBlockData) iblockdata1.setValue(BlockDirtSnowSpreadable.SNOWY, isSnowySetting(worldserver.getBlockState(blockposition1.above()))));
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition1, (IBlockData) iblockdata1.setValue(BlockDirtSnowSpreadable.SNOWY, isSnowySetting(worldserver.getBlockState(blockposition1.above())))); // CraftBukkit
}
}
}

View File

@@ -0,0 +1,27 @@
--- a/net/minecraft/world/level/block/BlockDispenser.java
+++ b/net/minecraft/world/level/block/BlockDispenser.java
@@ -52,6 +52,7 @@
private static final DispenseBehaviorItem DEFAULT_BEHAVIOR = new DispenseBehaviorItem();
public static final Map<Item, IDispenseBehavior> DISPENSER_REGISTRY = new IdentityHashMap();
private static final int TRIGGER_DURATION = 4;
+ public static boolean eventFired = false; // CraftBukkit
@Override
public MapCodec<? extends BlockDispenser> codec() {
@@ -88,7 +89,7 @@
}
public void dispenseFrom(WorldServer worldserver, IBlockData iblockdata, BlockPosition blockposition) {
- TileEntityDispenser tileentitydispenser = (TileEntityDispenser) worldserver.getBlockEntity(blockposition, TileEntityTypes.DISPENSER).orElse((Object) null);
+ TileEntityDispenser tileentitydispenser = (TileEntityDispenser) worldserver.getBlockEntity(blockposition, TileEntityTypes.DISPENSER).orElse(null); // CraftBukkit - decompile error
if (tileentitydispenser == null) {
BlockDispenser.LOGGER.warn("Ignoring dispensing attempt for Dispenser without matching block entity at {}", blockposition);
@@ -104,6 +105,7 @@
IDispenseBehavior idispensebehavior = this.getDispenseMethod(worldserver, itemstack);
if (idispensebehavior != IDispenseBehavior.NOOP) {
+ eventFired = false; // CraftBukkit - reset event status
tileentitydispenser.setItem(i, idispensebehavior.dispense(sourceblock, itemstack));
}

View File

@@ -0,0 +1,38 @@
--- a/net/minecraft/world/level/block/BlockDoor.java
+++ b/net/minecraft/world/level/block/BlockDoor.java
@@ -39,6 +39,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
+
public class BlockDoor extends Block {
public static final MapCodec<BlockDoor> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -222,9 +224,24 @@
@Override
protected void neighborChanged(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, @Nullable Orientation orientation, boolean flag) {
- boolean flag1 = world.hasNeighborSignal(blockposition) || world.hasNeighborSignal(blockposition.relative(iblockdata.getValue(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER ? EnumDirection.UP : EnumDirection.DOWN));
+ // CraftBukkit start
+ BlockPosition otherHalf = blockposition.relative(iblockdata.getValue(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER ? EnumDirection.UP : EnumDirection.DOWN);
- if (!this.defaultBlockState().is(block) && flag1 != (Boolean) iblockdata.getValue(BlockDoor.POWERED)) {
+ org.bukkit.World bworld = world.getWorld();
+ org.bukkit.block.Block bukkitBlock = bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ org.bukkit.block.Block blockTop = bworld.getBlockAt(otherHalf.getX(), otherHalf.getY(), otherHalf.getZ());
+
+ int power = bukkitBlock.getBlockPower();
+ int powerTop = blockTop.getBlockPower();
+ if (powerTop > power) power = powerTop;
+ int oldPower = (Boolean) iblockdata.getValue(BlockDoor.POWERED) ? 15 : 0;
+
+ if (oldPower == 0 ^ power == 0) {
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, oldPower, power);
+ world.getCraftServer().getPluginManager().callEvent(eventRedstone);
+
+ boolean flag1 = eventRedstone.getNewCurrent() > 0;
+ // CraftBukkit end
if (flag1 != (Boolean) iblockdata.getValue(BlockDoor.OPEN)) {
this.playSound((Entity) null, world, blockposition, flag1);
world.gameEvent((Entity) null, (Holder) (flag1 ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE), blockposition);

View File

@@ -0,0 +1,30 @@
--- a/net/minecraft/world/level/block/BlockDragonEgg.java
+++ b/net/minecraft/world/level/block/BlockDragonEgg.java
@@ -16,6 +16,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.event.block.BlockFromToEvent; // CraftBukkit
+
public class BlockDragonEgg extends BlockFalling {
public static final MapCodec<BlockDragonEgg> CODEC = simpleCodec(BlockDragonEgg::new);
@@ -53,6 +55,18 @@
BlockPosition blockposition1 = blockposition.offset(world.random.nextInt(16) - world.random.nextInt(16), world.random.nextInt(8) - world.random.nextInt(8), world.random.nextInt(16) - world.random.nextInt(16));
if (world.getBlockState(blockposition1).isAir() && worldborder.isWithinBounds(blockposition1)) {
+ // CraftBukkit start
+ org.bukkit.block.Block from = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ org.bukkit.block.Block to = world.getWorld().getBlockAt(blockposition1.getX(), blockposition1.getY(), blockposition1.getZ());
+ BlockFromToEvent event = new BlockFromToEvent(from, to);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+
+ blockposition1 = new BlockPosition(event.getToBlock().getX(), event.getToBlock().getY(), event.getToBlock().getZ());
+ // CraftBukkit end
if (world.isClientSide) {
for (int j = 0; j < 128; ++j) {
double d0 = world.random.nextDouble();

View File

@@ -0,0 +1,58 @@
--- a/net/minecraft/world/level/block/BlockDropper.java
+++ b/net/minecraft/world/level/block/BlockDropper.java
@@ -20,11 +20,17 @@
import net.minecraft.world.level.block.state.IBlockData;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.InventoryLargeChest;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
+// CraftBukkit end
+
public class BlockDropper extends BlockDispenser {
private static final Logger LOGGER = LogUtils.getLogger();
public static final MapCodec<BlockDropper> CODEC = simpleCodec(BlockDropper::new);
- private static final IDispenseBehavior DISPENSE_BEHAVIOUR = new DispenseBehaviorItem();
+ private static final IDispenseBehavior DISPENSE_BEHAVIOUR = new DispenseBehaviorItem(true); // CraftBukkit
@Override
public MapCodec<BlockDropper> codec() {
@@ -47,7 +53,7 @@
@Override
public void dispenseFrom(WorldServer worldserver, IBlockData iblockdata, BlockPosition blockposition) {
- TileEntityDispenser tileentitydispenser = (TileEntityDispenser) worldserver.getBlockEntity(blockposition, TileEntityTypes.DROPPER).orElse((Object) null);
+ TileEntityDispenser tileentitydispenser = (TileEntityDispenser) worldserver.getBlockEntity(blockposition, TileEntityTypes.DROPPER).orElse(null); // CraftBukkit - decompile error
if (tileentitydispenser == null) {
BlockDropper.LOGGER.warn("Ignoring dispensing attempt for Dropper without matching block entity at {}", blockposition);
@@ -68,8 +74,25 @@
if (iinventory == null) {
itemstack1 = BlockDropper.DISPENSE_BEHAVIOUR.dispense(sourceblock, itemstack);
} else {
- itemstack1 = TileEntityHopper.addItem(tileentitydispenser, iinventory, itemstack.copyWithCount(1), enumdirection.getOpposite());
- if (itemstack1.isEmpty()) {
+ // CraftBukkit start - Fire event when pushing items into other inventories
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack.copyWithCount(1));
+
+ org.bukkit.inventory.Inventory destinationInventory;
+ // Have to special case large chests as they work oddly
+ if (iinventory instanceof InventoryLargeChest) {
+ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
+ } else {
+ destinationInventory = iinventory.getOwner().getInventory();
+ }
+
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(tileentitydispenser.getOwner().getInventory(), oitemstack, destinationInventory, true);
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ itemstack1 = TileEntityHopper.addItem(tileentitydispenser, iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection.getOpposite());
+ if (event.getItem().equals(oitemstack) && itemstack1.isEmpty()) {
+ // CraftBukkit end
itemstack1 = itemstack.copy();
itemstack1.shrink(1);
} else {

View File

@@ -0,0 +1,22 @@
--- a/net/minecraft/world/level/block/BlockEndGateway.java
+++ b/net/minecraft/world/level/block/BlockEndGateway.java
@@ -23,6 +23,10 @@
import net.minecraft.world.level.portal.TeleportTransition;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import org.bukkit.event.player.PlayerTeleportEvent;
+// CraftBukkit end
+
public class BlockEndGateway extends BlockTileEntity implements Portal {
public static final MapCodec<BlockEndGateway> CODEC = simpleCodec(BlockEndGateway::new);
@@ -112,7 +116,7 @@
if (tileentity instanceof TileEntityEndGateway tileentityendgateway) {
Vec3D vec3d = tileentityendgateway.getPortalPosition(worldserver, blockposition);
- return vec3d == null ? null : (entity instanceof EntityEnderPearl ? new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Set.of(), TeleportTransition.PLACE_PORTAL_TICKET) : new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), TeleportTransition.PLACE_PORTAL_TICKET));
+ return vec3d == null ? null : (entity instanceof EntityEnderPearl ? new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Set.of(), TeleportTransition.PLACE_PORTAL_TICKET, PlayerTeleportEvent.TeleportCause.END_GATEWAY) : new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), TeleportTransition.PLACE_PORTAL_TICKET, PlayerTeleportEvent.TeleportCause.END_GATEWAY)); // CraftBukkit
} else {
return null;
}

View File

@@ -0,0 +1,80 @@
--- a/net/minecraft/world/level/block/BlockEnderPortal.java
+++ b/net/minecraft/world/level/block/BlockEnderPortal.java
@@ -26,6 +26,19 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import java.util.List;
+import net.minecraft.server.level.EntityPlayer;
+import net.minecraft.world.level.dimension.WorldDimension;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.event.CraftPortalEvent;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.event.entity.EntityPortalEnterEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+// CraftBukkit end
+
public class BlockEnderPortal extends BlockTileEntity implements Portal {
public static final MapCodec<BlockEnderPortal> CODEC = simpleCodec(BlockEnderPortal::new);
@@ -58,6 +71,10 @@
@Override
protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
if (entity.canUsePortal(false)) {
+ // CraftBukkit start - Entity in portal
+ EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ world.getCraftServer().getPluginManager().callEvent(event);
+ // CraftBukkit end
if (!world.isClientSide && world.dimension() == World.END && entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
@@ -74,11 +91,11 @@
@Override
public TeleportTransition getPortalDestination(WorldServer worldserver, Entity entity, BlockPosition blockposition) {
- ResourceKey<World> resourcekey = worldserver.dimension() == World.END ? World.OVERWORLD : World.END;
+ ResourceKey<World> resourcekey = worldserver.getTypeKey() == WorldDimension.END ? World.OVERWORLD : World.END; // CraftBukkit - SPIGOT-6152: send back to main overworld in custom ends
WorldServer worldserver1 = worldserver.getServer().getLevel(resourcekey);
if (worldserver1 == null) {
- return null;
+ return new TeleportTransition(PlayerTeleportEvent.TeleportCause.END_PORTAL); // CraftBukkit- always fire event in case plugins wish to change it
} else {
boolean flag = resourcekey == World.END;
BlockPosition blockposition1 = flag ? WorldServer.END_SPAWN_POINT : worldserver1.getSharedSpawnPos();
@@ -87,7 +104,7 @@
Set set;
if (flag) {
- EndPlatformFeature.createEndPlatform(worldserver1, BlockPosition.containing(vec3d).below(), true);
+ EndPlatformFeature.createEndPlatform(worldserver1, BlockPosition.containing(vec3d).below(), true, entity); // CraftBukkit
f = EnumDirection.WEST.toYRot();
set = Relative.union(Relative.DELTA, Set.of(Relative.X_ROT));
if (entity instanceof EntityPlayer) {
@@ -99,13 +116,21 @@
if (entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
- return entityplayer.findRespawnPositionAndUseSpawnBlock(false, TeleportTransition.DO_NOTHING);
+ return entityplayer.findRespawnPositionAndUseSpawnBlock(false, TeleportTransition.DO_NOTHING, PlayerRespawnEvent.RespawnReason.END_PORTAL); // CraftBukkit
}
vec3d = entity.adjustSpawnLocation(worldserver1, blockposition1).getBottomCenter();
}
- return new TeleportTransition(worldserver1, vec3d, Vec3D.ZERO, f, 0.0F, set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET));
+ // CraftBukkit start
+ CraftPortalEvent event = entity.callPortalEvent(entity, CraftLocation.toBukkit(vec3d, worldserver1.getWorld(), f, entity.getXRot()), PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0);
+ if (event == null) {
+ return null;
+ }
+ Location to = event.getTo();
+
+ return new TeleportTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), entity.getDeltaMovement(), to.getYaw(), to.getPitch(), set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET), PlayerTeleportEvent.TeleportCause.END_PORTAL);
+ // CraftBukkit end
}
}

View File

@@ -0,0 +1,20 @@
--- a/net/minecraft/world/level/block/BlockFenceGate.java
+++ b/net/minecraft/world/level/block/BlockFenceGate.java
@@ -173,6 +173,17 @@
protected void neighborChanged(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, @Nullable Orientation orientation, boolean flag) {
if (!world.isClientSide) {
boolean flag1 = world.hasNeighborSignal(blockposition);
+ // CraftBukkit start
+ boolean oldPowered = iblockdata.getValue(BlockFenceGate.POWERED);
+ if (oldPowered != flag1) {
+ int newPower = flag1 ? 15 : 0;
+ int oldPower = oldPowered ? 15 : 0;
+ org.bukkit.block.Block bukkitBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition);
+ org.bukkit.event.block.BlockRedstoneEvent eventRedstone = new org.bukkit.event.block.BlockRedstoneEvent(bukkitBlock, oldPower, newPower);
+ world.getCraftServer().getPluginManager().callEvent(eventRedstone);
+ flag1 = eventRedstone.getNewCurrent() > 0;
+ }
+ // CraftBukkit end
if ((Boolean) iblockdata.getValue(BlockFenceGate.POWERED) != flag1) {
world.setBlock(blockposition, (IBlockData) ((IBlockData) iblockdata.setValue(BlockFenceGate.POWERED, flag1)).setValue(BlockFenceGate.OPEN, flag1), 2);

View File

@@ -0,0 +1,160 @@
--- a/net/minecraft/world/level/block/BlockFire.java
+++ b/net/minecraft/world/level/block/BlockFire.java
@@ -29,6 +29,15 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;
+// CraftBukkit start
+import net.minecraft.world.item.context.ItemActionContext;
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.block.CraftBlockStates;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.BlockBurnEvent;
+import org.bukkit.event.block.BlockFadeEvent;
+// CraftBukkit end
+
public class BlockFire extends BlockFireAbstract {
public static final MapCodec<BlockFire> CODEC = simpleCodec(BlockFire::new);
@@ -100,7 +109,24 @@
@Override
protected IBlockData updateShape(IBlockData iblockdata, IWorldReader iworldreader, ScheduledTickAccess scheduledtickaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition blockposition1, IBlockData iblockdata1, RandomSource randomsource) {
- return this.canSurvive(iblockdata, iworldreader, blockposition) ? this.getStateWithAge(iworldreader, blockposition, (Integer) iblockdata.getValue(BlockFire.AGE)) : Blocks.AIR.defaultBlockState();
+ // CraftBukkit start
+ if (!this.canSurvive(iblockdata, iworldreader, blockposition)) {
+ // Suppress during worldgen
+ if (!(iworldreader instanceof World world)) {
+ return Blocks.AIR.defaultBlockState();
+ }
+ CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockposition);
+ blockState.setData(Blocks.AIR.defaultBlockState());
+
+ BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ return blockState.getHandle();
+ }
+ }
+ return this.getStateWithAge(iworldreader, blockposition, (Integer) iblockdata.getValue(BlockFire.AGE));
+ // CraftBukkit end
}
@Override
@@ -149,7 +175,7 @@
worldserver.scheduleTick(blockposition, (Block) this, getFireTickDelay(worldserver.random));
if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOFIRETICK)) {
if (!iblockdata.canSurvive(worldserver, blockposition)) {
- worldserver.removeBlock(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit - invalid place location
}
IBlockData iblockdata1 = worldserver.getBlockState(blockposition.below());
@@ -157,7 +183,7 @@
int i = (Integer) iblockdata.getValue(BlockFire.AGE);
if (!flag && worldserver.isRaining() && this.isNearRain(worldserver, blockposition) && randomsource.nextFloat() < 0.2F + (float) i * 0.03F) {
- worldserver.removeBlock(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit - extinguished by rain
} else {
int j = Math.min(15, i + randomsource.nextInt(3) / 2);
@@ -171,14 +197,14 @@
BlockPosition blockposition1 = blockposition.below();
if (!worldserver.getBlockState(blockposition1).isFaceSturdy(worldserver, blockposition1, EnumDirection.UP) || i > 3) {
- worldserver.removeBlock(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit
}
return;
}
if (i == 15 && randomsource.nextInt(4) == 0 && !this.canBurn(worldserver.getBlockState(blockposition.below()))) {
- worldserver.removeBlock(blockposition, false);
+ fireExtinguished(worldserver, blockposition); // CraftBukkit
return;
}
}
@@ -186,12 +212,14 @@
boolean flag1 = worldserver.getBiome(blockposition).is(BiomeTags.INCREASED_FIRE_BURNOUT);
int k = flag1 ? -50 : 0;
- this.checkBurnOut(worldserver, blockposition.east(), 300 + k, randomsource, i);
- this.checkBurnOut(worldserver, blockposition.west(), 300 + k, randomsource, i);
- this.checkBurnOut(worldserver, blockposition.below(), 250 + k, randomsource, i);
- this.checkBurnOut(worldserver, blockposition.above(), 250 + k, randomsource, i);
- this.checkBurnOut(worldserver, blockposition.north(), 300 + k, randomsource, i);
- this.checkBurnOut(worldserver, blockposition.south(), 300 + k, randomsource, i);
+ // CraftBukkit start - add source blockposition to burn calls
+ this.trySpread(worldserver, blockposition.east(), 300 + k, randomsource, i, blockposition);
+ this.trySpread(worldserver, blockposition.west(), 300 + k, randomsource, i, blockposition);
+ this.trySpread(worldserver, blockposition.below(), 250 + k, randomsource, i, blockposition);
+ this.trySpread(worldserver, blockposition.above(), 250 + k, randomsource, i, blockposition);
+ this.trySpread(worldserver, blockposition.north(), 300 + k, randomsource, i, blockposition);
+ this.trySpread(worldserver, blockposition.south(), 300 + k, randomsource, i, blockposition);
+ // CraftBukkit end
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
for (int l = -1; l <= 1; ++l) {
@@ -217,7 +245,15 @@
if (i2 > 0 && randomsource.nextInt(k1) <= i2 && (!worldserver.isRaining() || !this.isNearRain(worldserver, blockposition_mutableblockposition))) {
int j2 = Math.min(15, i + randomsource.nextInt(5) / 4);
- worldserver.setBlock(blockposition_mutableblockposition, this.getStateWithAge(worldserver, blockposition_mutableblockposition, j2), 3);
+ // CraftBukkit start - Call to stop spread of fire
+ if (worldserver.getBlockState(blockposition_mutableblockposition).getBlock() != Blocks.FIRE) {
+ if (CraftEventFactory.callBlockIgniteEvent(worldserver, blockposition_mutableblockposition, blockposition).isCancelled()) {
+ continue;
+ }
+
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition_mutableblockposition, this.getStateWithAge(worldserver, blockposition_mutableblockposition, j2), 3); // CraftBukkit
+ }
+ // CraftBukkit end
}
}
}
@@ -241,12 +277,28 @@
return iblockdata.hasProperty(BlockProperties.WATERLOGGED) && (Boolean) iblockdata.getValue(BlockProperties.WATERLOGGED) ? 0 : this.igniteOdds.getInt(iblockdata.getBlock());
}
- private void checkBurnOut(World world, BlockPosition blockposition, int i, RandomSource randomsource, int j) {
+ private void trySpread(World world, BlockPosition blockposition, int i, RandomSource randomsource, int j, BlockPosition sourceposition) { // CraftBukkit add sourceposition
int k = this.getBurnOdds(world.getBlockState(blockposition));
if (randomsource.nextInt(i) < k) {
IBlockData iblockdata = world.getBlockState(blockposition);
+ // CraftBukkit start
+ org.bukkit.block.Block theBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ org.bukkit.block.Block sourceBlock = world.getWorld().getBlockAt(sourceposition.getX(), sourceposition.getY(), sourceposition.getZ());
+
+ BlockBurnEvent event = new BlockBurnEvent(theBlock, sourceBlock);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+
+ if (iblockdata.getBlock() instanceof BlockTNT && !CraftEventFactory.callTNTPrimeEvent(world, blockposition, org.bukkit.event.block.TNTPrimeEvent.PrimeCause.FIRE, null, sourceposition)) {
+ return;
+ }
+ // CraftBukkit end
+
if (randomsource.nextInt(j + 10) < 5 && !world.isRainingAt(blockposition)) {
int l = Math.min(j + randomsource.nextInt(5) / 4, 15);
@@ -310,8 +362,10 @@
}
@Override
- protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
- super.onPlace(iblockdata, world, blockposition, iblockdata1, flag);
+ // CraftBukkit start - context
+ protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag, ItemActionContext context) {
+ super.onPlace(iblockdata, world, blockposition, iblockdata1, flag, context);
+ // CraftBukkit end
world.scheduleTick(blockposition, (Block) this, getFireTickDelay(world.random));
}

View File

@@ -0,0 +1,73 @@
--- a/net/minecraft/world/level/block/BlockFireAbstract.java
+++ b/net/minecraft/world/level/block/BlockFireAbstract.java
@@ -20,6 +20,10 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import net.minecraft.world.item.context.ItemActionContext;
+// CraftBukkit end
+
public abstract class BlockFireAbstract extends Block {
private static final int SECONDS_ON_FIRE = 8;
@@ -137,7 +141,14 @@
}
if (entity.getRemainingFireTicks() >= 0) {
- entity.igniteForSeconds(8.0F);
+ // CraftBukkit start
+ org.bukkit.event.entity.EntityCombustEvent event = new org.bukkit.event.entity.EntityCombustByBlockEvent(org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition), entity.getBukkitEntity(), 8.0F);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ entity.igniteForSeconds(event.getDuration(), false);
+ }
+ // CraftBukkit end
}
}
@@ -146,26 +157,26 @@
}
@Override
- protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
+ protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag, ItemActionContext context) { // CraftBukkit - context
if (!iblockdata1.is(iblockdata.getBlock())) {
if (inPortalDimension(world)) {
Optional<BlockPortalShape> optional = BlockPortalShape.findEmptyPortalShape(world, blockposition, EnumDirection.EnumAxis.X);
if (optional.isPresent()) {
- ((BlockPortalShape) optional.get()).createPortalBlocks(world);
+ ((BlockPortalShape) optional.get()).createPortalBlocks(world, (context == null) ? null : context.getPlayer()); // CraftBukkit - player
return;
}
}
if (!iblockdata.canSurvive(world, blockposition)) {
- world.removeBlock(blockposition, false);
+ fireExtinguished(world, blockposition); // CraftBukkit - fuel block broke
}
}
}
private static boolean inPortalDimension(World world) {
- return world.dimension() == World.OVERWORLD || world.dimension() == World.NETHER;
+ return world.getTypeKey() == net.minecraft.world.level.dimension.WorldDimension.OVERWORLD || world.getTypeKey() == net.minecraft.world.level.dimension.WorldDimension.NETHER; // CraftBukkit - getTypeKey()
}
@Override
@@ -213,4 +224,12 @@
}
}
}
+
+ // CraftBukkit start
+ protected void fireExtinguished(net.minecraft.world.level.GeneratorAccess world, BlockPosition position) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(world, position, Blocks.AIR.defaultBlockState()).isCancelled()) {
+ world.removeBlock(position, false);
+ }
+ }
+ // CraftBukkit end
}

View File

@@ -0,0 +1,36 @@
--- a/net/minecraft/world/level/block/BlockFluids.java
+++ b/net/minecraft/world/level/block/BlockFluids.java
@@ -42,7 +42,7 @@
public class BlockFluids extends Block implements IFluidSource {
private static final Codec<FluidTypeFlowing> FLOWING_FLUID = BuiltInRegistries.FLUID.byNameCodec().comapFlatMap((fluidtype) -> {
- DataResult dataresult;
+ DataResult<FluidTypeFlowing> dataresult; // CraftBukkit - decompile error
if (fluidtype instanceof FluidTypeFlowing fluidtypeflowing) {
dataresult = DataResult.success(fluidtypeflowing);
@@ -175,14 +175,20 @@
if (world.getFluidState(blockposition1).is(TagsFluid.WATER)) {
Block block = world.getFluidState(blockposition).isSource() ? Blocks.OBSIDIAN : Blocks.COBBLESTONE;
- world.setBlockAndUpdate(blockposition, block.defaultBlockState());
- this.fizz(world, blockposition);
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(world, blockposition, block.defaultBlockState())) {
+ this.fizz(world, blockposition);
+ }
+ // CraftBukkit end
return false;
}
if (flag && world.getBlockState(blockposition1).is(Blocks.BLUE_ICE)) {
- world.setBlockAndUpdate(blockposition, Blocks.BASALT.defaultBlockState());
- this.fizz(world, blockposition);
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(world, blockposition, Blocks.BASALT.defaultBlockState())) {
+ this.fizz(world, blockposition);
+ }
+ // CraftBukkit end
return false;
}
}

View File

@@ -0,0 +1,16 @@
--- a/net/minecraft/world/level/block/BlockFungi.java
+++ b/net/minecraft/world/level/block/BlockFungi.java
@@ -74,6 +74,13 @@
@Override
public void performBonemeal(WorldServer worldserver, RandomSource randomsource, BlockPosition blockposition, IBlockData iblockdata) {
this.getFeature(worldserver).ifPresent((holder) -> {
+ // CraftBukkit start
+ if (this == Blocks.WARPED_FUNGUS) {
+ BlockSapling.treeType = org.bukkit.TreeType.WARPED_FUNGUS;
+ } else if (this == Blocks.CRIMSON_FUNGUS) {
+ BlockSapling.treeType = org.bukkit.TreeType.CRIMSON_FUNGUS;
+ }
+ // CraftBukkit end
((WorldGenFeatureConfigured) holder.value()).place(worldserver, worldserver.getChunkSource().getGenerator(), randomsource, blockposition);
});
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockGrassPath.java
+++ b/net/minecraft/world/level/block/BlockGrassPath.java
@@ -51,6 +51,11 @@
@Override
protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
+ // CraftBukkit start - do not fade if the block is valid here
+ if (iblockdata.canSurvive(worldserver, blockposition)) {
+ return;
+ }
+ // CraftBukkit end
BlockSoil.turnToDirt((Entity) null, iblockdata, worldserver, blockposition);
}

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/level/block/BlockGrowingTop.java
+++ b/net/minecraft/world/level/block/BlockGrowingTop.java
@@ -48,7 +48,7 @@
BlockPosition blockposition1 = blockposition.relative(this.growthDirection);
if (this.canGrowInto(worldserver.getBlockState(blockposition1))) {
- worldserver.setBlockAndUpdate(blockposition1, this.getGrowIntoState(iblockdata, worldserver.random));
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition1, this.getGrowIntoState(iblockdata, worldserver.random)); // CraftBukkit
}
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockIce.java
+++ b/net/minecraft/world/level/block/BlockIce.java
@@ -60,6 +60,11 @@
}
protected void melt(IBlockData iblockdata, World world, BlockPosition blockposition) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(world, blockposition, world.dimensionType().ultraWarm() ? Blocks.AIR.defaultBlockState() : Blocks.WATER.defaultBlockState()).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
if (world.dimensionType().ultraWarm()) {
world.removeBlock(blockposition, false);
} else {

View File

@@ -0,0 +1,26 @@
--- a/net/minecraft/world/level/block/BlockLeaves.java
+++ b/net/minecraft/world/level/block/BlockLeaves.java
@@ -27,6 +27,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapes;
+import org.bukkit.event.block.LeavesDecayEvent; // CraftBukkit
+
public class BlockLeaves extends Block implements IBlockWaterlogged {
public static final MapCodec<BlockLeaves> CODEC = simpleCodec(BlockLeaves::new);
@@ -59,6 +61,14 @@
@Override
protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if (this.decaying(iblockdata)) {
+ // CraftBukkit start
+ LeavesDecayEvent event = new LeavesDecayEvent(worldserver.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled() || worldserver.getBlockState(blockposition).getBlock() != this) {
+ return;
+ }
+ // CraftBukkit end
dropResources(iblockdata, worldserver, blockposition);
worldserver.removeBlock(blockposition, false);
}

View File

@@ -0,0 +1,16 @@
--- a/net/minecraft/world/level/block/BlockLectern.java
+++ b/net/minecraft/world/level/block/BlockLectern.java
@@ -206,11 +206,12 @@
}
private void popBook(IBlockData iblockdata, World world, BlockPosition blockposition) {
- TileEntity tileentity = world.getBlockEntity(blockposition);
+ TileEntity tileentity = world.getBlockEntity(blockposition, false); // CraftBukkit - don't validate, type may be changed already
if (tileentity instanceof TileEntityLectern tileentitylectern) {
EnumDirection enumdirection = (EnumDirection) iblockdata.getValue(BlockLectern.FACING);
ItemStack itemstack = tileentitylectern.getBook().copy();
+ if (itemstack.isEmpty()) return; // CraftBukkit - SPIGOT-5500
float f = 0.25F * (float) enumdirection.getStepX();
float f1 = 0.25F * (float) enumdirection.getStepZ();
EntityItem entityitem = new EntityItem(world, (double) blockposition.getX() + 0.5D + (double) f, (double) (blockposition.getY() + 1), (double) blockposition.getZ() + 0.5D + (double) f1, itemstack);

View File

@@ -0,0 +1,32 @@
--- a/net/minecraft/world/level/block/BlockLever.java
+++ b/net/minecraft/world/level/block/BlockLever.java
@@ -32,6 +32,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
+
public class BlockLever extends BlockAttachable {
public static final MapCodec<BlockLever> CODEC = simpleCodec(BlockLever::new);
@@ -102,6 +104,20 @@
makeParticle(iblockdata1, world, blockposition, 1.0F);
}
} else {
+ // CraftBukkit start - Interact Lever
+ boolean powered = iblockdata.getValue(BlockLever.POWERED); // Old powered state
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ int old = (powered) ? 15 : 0;
+ int current = (!powered) ? 15 : 0;
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current);
+ world.getCraftServer().getPluginManager().callEvent(eventRedstone);
+
+ if ((eventRedstone.getNewCurrent() > 0) != (!powered)) {
+ return EnumInteractionResult.SUCCESS;
+ }
+ // CraftBukkit end
+
this.pull(iblockdata, world, blockposition, (EntityHuman) null);
}

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/level/block/BlockMagma.java
+++ b/net/minecraft/world/level/block/BlockMagma.java
@@ -30,7 +30,7 @@
@Override
public void stepOn(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity) {
if (!entity.isSteppingCarefully() && entity instanceof EntityLiving) {
- entity.hurt(world.damageSources().hotFloor(), 1.0F);
+ entity.hurt(world.damageSources().hotFloor().directBlock(world, blockposition), 1.0F); // CraftBukkit
}
super.stepOn(world, blockposition, iblockdata, entity);

View File

@@ -0,0 +1,28 @@
--- a/net/minecraft/world/level/block/BlockMinecartDetector.java
+++ b/net/minecraft/world/level/block/BlockMinecartDetector.java
@@ -27,6 +27,8 @@
import net.minecraft.world.level.redstone.Orientation;
import net.minecraft.world.phys.AxisAlignedBB;
+import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
+
public class BlockMinecartDetector extends BlockMinecartTrackAbstract {
public static final MapCodec<BlockMinecartDetector> CODEC = simpleCodec(BlockMinecartDetector::new);
@@ -88,6 +90,16 @@
}
IBlockData iblockdata1;
+ // CraftBukkit start
+ if (flag != flag1) {
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, flag ? 15 : 0, flag1 ? 15 : 0);
+ world.getCraftServer().getPluginManager().callEvent(eventRedstone);
+
+ flag1 = eventRedstone.getNewCurrent() > 0;
+ }
+ // CraftBukkit end
if (flag1 && !flag) {
iblockdata1 = (IBlockData) iblockdata.setValue(BlockMinecartDetector.POWERED, true);

View File

@@ -0,0 +1,24 @@
--- a/net/minecraft/world/level/block/BlockMobSpawner.java
+++ b/net/minecraft/world/level/block/BlockMobSpawner.java
@@ -45,12 +45,20 @@
@Override
protected void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) {
super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag);
+ // CraftBukkit start - Delegate to getExpDrop
+ }
+
+ @Override
+ public int getExpDrop(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) {
if (flag) {
int i = 15 + worldserver.random.nextInt(15) + worldserver.random.nextInt(15);
- this.popExperience(worldserver, blockposition, i);
+ // this.popExperience(worldserver, blockposition, i);
+ return i;
}
+ return 0;
+ // CraftBukkit end
}
@Override

View File

@@ -0,0 +1,20 @@
--- a/net/minecraft/world/level/block/BlockMonsterEggs.java
+++ b/net/minecraft/world/level/block/BlockMonsterEggs.java
@@ -20,6 +20,8 @@
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.block.state.properties.IBlockState;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; // CraftBukkit
+
public class BlockMonsterEggs extends Block {
public static final MapCodec<BlockMonsterEggs> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -54,7 +56,7 @@
if (entitysilverfish != null) {
entitysilverfish.moveTo((double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, 0.0F, 0.0F);
- worldserver.addFreshEntity(entitysilverfish);
+ worldserver.addFreshEntity(entitysilverfish, SpawnReason.SILVERFISH_BLOCK); // CraftBukkit - add SpawnReason
entitysilverfish.spawnAnim();
}

View File

@@ -0,0 +1,30 @@
--- a/net/minecraft/world/level/block/BlockMushroom.java
+++ b/net/minecraft/world/level/block/BlockMushroom.java
@@ -20,6 +20,10 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import org.bukkit.TreeType;
+// CraftBukkit end
+
public class BlockMushroom extends BlockPlant implements IBlockFragilePlantElement {
public static final MapCodec<BlockMushroom> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -75,7 +79,7 @@
}
if (worldserver.isEmptyBlock(blockposition2) && iblockdata.canSurvive(worldserver, blockposition2)) {
- worldserver.setBlock(blockposition2, iblockdata, 2);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition2, iblockdata, 2); // CraftBukkit
}
}
@@ -101,6 +105,7 @@
return false;
} else {
worldserver.removeBlock(blockposition, false);
+ BlockSapling.treeType = (this == Blocks.BROWN_MUSHROOM) ? TreeType.BROWN_MUSHROOM : TreeType.RED_MUSHROOM; // CraftBukkit
if (((WorldGenFeatureConfigured) ((Holder) optional.get()).value()).place(worldserver, worldserver.getChunkSource().getGenerator(), randomsource, blockposition)) {
return true;
} else {

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/level/block/BlockNetherWart.java
+++ b/net/minecraft/world/level/block/BlockNetherWart.java
@@ -54,7 +54,7 @@
if (i < 3 && randomsource.nextInt(10) == 0) {
iblockdata = (IBlockData) iblockdata.setValue(BlockNetherWart.AGE, i + 1);
- worldserver.setBlock(blockposition, iblockdata, 2);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, iblockdata, 2); // CraftBukkit
}
}

View File

@@ -0,0 +1,23 @@
--- a/net/minecraft/world/level/block/BlockNote.java
+++ b/net/minecraft/world/level/block/BlockNote.java
@@ -85,6 +85,7 @@
if (flag1 != (Boolean) iblockdata.getValue(BlockNote.POWERED)) {
if (flag1) {
this.playNote((Entity) null, iblockdata, world, blockposition);
+ iblockdata = world.getBlockState(blockposition); // CraftBukkit - SPIGOT-5617: update in case changed in event
}
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockNote.POWERED, flag1), 3);
@@ -94,6 +95,12 @@
private void playNote(@Nullable Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) {
if (((BlockPropertyInstrument) iblockdata.getValue(BlockNote.INSTRUMENT)).worksAboveNoteBlock() || world.getBlockState(blockposition.above()).isAir()) {
+ // CraftBukkit start
+ org.bukkit.event.block.NotePlayEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callNotePlayEvent(world, blockposition, iblockdata.getValue(BlockNote.INSTRUMENT), iblockdata.getValue(BlockNote.NOTE));
+ if (event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
world.blockEvent(blockposition, this, 0, 0);
world.gameEvent(entity, (Holder) GameEvent.NOTE_BLOCK_PLAY, blockposition);
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockNylium.java
+++ b/net/minecraft/world/level/block/BlockNylium.java
@@ -41,6 +41,11 @@
@Override
protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if (!canBeNylium(iblockdata, worldserver, blockposition)) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, Blocks.NETHERRACK.defaultBlockState()).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlockAndUpdate(blockposition, Blocks.NETHERRACK.defaultBlockState());
}

View File

@@ -0,0 +1,30 @@
--- a/net/minecraft/world/level/block/BlockObserver.java
+++ b/net/minecraft/world/level/block/BlockObserver.java
@@ -18,6 +18,8 @@
import net.minecraft.world.level.redstone.ExperimentalRedstoneUtils;
import net.minecraft.world.level.redstone.Orientation;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class BlockObserver extends BlockDirectional {
public static final MapCodec<BlockObserver> CODEC = simpleCodec(BlockObserver::new);
@@ -51,8 +53,18 @@
@Override
protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if ((Boolean) iblockdata.getValue(BlockObserver.POWERED)) {
+ // CraftBukkit start
+ if (CraftEventFactory.callRedstoneChange(worldserver, blockposition, 15, 0).getNewCurrent() != 0) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockObserver.POWERED, false), 2);
} else {
+ // CraftBukkit start
+ if (CraftEventFactory.callRedstoneChange(worldserver, blockposition, 0, 15).getNewCurrent() != 15) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockObserver.POWERED, true), 2);
worldserver.scheduleTick(blockposition, (Block) this, 2);
}

View File

@@ -0,0 +1,30 @@
--- a/net/minecraft/world/level/block/BlockPlant.java
+++ b/net/minecraft/world/level/block/BlockPlant.java
@@ -12,6 +12,10 @@
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.pathfinder.PathMode;
+// CraftBukkit start
+import net.minecraft.world.level.World;
+// CraftBukkit end
+
public abstract class BlockPlant extends Block {
protected BlockPlant(BlockBase.Info blockbase_info) {
@@ -27,7 +31,15 @@
@Override
protected IBlockData updateShape(IBlockData iblockdata, IWorldReader iworldreader, ScheduledTickAccess scheduledtickaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition blockposition1, IBlockData iblockdata1, RandomSource randomsource) {
- return !iblockdata.canSurvive(iworldreader, blockposition) ? Blocks.AIR.defaultBlockState() : super.updateShape(iblockdata, iworldreader, scheduledtickaccess, blockposition, enumdirection, blockposition1, iblockdata1, randomsource);
+ // CraftBukkit start
+ if (!iblockdata.canSurvive(iworldreader, blockposition)) {
+ // Suppress during worldgen
+ if (!(iworldreader instanceof World world) || !org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world, blockposition).isCancelled()) {
+ return Blocks.AIR.defaultBlockState();
+ }
+ }
+ return super.updateShape(iblockdata, iworldreader, scheduledtickaccess, blockposition, enumdirection, blockposition1, iblockdata1, randomsource);
+ // CraftBukkit end
}
@Override

View File

@@ -0,0 +1,115 @@
--- a/net/minecraft/world/level/block/BlockPortal.java
+++ b/net/minecraft/world/level/block/BlockPortal.java
@@ -39,6 +39,15 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.level.dimension.WorldDimension;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.event.CraftPortalEvent;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.event.entity.EntityPortalEnterEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+// CraftBukkit end
+
public class BlockPortal extends Block implements Portal {
public static final MapCodec<BlockPortal> CODEC = simpleCodec(BlockPortal::new);
@@ -77,7 +86,8 @@
}
if (worldserver.getBlockState(blockposition).isValidSpawn(worldserver, blockposition, EntityTypes.ZOMBIFIED_PIGLIN)) {
- Entity entity = EntityTypes.ZOMBIFIED_PIGLIN.spawn(worldserver, blockposition.above(), EntitySpawnReason.STRUCTURE);
+ // CraftBukkit - set spawn reason to NETHER_PORTAL
+ Entity entity = EntityTypes.ZOMBIFIED_PIGLIN.spawn(worldserver, blockposition.above(), EntitySpawnReason.STRUCTURE, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NETHER_PORTAL);
if (entity != null) {
entity.setPortalCooldown();
@@ -104,6 +114,10 @@
@Override
protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
if (entity.canUsePortal(false)) {
+ // CraftBukkit start - Entity in portal
+ EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ world.getCraftServer().getPluginManager().callEvent(event);
+ // CraftBukkit end
entity.setAsInsidePortal(this, blockposition);
}
@@ -121,24 +135,34 @@
@Nullable
@Override
public TeleportTransition getPortalDestination(WorldServer worldserver, Entity entity, BlockPosition blockposition) {
- ResourceKey<World> resourcekey = worldserver.dimension() == World.NETHER ? World.OVERWORLD : World.NETHER;
+ // CraftBukkit start
+ ResourceKey<World> resourcekey = worldserver.getTypeKey() == WorldDimension.NETHER ? World.OVERWORLD : World.NETHER;
WorldServer worldserver1 = worldserver.getServer().getLevel(resourcekey);
if (worldserver1 == null) {
- return null;
+ return new TeleportTransition(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); // always fire event in case plugins wish to change it
} else {
- boolean flag = worldserver1.dimension() == World.NETHER;
+ boolean flag = worldserver1.getTypeKey() == WorldDimension.NETHER;
+ // CraftBukkit end
WorldBorder worldborder = worldserver1.getWorldBorder();
double d0 = DimensionManager.getTeleportationScale(worldserver.dimensionType(), worldserver1.dimensionType());
BlockPosition blockposition1 = worldborder.clampToBounds(entity.getX() * d0, entity.getY(), entity.getZ() * d0);
+ // CraftBukkit start
+ CraftPortalEvent event = entity.callPortalEvent(entity, CraftLocation.toBukkit(blockposition1, worldserver1.getWorld()), PlayerTeleportEvent.TeleportCause.NETHER_PORTAL, flag ? 16 : 128, 16);
+ if (event == null) {
+ return null;
+ }
+ worldserver1 = ((CraftWorld) event.getTo().getWorld()).getHandle();
+ worldborder = worldserver1.getWorldBorder();
+ blockposition1 = worldborder.clampToBounds(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
- return this.getExitPortal(worldserver1, entity, blockposition, blockposition1, flag, worldborder);
+ return this.getExitPortal(worldserver1, entity, blockposition, blockposition1, flag, worldborder, event.getSearchRadius(), event.getCanCreatePortal(), event.getCreationRadius());
}
}
@Nullable
- private TeleportTransition getExitPortal(WorldServer worldserver, Entity entity, BlockPosition blockposition, BlockPosition blockposition1, boolean flag, WorldBorder worldborder) {
- Optional<BlockPosition> optional = worldserver.getPortalForcer().findClosestPortalPosition(blockposition1, flag, worldborder);
+ private TeleportTransition getExitPortal(WorldServer worldserver, Entity entity, BlockPosition blockposition, BlockPosition blockposition1, boolean flag, WorldBorder worldborder, int searchRadius, boolean canCreatePortal, int createRadius) {
+ Optional<BlockPosition> optional = worldserver.getPortalForcer().findClosestPortalPosition(blockposition1, worldborder, searchRadius);
BlockUtil.Rectangle blockutil_rectangle;
TeleportTransition.a teleporttransition_a;
@@ -152,17 +176,22 @@
teleporttransition_a = TeleportTransition.PLAY_PORTAL_SOUND.then((entity1) -> {
entity1.placePortalTicket(blockposition2);
});
- } else {
+ } else if (canCreatePortal) {
EnumDirection.EnumAxis enumdirection_enumaxis = (EnumDirection.EnumAxis) entity.level().getBlockState(blockposition).getOptionalValue(BlockPortal.AXIS).orElse(EnumDirection.EnumAxis.X);
- Optional<BlockUtil.Rectangle> optional1 = worldserver.getPortalForcer().createPortal(blockposition1, enumdirection_enumaxis);
+ Optional<BlockUtil.Rectangle> optional1 = worldserver.getPortalForcer().createPortal(blockposition1, enumdirection_enumaxis, entity, createRadius);
+ // CraftBukkit end
if (optional1.isEmpty()) {
- BlockPortal.LOGGER.error("Unable to create a portal, likely target out of worldborder");
+ // BlockPortal.LOGGER.error("Unable to create a portal, likely target out of worldborder"); // CraftBukkit
return null;
}
blockutil_rectangle = (BlockUtil.Rectangle) optional1.get();
teleporttransition_a = TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET);
+ // CraftBukkit start
+ } else {
+ return null;
+ // CraftBukkit end
}
return getDimensionTransitionFromExit(entity, blockposition, blockutil_rectangle, worldserver, teleporttransition_a);
@@ -203,7 +232,7 @@
Vec3D vec3d1 = new Vec3D((double) blockposition.getX() + (flag ? d2 : d4), (double) blockposition.getY() + d3, (double) blockposition.getZ() + (flag ? d4 : d2));
Vec3D vec3d2 = BlockPortalShape.findCollisionFreePosition(vec3d1, worldserver, entity, entitysize);
- return new TeleportTransition(worldserver, vec3d2, Vec3D.ZERO, (float) i, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), teleporttransition_a);
+ return new TeleportTransition(worldserver, vec3d2, Vec3D.ZERO, (float) i, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), teleporttransition_a, PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); // CraftBukkit
}
@Override

View File

@@ -0,0 +1,25 @@
--- a/net/minecraft/world/level/block/BlockPoweredRail.java
+++ b/net/minecraft/world/level/block/BlockPoweredRail.java
@@ -12,6 +12,8 @@
import net.minecraft.world.level.block.state.properties.BlockStateEnum;
import net.minecraft.world.level.block.state.properties.IBlockState;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class BlockPoweredRail extends BlockMinecartTrackAbstract {
public static final MapCodec<BlockPoweredRail> CODEC = simpleCodec(BlockPoweredRail::new);
@@ -120,6 +122,13 @@
boolean flag1 = world.hasNeighborSignal(blockposition) || this.findPoweredRailSignal(world, blockposition, iblockdata, true, 0) || this.findPoweredRailSignal(world, blockposition, iblockdata, false, 0);
if (flag1 != flag) {
+ // CraftBukkit start
+ int power = flag ? 15 : 0;
+ int newPower = CraftEventFactory.callRedstoneChange(world, blockposition, power, 15 - power).getNewCurrent();
+ if (newPower == power) {
+ return;
+ }
+ // CraftBukkit end
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockPoweredRail.POWERED, flag1), 3);
world.updateNeighborsAt(blockposition.below(), this);
if (((BlockPropertyTrackPosition) iblockdata.getValue(BlockPoweredRail.SHAPE)).isSlope()) {

View File

@@ -0,0 +1,48 @@
--- a/net/minecraft/world/level/block/BlockPressurePlateAbstract.java
+++ b/net/minecraft/world/level/block/BlockPressurePlateAbstract.java
@@ -23,6 +23,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
+
public abstract class BlockPressurePlateAbstract extends Block {
protected static final VoxelShape PRESSED_AABB = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 0.5D, 15.0D);
@@ -91,6 +93,19 @@
boolean flag = i > 0;
boolean flag1 = j > 0;
+ // CraftBukkit start - Interact Pressure Plate
+ org.bukkit.World bworld = world.getWorld();
+ org.bukkit.plugin.PluginManager manager = world.getCraftServer().getPluginManager();
+
+ if (flag != flag1) {
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), i, j);
+ manager.callEvent(eventRedstone);
+
+ flag1 = eventRedstone.getNewCurrent() > 0;
+ j = eventRedstone.getNewCurrent();
+ }
+ // CraftBukkit end
+
if (i != j) {
IBlockData iblockdata1 = this.setSignalForState(iblockdata, j);
@@ -145,9 +160,15 @@
}
protected static int getEntityCount(World world, AxisAlignedBB axisalignedbb, Class<? extends Entity> oclass) {
+ // CraftBukkit start
+ return getEntities(world, axisalignedbb, oclass).size();
+ }
+
+ protected static <T extends Entity> java.util.List<T> getEntities(World world, AxisAlignedBB axisalignedbb, Class<T> oclass) {
+ // CraftBukkit end
return world.getEntitiesOfClass(oclass, axisalignedbb, IEntitySelector.NO_SPECTATORS.and((entity) -> {
return !entity.isIgnoringBlockTriggers();
- })).size();
+ })); // CraftBukkit
}
protected abstract int getSignalStrength(World world, BlockPosition blockposition);

View File

@@ -0,0 +1,56 @@
--- a/net/minecraft/world/level/block/BlockPressurePlateBinary.java
+++ b/net/minecraft/world/level/block/BlockPressurePlateBinary.java
@@ -13,6 +13,11 @@
import net.minecraft.world.level.block.state.properties.BlockSetType;
import net.minecraft.world.level.block.state.properties.BlockStateBoolean;
+// CraftBukkit start
+import net.minecraft.world.entity.player.EntityHuman;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
+
public class BlockPressurePlateBinary extends BlockPressurePlateAbstract {
public static final MapCodec<BlockPressurePlateBinary> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -44,7 +49,7 @@
@Override
protected int getSignalStrength(World world, BlockPosition blockposition) {
- Class oclass;
+ Class<? extends Entity> oclass; // CraftBukkit
switch (this.type.pressurePlateSensitivity()) {
case EVERYTHING:
@@ -59,7 +64,31 @@
Class<? extends Entity> oclass1 = oclass;
- return getEntityCount(world, BlockPressurePlateBinary.TOUCH_AABB.move(blockposition), oclass1) > 0 ? 15 : 0;
+ // CraftBukkit start - Call interact event when turning on a pressure plate
+ for (Entity entity : getEntities(world, BlockPressurePlateBinary.TOUCH_AABB.move(blockposition), oclass)) {
+ if (this.getSignalForState(world.getBlockState(blockposition)) == 0) {
+ org.bukkit.World bworld = world.getWorld();
+ org.bukkit.plugin.PluginManager manager = world.getCraftServer().getPluginManager();
+ org.bukkit.event.Cancellable cancellable;
+
+ if (entity instanceof EntityHuman) {
+ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ } else {
+ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ manager.callEvent((EntityInteractEvent) cancellable);
+ }
+
+ // We only want to block turning the plate on if all events are cancelled
+ if (cancellable.isCancelled()) {
+ continue;
+ }
+ }
+
+ return 15;
+ }
+
+ return 0;
+ // CraftBukkit end
}
@Override

View File

@@ -0,0 +1,43 @@
--- a/net/minecraft/world/level/block/BlockPressurePlateWeighted.java
+++ b/net/minecraft/world/level/block/BlockPressurePlateWeighted.java
@@ -14,6 +14,11 @@
import net.minecraft.world.level.block.state.properties.BlockSetType;
import net.minecraft.world.level.block.state.properties.BlockStateInteger;
+// CraftBukkit start
+import net.minecraft.world.entity.player.EntityHuman;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
+
public class BlockPressurePlateWeighted extends BlockPressurePlateAbstract {
public static final MapCodec<BlockPressurePlateWeighted> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -39,7 +44,27 @@
@Override
protected int getSignalStrength(World world, BlockPosition blockposition) {
- int i = Math.min(getEntityCount(world, BlockPressurePlateWeighted.TOUCH_AABB.move(blockposition), Entity.class), this.maxWeight);
+ // CraftBukkit start
+ // int i = Math.min(getEntityCount(world, BlockPressurePlateWeighted.TOUCH_AABB.move(blockposition), Entity.class), this.maxWeight);
+ int i = 0;
+ for (Entity entity : getEntities(world, BlockPressurePlateWeighted.TOUCH_AABB.move(blockposition), Entity.class)) {
+ org.bukkit.event.Cancellable cancellable;
+
+ if (entity instanceof EntityHuman) {
+ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ } else {
+ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ world.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
+ }
+
+ // We only want to block turning the plate on if all events are cancelled
+ if (!cancellable.isCancelled()) {
+ i++;
+ }
+ }
+
+ i = Math.min(i, this.maxWeight);
+ // CraftBukkit end
if (i > 0) {
float f = (float) Math.min(this.maxWeight, i) / (float) this.maxWeight;

View File

@@ -0,0 +1,30 @@
--- a/net/minecraft/world/level/block/BlockPumpkinCarved.java
+++ b/net/minecraft/world/level/block/BlockPumpkinCarved.java
@@ -25,6 +25,10 @@
import net.minecraft.world.level.block.state.predicate.BlockStatePredicate;
import net.minecraft.world.level.block.state.properties.BlockStateEnum;
+// CraftBukkit start
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+// CraftBukkit end
+
public class BlockPumpkinCarved extends BlockFacingHorizontal {
public static final MapCodec<BlockPumpkinCarved> CODEC = simpleCodec(BlockPumpkinCarved::new);
@@ -87,9 +91,14 @@
}
private static void spawnGolemInWorld(World world, ShapeDetector.ShapeDetectorCollection shapedetector_shapedetectorcollection, Entity entity, BlockPosition blockposition) {
- clearPatternBlocks(world, shapedetector_shapedetectorcollection);
+ // clearPatternBlocks(world, shapedetector_shapedetectorcollection); // CraftBukkit - moved down
entity.moveTo((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.05D, (double) blockposition.getZ() + 0.5D, 0.0F, 0.0F);
- world.addFreshEntity(entity);
+ // CraftBukkit start
+ if (!world.addFreshEntity(entity, (entity.getType() == EntityTypes.SNOW_GOLEM) ? SpawnReason.BUILD_SNOWMAN : SpawnReason.BUILD_IRONGOLEM)) {
+ return;
+ }
+ clearPatternBlocks(world, shapedetector_shapedetectorcollection); // CraftBukkit - from above
+ // CraftBukkit end
Iterator iterator = world.getEntitiesOfClass(EntityPlayer.class, entity.getBoundingBox().inflate(5.0D)).iterator();
while (iterator.hasNext()) {

View File

@@ -0,0 +1,40 @@
--- a/net/minecraft/world/level/block/BlockRedstoneComparator.java
+++ b/net/minecraft/world/level/block/BlockRedstoneComparator.java
@@ -28,6 +28,8 @@
import net.minecraft.world.phys.MovingObjectPositionBlock;
import net.minecraft.world.ticks.TickListPriority;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class BlockRedstoneComparator extends BlockDiodeAbstract implements ITileEntity {
public static final MapCodec<BlockRedstoneComparator> CODEC = simpleCodec(BlockRedstoneComparator::new);
@@ -110,7 +112,8 @@
@Nullable
private EntityItemFrame getItemFrame(World world, EnumDirection enumdirection, BlockPosition blockposition) {
- List<EntityItemFrame> list = world.getEntitiesOfClass(EntityItemFrame.class, new AxisAlignedBB((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), (double) (blockposition.getX() + 1), (double) (blockposition.getY() + 1), (double) (blockposition.getZ() + 1)), (entityitemframe) -> {
+ // CraftBukkit - decompile error
+ List<EntityItemFrame> list = world.getEntitiesOfClass(EntityItemFrame.class, new AxisAlignedBB((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), (double) (blockposition.getX() + 1), (double) (blockposition.getY() + 1), (double) (blockposition.getZ() + 1)), (java.util.function.Predicate<EntityItemFrame>) (entityitemframe) -> {
return entityitemframe != null && entityitemframe.getDirection() == enumdirection;
});
@@ -163,8 +166,18 @@
boolean flag1 = (Boolean) iblockdata.getValue(BlockRedstoneComparator.POWERED);
if (flag1 && !flag) {
+ // CraftBukkit start
+ if (CraftEventFactory.callRedstoneChange(world, blockposition, 15, 0).getNewCurrent() != 0) {
+ return;
+ }
+ // CraftBukkit end
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneComparator.POWERED, false), 2);
} else if (!flag1 && flag) {
+ // CraftBukkit start
+ if (CraftEventFactory.callRedstoneChange(world, blockposition, 0, 15).getNewCurrent() != 15) {
+ return;
+ }
+ // CraftBukkit end
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneComparator.POWERED, true), 2);
}

View File

@@ -0,0 +1,35 @@
--- a/net/minecraft/world/level/block/BlockRedstoneLamp.java
+++ b/net/minecraft/world/level/block/BlockRedstoneLamp.java
@@ -13,6 +13,8 @@
import net.minecraft.world.level.block.state.properties.BlockStateBoolean;
import net.minecraft.world.level.redstone.Orientation;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class BlockRedstoneLamp extends Block {
public static final MapCodec<BlockRedstoneLamp> CODEC = simpleCodec(BlockRedstoneLamp::new);
@@ -43,6 +45,11 @@
if (flag1) {
world.scheduleTick(blockposition, (Block) this, 4);
} else {
+ // CraftBukkit start
+ if (CraftEventFactory.callRedstoneChange(world, blockposition, 0, 15).getNewCurrent() != 15) {
+ return;
+ }
+ // CraftBukkit end
world.setBlock(blockposition, (IBlockData) iblockdata.cycle(BlockRedstoneLamp.LIT), 2);
}
}
@@ -53,6 +60,11 @@
@Override
protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if ((Boolean) iblockdata.getValue(BlockRedstoneLamp.LIT) && !worldserver.hasNeighborSignal(blockposition)) {
+ // CraftBukkit start
+ if (CraftEventFactory.callRedstoneChange(worldserver, blockposition, 15, 0).getNewCurrent() != 0) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) iblockdata.cycle(BlockRedstoneLamp.LIT), 2);
}

View File

@@ -0,0 +1,98 @@
--- a/net/minecraft/world/level/block/BlockRedstoneOre.java
+++ b/net/minecraft/world/level/block/BlockRedstoneOre.java
@@ -21,6 +21,11 @@
import net.minecraft.world.level.block.state.properties.BlockStateBoolean;
import net.minecraft.world.phys.MovingObjectPositionBlock;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
+
public class BlockRedstoneOre extends Block {
public static final MapCodec<BlockRedstoneOre> CODEC = simpleCodec(BlockRedstoneOre::new);
@@ -38,14 +43,27 @@
@Override
protected void attack(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman) {
- interact(iblockdata, world, blockposition);
+ interact(iblockdata, world, blockposition, entityhuman); // CraftBukkit - add entityhuman
super.attack(iblockdata, world, blockposition, entityhuman);
}
@Override
public void stepOn(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity) {
if (!entity.isSteppingCarefully()) {
- interact(iblockdata, world, blockposition);
+ // CraftBukkit start
+ if (entity instanceof EntityHuman) {
+ org.bukkit.event.player.PlayerInteractEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ if (!event.isCancelled()) {
+ interact(world.getBlockState(blockposition), world, blockposition, entity); // add entity
+ }
+ } else {
+ EntityInteractEvent event = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ world.getCraftServer().getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ interact(world.getBlockState(blockposition), world, blockposition, entity); // add entity
+ }
+ }
+ // CraftBukkit end
}
super.stepOn(world, blockposition, iblockdata, entity);
@@ -56,15 +74,20 @@
if (world.isClientSide) {
spawnParticles(world, blockposition);
} else {
- interact(iblockdata, world, blockposition);
+ interact(iblockdata, world, blockposition, entityhuman); // CraftBukkit - add entityhuman
}
return (EnumInteractionResult) (itemstack.getItem() instanceof ItemBlock && (new BlockActionContext(entityhuman, enumhand, itemstack, movingobjectpositionblock)).canPlace() ? EnumInteractionResult.PASS : EnumInteractionResult.SUCCESS);
}
- private static void interact(IBlockData iblockdata, World world, BlockPosition blockposition) {
+ private static void interact(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { // CraftBukkit - add Entity
spawnParticles(world, blockposition);
if (!(Boolean) iblockdata.getValue(BlockRedstoneOre.LIT)) {
+ // CraftBukkit start
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata.setValue(BlockRedstoneOre.LIT, true))) {
+ return;
+ }
+ // CraftBukkit end
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneOre.LIT, true), 3);
}
@@ -78,6 +101,11 @@
@Override
protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if ((Boolean) iblockdata.getValue(BlockRedstoneOre.LIT)) {
+ // CraftBukkit start
+ if (CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, iblockdata.setValue(BlockRedstoneOre.LIT, false)).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneOre.LIT, false), 3);
}
@@ -86,10 +114,17 @@
@Override
protected void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) {
super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag);
+ // CraftBukkit start - Delegated to getExpDrop
+ }
+
+ @Override
+ public int getExpDrop(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) {
if (flag) {
- this.tryDropExperience(worldserver, blockposition, itemstack, UniformInt.of(1, 5));
+ return this.tryDropExperience(worldserver, blockposition, itemstack, UniformInt.of(1, 5));
}
+ return 0;
+ // CraftBukkit end
}
@Override

View File

@@ -0,0 +1,52 @@
--- a/net/minecraft/world/level/block/BlockRedstoneTorch.java
+++ b/net/minecraft/world/level/block/BlockRedstoneTorch.java
@@ -22,6 +22,8 @@
import net.minecraft.world.level.redstone.ExperimentalRedstoneUtils;
import net.minecraft.world.level.redstone.Orientation;
+import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
+
public class BlockRedstoneTorch extends BaseTorchBlock {
public static final MapCodec<BlockRedstoneTorch> CODEC = simpleCodec(BlockRedstoneTorch::new);
@@ -85,8 +87,24 @@
list.remove(0);
}
+ // CraftBukkit start
+ org.bukkit.plugin.PluginManager manager = worldserver.getCraftServer().getPluginManager();
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ int oldCurrent = ((Boolean) iblockdata.getValue(BlockRedstoneTorch.LIT)).booleanValue() ? 15 : 0;
+
+ BlockRedstoneEvent event = new BlockRedstoneEvent(block, oldCurrent, oldCurrent);
+ // CraftBukkit end
if ((Boolean) iblockdata.getValue(BlockRedstoneTorch.LIT)) {
if (flag) {
+ // CraftBukkit start
+ if (oldCurrent != 0) {
+ event.setNewCurrent(0);
+ manager.callEvent(event);
+ if (event.getNewCurrent() != 0) {
+ return;
+ }
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneTorch.LIT, false), 3);
if (isToggledTooFrequently(worldserver, blockposition, true)) {
worldserver.levelEvent(1502, blockposition, 0);
@@ -94,6 +112,15 @@
}
}
} else if (!flag && !isToggledTooFrequently(worldserver, blockposition, false)) {
+ // CraftBukkit start
+ if (oldCurrent != 15) {
+ event.setNewCurrent(15);
+ manager.callEvent(event);
+ if (event.getNewCurrent() != 15) {
+ return;
+ }
+ }
+ // CraftBukkit end
worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneTorch.LIT, true), 3);
}

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/level/block/BlockReed.java
+++ b/net/minecraft/world/level/block/BlockReed.java
@@ -63,7 +63,7 @@
int j = (Integer) iblockdata.getValue(BlockReed.AGE);
if (j == 15) {
- worldserver.setBlockAndUpdate(blockposition.above(), this.defaultBlockState());
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition.above(), this.defaultBlockState()); // CraftBukkit
worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockReed.AGE, 0), 4);
} else {
worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockReed.AGE, j + 1), 4);

View File

@@ -0,0 +1,39 @@
--- a/net/minecraft/world/level/block/BlockRespawnAnchor.java
+++ b/net/minecraft/world/level/block/BlockRespawnAnchor.java
@@ -88,7 +88,7 @@
EntityPlayer entityplayer = (EntityPlayer) entityhuman;
if (entityplayer.getRespawnDimension() != world.dimension() || !blockposition.equals(entityplayer.getRespawnPosition())) {
- entityplayer.setRespawnPosition(world.dimension(), blockposition, 0.0F, false, true);
+ entityplayer.setRespawnPosition(world.dimension(), blockposition, 0.0F, false, true, org.bukkit.event.player.PlayerSpawnChangeEvent.Cause.RESPAWN_ANCHOR); // CraftBukkit
world.playSound((EntityHuman) null, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, SoundEffects.RESPAWN_ANCHOR_SET_SPAWN, SoundCategory.BLOCKS, 1.0F, 1.0F);
return EnumInteractionResult.SUCCESS_SERVER;
}
@@ -127,15 +127,16 @@
}
private void explode(IBlockData iblockdata, World world, final BlockPosition blockposition) {
+ org.bukkit.block.BlockState blockState = org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition).getState(); // CraftBukkit - capture BlockState before remove block
world.removeBlock(blockposition, false);
- Stream stream = EnumDirection.EnumDirectionLimit.HORIZONTAL.stream();
+ Stream<EnumDirection> stream = EnumDirection.EnumDirectionLimit.HORIZONTAL.stream(); // CraftBukkit - decompile error
Objects.requireNonNull(blockposition);
boolean flag = stream.map(blockposition::relative).anyMatch((blockposition1) -> {
return isWaterThatWouldFlow(blockposition1, world);
});
final boolean flag1 = flag || world.getFluidState(blockposition.above()).is(TagsFluid.WATER);
- ExplosionDamageCalculator explosiondamagecalculator = new ExplosionDamageCalculator(this) {
+ ExplosionDamageCalculator explosiondamagecalculator = new ExplosionDamageCalculator() { // CraftBukkit - decompile error
@Override
public Optional<Float> getBlockExplosionResistance(Explosion explosion, IBlockAccess iblockaccess, BlockPosition blockposition1, IBlockData iblockdata1, Fluid fluid) {
return blockposition1.equals(blockposition) && flag1 ? Optional.of(Blocks.WATER.getExplosionResistance()) : super.getBlockExplosionResistance(explosion, iblockaccess, blockposition1, iblockdata1, fluid);
@@ -143,7 +144,7 @@
};
Vec3D vec3d = blockposition.getCenter();
- world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d), explosiondamagecalculator, vec3d, 5.0F, true, World.a.BLOCK);
+ world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d, blockState), explosiondamagecalculator, vec3d, 5.0F, true, World.a.BLOCK); // CraftBukkit - add state
}
public static boolean canSetSpawn(World world) {

View File

@@ -0,0 +1,60 @@
--- a/net/minecraft/world/level/block/BlockSapling.java
+++ b/net/minecraft/world/level/block/BlockSapling.java
@@ -17,6 +17,15 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.TreeType;
+import org.bukkit.block.BlockState;
+import org.bukkit.craftbukkit.block.CapturedBlockState;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.event.world.StructureGrowEvent;
+// CraftBukkit end
+
public class BlockSapling extends BlockPlant implements IBlockFragilePlantElement {
public static final MapCodec<BlockSapling> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -28,6 +37,7 @@
protected static final float AABB_OFFSET = 6.0F;
protected static final VoxelShape SHAPE = Block.box(2.0D, 0.0D, 2.0D, 14.0D, 12.0D, 14.0D);
protected final WorldGenTreeProvider treeGrower;
+ public static TreeType treeType; // CraftBukkit
@Override
public MapCodec<? extends BlockSapling> codec() {
@@ -57,7 +67,32 @@
if ((Integer) iblockdata.getValue(BlockSapling.STAGE) == 0) {
worldserver.setBlock(blockposition, (IBlockData) iblockdata.cycle(BlockSapling.STAGE), 4);
} else {
- this.treeGrower.growTree(worldserver, worldserver.getChunkSource().getGenerator(), blockposition, iblockdata, randomsource);
+ // CraftBukkit start
+ if (worldserver.captureTreeGeneration) {
+ this.treeGrower.growTree(worldserver, worldserver.getChunkSource().getGenerator(), blockposition, iblockdata, randomsource);
+ } else {
+ worldserver.captureTreeGeneration = true;
+ this.treeGrower.growTree(worldserver, worldserver.getChunkSource().getGenerator(), blockposition, iblockdata, randomsource);
+ worldserver.captureTreeGeneration = false;
+ if (worldserver.capturedBlockStates.size() > 0) {
+ TreeType treeType = BlockSapling.treeType;
+ BlockSapling.treeType = null;
+ Location location = CraftLocation.toBukkit(blockposition, worldserver.getWorld());
+ java.util.List<BlockState> blocks = new java.util.ArrayList<>(worldserver.capturedBlockStates.values());
+ worldserver.capturedBlockStates.clear();
+ StructureGrowEvent event = null;
+ if (treeType != null) {
+ event = new StructureGrowEvent(location, treeType, false, null, blocks);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ }
+ if (event == null || !event.isCancelled()) {
+ for (BlockState blockstate : blocks) {
+ CapturedBlockState.setBlockState(blockstate);
+ }
+ }
+ }
+ }
+ // CraftBukkit end
}
}

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/level/block/BlockScaffolding.java
+++ b/net/minecraft/world/level/block/BlockScaffolding.java
@@ -103,7 +103,7 @@
int i = getDistance(worldserver, blockposition);
IBlockData iblockdata1 = (IBlockData) ((IBlockData) iblockdata.setValue(BlockScaffolding.DISTANCE, i)).setValue(BlockScaffolding.BOTTOM, this.isBottom(worldserver, blockposition, i));
- if ((Integer) iblockdata1.getValue(BlockScaffolding.DISTANCE) == 7) {
+ if ((Integer) iblockdata1.getValue(BlockScaffolding.DISTANCE) == 7 && !org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, Blocks.AIR.defaultBlockState()).isCancelled()) { // CraftBukkit - BlockFadeEvent
if ((Integer) iblockdata.getValue(BlockScaffolding.DISTANCE) == 7) {
EntityFallingBlock.fall(worldserver, blockposition, iblockdata1);
} else {

View File

@@ -0,0 +1,35 @@
--- a/net/minecraft/world/level/block/BlockSign.java
+++ b/net/minecraft/world/level/block/BlockSign.java
@@ -140,7 +140,7 @@
} else if (flag1) {
return EnumInteractionResult.SUCCESS_SERVER;
} else if (!this.otherPlayerIsEditingSign(entityhuman, tileentitysign) && entityhuman.mayBuild() && this.hasEditableText(entityhuman, tileentitysign, flag)) {
- this.openTextEdit(entityhuman, tileentitysign, flag);
+ this.openTextEdit(entityhuman, tileentitysign, flag, org.bukkit.event.player.PlayerSignOpenEvent.Cause.INTERACT); // CraftBukkit
return EnumInteractionResult.SUCCESS_SERVER;
} else {
return EnumInteractionResult.PASS;
@@ -186,6 +186,15 @@
}
public void openTextEdit(EntityHuman entityhuman, TileEntitySign tileentitysign, boolean flag) {
+ // Craftbukkit start
+ openTextEdit(entityhuman, tileentitysign, flag, org.bukkit.event.player.PlayerSignOpenEvent.Cause.UNKNOWN);
+ }
+
+ public void openTextEdit(EntityHuman entityhuman, TileEntitySign tileentitysign, boolean flag, org.bukkit.event.player.PlayerSignOpenEvent.Cause cause) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerSignOpenEvent(entityhuman, tileentitysign, flag, cause)) {
+ return;
+ }
+ // Craftbukkit end
tileentitysign.setAllowedPlayerEditor(entityhuman.getUUID());
entityhuman.openTextEdit(tileentitysign, flag);
}
@@ -199,6 +208,6 @@
@Nullable
@Override
public <T extends TileEntity> BlockEntityTicker<T> getTicker(World world, IBlockData iblockdata, TileEntityTypes<T> tileentitytypes) {
- return createTickerHelper(tileentitytypes, TileEntityTypes.SIGN, TileEntitySign::tick);
+ return null; // Craftbukkit - remove unnecessary sign ticking
}
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockSnow.java
+++ b/net/minecraft/world/level/block/BlockSnow.java
@@ -99,6 +99,11 @@
@Override
protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
if (worldserver.getBrightness(EnumSkyBlock.BLOCK, blockposition) > 11) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, Blocks.AIR.defaultBlockState()).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
dropResources(iblockdata, worldserver, blockposition);
worldserver.removeBlock(blockposition, false);
}

View File

@@ -0,0 +1,69 @@
--- a/net/minecraft/world/level/block/BlockSoil.java
+++ b/net/minecraft/world/level/block/BlockSoil.java
@@ -30,6 +30,11 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityInteractEvent;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class BlockSoil extends Block {
public static final MapCodec<BlockSoil> CODEC = simpleCodec(BlockSoil::new);
@@ -92,28 +97,51 @@
if (!isNearWater(worldserver, blockposition) && !worldserver.isRainingAt(blockposition.above())) {
if (i > 0) {
- worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockSoil.MOISTURE, i - 1), 2);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleMoistureChangeEvent(worldserver, blockposition, (IBlockData) iblockdata.setValue(BlockSoil.MOISTURE, i - 1), 2); // CraftBukkit
} else if (!shouldMaintainFarmland(worldserver, blockposition)) {
turnToDirt((Entity) null, iblockdata, worldserver, blockposition);
}
} else if (i < 7) {
- worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockSoil.MOISTURE, 7), 2);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleMoistureChangeEvent(worldserver, blockposition, (IBlockData) iblockdata.setValue(BlockSoil.MOISTURE, 7), 2); // CraftBukkit
}
}
@Override
public void fallOn(World world, IBlockData iblockdata, BlockPosition blockposition, Entity entity, float f) {
+ super.fallOn(world, iblockdata, blockposition, entity, f); // CraftBukkit - moved here as game rules / events shouldn't affect fall damage.
if (world instanceof WorldServer worldserver) {
if (world.random.nextFloat() < f - 0.5F && entity instanceof EntityLiving && (entity instanceof EntityHuman || worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F) {
+ // CraftBukkit start - Interact soil
+ org.bukkit.event.Cancellable cancellable;
+ if (entity instanceof EntityHuman) {
+ cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ } else {
+ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ world.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
+ }
+
+ if (cancellable.isCancelled()) {
+ return;
+ }
+
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.DIRT.defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end
turnToDirt(entity, iblockdata, world, blockposition);
}
}
- super.fallOn(world, iblockdata, blockposition, entity, f);
+ // super.fallOn(world, iblockdata, blockposition, entity, f); // CraftBukkit - moved up
}
public static void turnToDirt(@Nullable Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) {
+ // CraftBukkit start
+ if (CraftEventFactory.callBlockFadeEvent(world, blockposition, Blocks.DIRT.defaultBlockState()).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
IBlockData iblockdata1 = pushEntitiesUp(iblockdata, Blocks.DIRT.defaultBlockState(), world, blockposition);
world.setBlockAndUpdate(blockposition, iblockdata1);

View File

@@ -0,0 +1,110 @@
--- a/net/minecraft/world/level/block/BlockSponge.java
+++ b/net/minecraft/world/level/block/BlockSponge.java
@@ -15,6 +15,13 @@
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.redstone.Orientation;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.util.BlockStateListPopulator;
+import org.bukkit.event.block.SpongeAbsorbEvent;
+// CraftBukkit end
+
public class BlockSponge extends Block {
public static final MapCodec<BlockSponge> CODEC = simpleCodec(BlockSponge::new);
@@ -53,7 +60,8 @@
}
private boolean removeWaterBreadthFirstSearch(World world, BlockPosition blockposition) {
- return BlockPosition.breadthFirstTraversal(blockposition, 6, 65, (blockposition1, consumer) -> {
+ BlockStateListPopulator blockList = new BlockStateListPopulator(world); // CraftBukkit - Use BlockStateListPopulator
+ BlockPosition.breadthFirstTraversal(blockposition, 6, 65, (blockposition1, consumer) -> {
EnumDirection[] aenumdirection = BlockSponge.ALL_DIRECTIONS;
int i = aenumdirection.length;
@@ -67,8 +75,10 @@
if (blockposition1.equals(blockposition)) {
return BlockPosition.b.ACCEPT;
} else {
- IBlockData iblockdata = world.getBlockState(blockposition1);
- Fluid fluid = world.getFluidState(blockposition1);
+ // CraftBukkit start
+ IBlockData iblockdata = blockList.getBlockState(blockposition1);
+ Fluid fluid = blockList.getFluidState(blockposition1);
+ // CraftBukkit end
if (!fluid.is(TagsFluid.WATER)) {
return BlockPosition.b.SKIP;
@@ -78,27 +88,64 @@
if (block instanceof IFluidSource) {
IFluidSource ifluidsource = (IFluidSource) block;
- if (!ifluidsource.pickupBlock((EntityHuman) null, world, blockposition1, iblockdata).isEmpty()) {
+ if (!ifluidsource.pickupBlock((EntityHuman) null, blockList, blockposition1, iblockdata).isEmpty()) { // CraftBukkit
return BlockPosition.b.ACCEPT;
}
}
if (iblockdata.getBlock() instanceof BlockFluids) {
- world.setBlock(blockposition1, Blocks.AIR.defaultBlockState(), 3);
+ blockList.setBlock(blockposition1, Blocks.AIR.defaultBlockState(), 3); // CraftBukkit
} else {
if (!iblockdata.is(Blocks.KELP) && !iblockdata.is(Blocks.KELP_PLANT) && !iblockdata.is(Blocks.SEAGRASS) && !iblockdata.is(Blocks.TALL_SEAGRASS)) {
return BlockPosition.b.SKIP;
}
- TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition1) : null;
+ // CraftBukkit start
+ // TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition1) : null;
- dropResources(iblockdata, world, blockposition1, tileentity);
- world.setBlock(blockposition1, Blocks.AIR.defaultBlockState(), 3);
+ // dropResources(iblockdata, world, blockposition1, tileentity);
+ blockList.setBlock(blockposition1, Blocks.AIR.defaultBlockState(), 3);
+ // CraftBukkit end
}
return BlockPosition.b.ACCEPT;
}
}
- }) > 1;
+ });
+ // CraftBukkit start
+ List<CraftBlockState> blocks = blockList.getList(); // Is a clone
+ if (!blocks.isEmpty()) {
+ final org.bukkit.block.Block bblock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+
+ SpongeAbsorbEvent event = new SpongeAbsorbEvent(bblock, (List<org.bukkit.block.BlockState>) (List) blocks);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return false;
+ }
+
+ for (CraftBlockState block : blocks) {
+ BlockPosition blockposition1 = block.getPosition();
+ IBlockData iblockdata = world.getBlockState(blockposition1);
+ Fluid fluid = world.getFluidState(blockposition1);
+
+ if (fluid.is(TagsFluid.WATER)) {
+ if (iblockdata.getBlock() instanceof IFluidSource && !((IFluidSource) iblockdata.getBlock()).pickupBlock((EntityHuman) null, blockList, blockposition1, iblockdata).isEmpty()) {
+ // NOP
+ } else if (iblockdata.getBlock() instanceof BlockFluids) {
+ // NOP
+ } else if (iblockdata.is(Blocks.KELP) || iblockdata.is(Blocks.KELP_PLANT) || iblockdata.is(Blocks.SEAGRASS) || iblockdata.is(Blocks.TALL_SEAGRASS)) {
+ TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition1) : null;
+
+ dropResources(iblockdata, world, blockposition1, tileentity);
+ }
+ }
+ world.setBlock(blockposition1, block.getHandle(), block.getFlag());
+ }
+
+ return true;
+ }
+ return false;
+ // CraftBukkit end
}
}

View File

@@ -0,0 +1,42 @@
--- a/net/minecraft/world/level/block/BlockStem.java
+++ b/net/minecraft/world/level/block/BlockStem.java
@@ -27,6 +27,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class BlockStem extends BlockPlant implements IBlockFragilePlantElement {
public static final MapCodec<BlockStem> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -79,7 +81,7 @@
if (i < 7) {
iblockdata = (IBlockData) iblockdata.setValue(BlockStem.AGE, i + 1);
- worldserver.setBlock(blockposition, iblockdata, 2);
+ CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, iblockdata, 2); // CraftBukkit
} else {
EnumDirection enumdirection = EnumDirection.EnumDirectionLimit.HORIZONTAL.getRandomDirection(randomsource);
BlockPosition blockposition1 = blockposition.relative(enumdirection);
@@ -91,7 +93,11 @@
Optional<Block> optional1 = iregistry.getOptional(this.attachedStem);
if (optional.isPresent() && optional1.isPresent()) {
- worldserver.setBlockAndUpdate(blockposition1, ((Block) optional.get()).defaultBlockState());
+ // CraftBukkit start
+ if (!CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition1, ((Block) optional.get()).defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end
worldserver.setBlockAndUpdate(blockposition, (IBlockData) ((Block) optional1.get()).defaultBlockState().setValue(BlockFacingHorizontal.FACING, enumdirection));
}
}
@@ -121,7 +127,7 @@
int i = Math.min(7, (Integer) iblockdata.getValue(BlockStem.AGE) + MathHelper.nextInt(worldserver.random, 2, 5));
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockStem.AGE, i);
- worldserver.setBlock(blockposition, iblockdata1, 2);
+ CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, iblockdata1, 2); // CraftBukkit
if (i == 7) {
iblockdata1.randomTick(worldserver, blockposition, worldserver.random);
}

View File

@@ -0,0 +1,51 @@
--- a/net/minecraft/world/level/block/BlockSweetBerryBush.java
+++ b/net/minecraft/world/level/block/BlockSweetBerryBush.java
@@ -29,6 +29,13 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import java.util.Collections;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerHarvestBlockEvent;
+// CraftBukkit end
+
public class BlockSweetBerryBush extends BlockPlant implements IBlockFragilePlantElement {
public static final MapCodec<BlockSweetBerryBush> CODEC = simpleCodec(BlockSweetBerryBush::new);
@@ -70,7 +77,7 @@
if (i < 3 && randomsource.nextInt(5) == 0 && worldserver.getRawBrightness(blockposition.above(), 0) >= 9) {
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSweetBerryBush.AGE, i + 1);
- worldserver.setBlock(blockposition, iblockdata1, 2);
+ if (!CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, iblockdata1, 2)) return; // CraftBukkit
worldserver.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1));
}
@@ -91,7 +98,7 @@
double d1 = Math.abs(vec3d.z());
if (d0 >= 0.003000000026077032D || d1 >= 0.003000000026077032D) {
- entity.hurtServer(worldserver, world.damageSources().sweetBerryBush(), 1.0F);
+ entity.hurtServer(worldserver, world.damageSources().sweetBerryBush().directBlock(world, blockposition), 1.0F); // CraftBukkit
}
}
@@ -118,7 +125,15 @@
if (i > 1) {
int j = 1 + world.random.nextInt(2);
- popResource(world, blockposition, new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0)));
+ // CraftBukkit start - useWithoutItem is always MAIN_HAND
+ PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(world, blockposition, entityhuman, EnumHand.MAIN_HAND, Collections.singletonList(new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0))));
+ if (event.isCancelled()) {
+ return EnumInteractionResult.SUCCESS; // We need to return a success either way, because making it PASS or FAIL will result in a bug where cancelling while harvesting w/ block in hand places block
+ }
+ for (org.bukkit.inventory.ItemStack itemStack : event.getItemsHarvested()) {
+ popResource(world, blockposition, CraftItemStack.asNMSCopy(itemStack));
+ }
+ // CraftBukkit end
world.playSound((EntityHuman) null, blockposition, SoundEffects.SWEET_BERRY_BUSH_PICK_BERRIES, SoundCategory.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4F);
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSweetBerryBush.AGE, 1);

View File

@@ -0,0 +1,65 @@
--- a/net/minecraft/world/level/block/BlockTNT.java
+++ b/net/minecraft/world/level/block/BlockTNT.java
@@ -29,6 +29,11 @@
import net.minecraft.world.level.redstone.Orientation;
import net.minecraft.world.phys.MovingObjectPositionBlock;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.TNTPrimeEvent.PrimeCause;
+// CraftBukkit end
+
public class BlockTNT extends Block {
public static final MapCodec<BlockTNT> CODEC = simpleCodec(BlockTNT::new);
@@ -47,7 +52,7 @@
@Override
protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
if (!iblockdata1.is(iblockdata.getBlock())) {
- if (world.hasNeighborSignal(blockposition)) {
+ if (world.hasNeighborSignal(blockposition) && CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent
explode(world, blockposition);
world.removeBlock(blockposition, false);
}
@@ -57,7 +62,7 @@
@Override
protected void neighborChanged(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, @Nullable Orientation orientation, boolean flag) {
- if (world.hasNeighborSignal(blockposition)) {
+ if (world.hasNeighborSignal(blockposition) && CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent
explode(world, blockposition);
world.removeBlock(blockposition, false);
}
@@ -66,7 +71,7 @@
@Override
public IBlockData playerWillDestroy(World world, BlockPosition blockposition, IBlockData iblockdata, EntityHuman entityhuman) {
- if (!world.isClientSide() && !entityhuman.isCreative() && (Boolean) iblockdata.getValue(BlockTNT.UNSTABLE)) {
+ if (!world.isClientSide() && !entityhuman.isCreative() && (Boolean) iblockdata.getValue(BlockTNT.UNSTABLE) && CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.BLOCK_BREAK, entityhuman, null)) { // CraftBukkit - TNTPrimeEvent
explode(world, blockposition);
}
@@ -101,6 +106,11 @@
if (!itemstack.is(Items.FLINT_AND_STEEL) && !itemstack.is(Items.FIRE_CHARGE)) {
return super.useItemOn(itemstack, iblockdata, world, blockposition, entityhuman, enumhand, movingobjectpositionblock);
} else {
+ // CraftBukkit start - TNTPrimeEvent
+ if (!CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.PLAYER, entityhuman, null)) {
+ return EnumInteractionResult.CONSUME;
+ }
+ // CraftBukkit end
explode(world, blockposition, entityhuman);
world.setBlock(blockposition, Blocks.AIR.defaultBlockState(), 11);
Item item = itemstack.getItem();
@@ -123,6 +133,11 @@
Entity entity = iprojectile.getOwner();
if (iprojectile.isOnFire() && iprojectile.mayInteract(worldserver, blockposition)) {
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState()) || !CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.PROJECTILE, iprojectile, null)) {
+ return;
+ }
+ // CraftBukkit end
explode(world, blockposition, entity instanceof EntityLiving ? (EntityLiving) entity : null);
world.removeBlock(blockposition, false);
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/block/BlockTallPlant.java
+++ b/net/minecraft/world/level/block/BlockTallPlant.java
@@ -103,6 +103,11 @@
}
protected static void preventDropFromBottomPart(World world, BlockPosition blockposition, IBlockData iblockdata, EntityHuman entityhuman) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world, blockposition).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
BlockPropertyDoubleBlockHalf blockpropertydoubleblockhalf = (BlockPropertyDoubleBlockHalf) iblockdata.getValue(BlockTallPlant.HALF);
if (blockpropertydoubleblockhalf == BlockPropertyDoubleBlockHalf.UPPER) {

View File

@@ -0,0 +1,31 @@
--- a/net/minecraft/world/level/block/BlockTrapdoor.java
+++ b/net/minecraft/world/level/block/BlockTrapdoor.java
@@ -38,6 +38,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
+
public class BlockTrapdoor extends BlockFacingHorizontal implements IBlockWaterlogged {
public static final MapCodec<BlockTrapdoor> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -143,6 +145,19 @@
boolean flag1 = world.hasNeighborSignal(blockposition);
if (flag1 != (Boolean) iblockdata.getValue(BlockTrapdoor.POWERED)) {
+ // CraftBukkit start
+ org.bukkit.World bworld = world.getWorld();
+ org.bukkit.block.Block bblock = bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+
+ int power = bblock.getBlockPower();
+ int oldPower = (Boolean) iblockdata.getValue(OPEN) ? 15 : 0;
+
+ if (oldPower == 0 ^ power == 0 || block.defaultBlockState().isSignalSource()) {
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bblock, oldPower, power);
+ world.getCraftServer().getPluginManager().callEvent(eventRedstone);
+ flag1 = eventRedstone.getNewCurrent() > 0;
+ }
+ // CraftBukkit end
if ((Boolean) iblockdata.getValue(BlockTrapdoor.OPEN) != flag1) {
iblockdata = (IBlockData) iblockdata.setValue(BlockTrapdoor.OPEN, flag1);
this.playSound((EntityHuman) null, world, blockposition, flag1);

View File

@@ -0,0 +1,52 @@
--- a/net/minecraft/world/level/block/BlockTripwire.java
+++ b/net/minecraft/world/level/block/BlockTripwire.java
@@ -29,6 +29,8 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import org.bukkit.event.entity.EntityInteractEvent; // CraftBukkit
+
public class BlockTripwire extends Block {
public static final MapCodec<BlockTripwire> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -179,6 +181,40 @@
}
}
+ // CraftBukkit start - Call interact even when triggering connected tripwire
+ if (flag != flag1 && flag1 && (Boolean)iblockdata.getValue(ATTACHED)) {
+ org.bukkit.World bworld = world.getWorld();
+ org.bukkit.plugin.PluginManager manager = world.getCraftServer().getPluginManager();
+ org.bukkit.block.Block block = bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ boolean allowed = false;
+
+ // If all of the events are cancelled block the tripwire trigger, else allow
+ for (Object object : list) {
+ if (object != null) {
+ org.bukkit.event.Cancellable cancellable;
+
+ if (object instanceof EntityHuman) {
+ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) object, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ } else if (object instanceof Entity) {
+ cancellable = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block);
+ manager.callEvent((EntityInteractEvent) cancellable);
+ } else {
+ continue;
+ }
+
+ if (!cancellable.isCancelled()) {
+ allowed = true;
+ break;
+ }
+ }
+ }
+
+ if (!allowed) {
+ return;
+ }
+ }
+ // CraftBukkit end
+
if (flag1 != flag) {
iblockdata = (IBlockData) iblockdata.setValue(BlockTripwire.POWERED, flag1);
world.setBlock(blockposition, iblockdata, 3);

View File

@@ -0,0 +1,30 @@
--- a/net/minecraft/world/level/block/BlockTripwireHook.java
+++ b/net/minecraft/world/level/block/BlockTripwireHook.java
@@ -32,6 +32,11 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.block.BlockRedstoneEvent;
+// CraftBukkit end
+
public class BlockTripwireHook extends Block {
public static final MapCodec<BlockTripwireHook> CODEC = simpleCodec(BlockTripwireHook::new);
@@ -176,6 +181,15 @@
emitState(world, blockposition1, flag4, flag5, flag2, flag3);
}
+ // CraftBukkit start
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(CraftBlock.at(world, blockposition), 15, 0);
+ world.getCraftServer().getPluginManager().callEvent(eventRedstone);
+
+ if (eventRedstone.getNewCurrent() > 0) {
+ return;
+ }
+ // CraftBukkit end
+
emitState(world, blockposition, flag4, flag5, flag2, flag3);
if (!flag) {
world.setBlock(blockposition, (IBlockData) iblockdata3.setValue(BlockTripwireHook.FACING, enumdirection), 3);

View File

@@ -0,0 +1,66 @@
--- a/net/minecraft/world/level/block/BlockTurtleEgg.java
+++ b/net/minecraft/world/level/block/BlockTurtleEgg.java
@@ -32,6 +32,12 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityInteractEvent;
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class BlockTurtleEgg extends Block {
public static final MapCodec<BlockTurtleEgg> CODEC = simpleCodec(BlockTurtleEgg::new);
@@ -74,6 +80,19 @@
private void destroyEgg(World world, IBlockData iblockdata, BlockPosition blockposition, Entity entity, int i) {
if (iblockdata.is(Blocks.TURTLE_EGG) && world instanceof WorldServer worldserver) {
if (this.canDestroyEgg(worldserver, entity) && world.random.nextInt(i) == 0) {
+ // CraftBukkit start - Step on eggs
+ org.bukkit.event.Cancellable cancellable;
+ if (entity instanceof EntityHuman) {
+ cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ } else {
+ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), CraftBlock.at(worldserver, blockposition));
+ worldserver.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
+ }
+
+ if (cancellable.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
this.decreaseEggs(worldserver, blockposition, iblockdata);
}
}
@@ -100,10 +119,20 @@
int i = (Integer) iblockdata.getValue(BlockTurtleEgg.HATCH);
if (i < 2) {
+ // CraftBukkit start - Call BlockGrowEvent
+ if (!CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, iblockdata.setValue(BlockTurtleEgg.HATCH, i + 1), 2)) {
+ return;
+ }
+ // CraftBukkit end
worldserver.playSound((EntityHuman) null, blockposition, SoundEffects.TURTLE_EGG_CRACK, SoundCategory.BLOCKS, 0.7F, 0.9F + randomsource.nextFloat() * 0.2F);
- worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockTurtleEgg.HATCH, i + 1), 2);
+ // worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockTurtleEgg.HATCH, i + 1), 2); // CraftBukkit - handled above
worldserver.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata));
} else {
+ // CraftBukkit start - Call BlockFadeEvent
+ if (CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, Blocks.AIR.defaultBlockState()).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
worldserver.playSound((EntityHuman) null, blockposition, SoundEffects.TURTLE_EGG_HATCH, SoundCategory.BLOCKS, 0.7F, 0.9F + randomsource.nextFloat() * 0.2F);
worldserver.removeBlock(blockposition, false);
worldserver.gameEvent((Holder) GameEvent.BLOCK_DESTROY, blockposition, GameEvent.a.of(iblockdata));
@@ -116,7 +145,7 @@
entityturtle.setAge(-24000);
entityturtle.setHomePos(blockposition);
entityturtle.moveTo((double) blockposition.getX() + 0.3D + (double) j * 0.2D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.3D, 0.0F, 0.0F);
- worldserver.addFreshEntity(entityturtle);
+ worldserver.addFreshEntity(entityturtle, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // CraftBukkit
}
}
}

View File

@@ -0,0 +1,71 @@
--- a/net/minecraft/world/level/block/BlockVine.java
+++ b/net/minecraft/world/level/block/BlockVine.java
@@ -25,6 +25,8 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class BlockVine extends Block {
public static final MapCodec<BlockVine> CODEC = simpleCodec(BlockVine::new);
@@ -203,30 +205,34 @@
BlockPosition blockposition3 = blockposition2.relative(enumdirection1);
BlockPosition blockposition4 = blockposition2.relative(enumdirection2);
+ // CraftBukkit start - Call BlockSpreadEvent
+ BlockPosition source = blockposition;
+
if (flag && isAcceptableNeighbour(worldserver, blockposition3, enumdirection1)) {
- worldserver.setBlock(blockposition2, (IBlockData) this.defaultBlockState().setValue(getPropertyForFace(enumdirection1), true), 2);
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, source, blockposition2, (IBlockData) this.defaultBlockState().setValue(getPropertyForFace(enumdirection1), true), 2);
} else if (flag1 && isAcceptableNeighbour(worldserver, blockposition4, enumdirection2)) {
- worldserver.setBlock(blockposition2, (IBlockData) this.defaultBlockState().setValue(getPropertyForFace(enumdirection2), true), 2);
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, source, blockposition2, (IBlockData) this.defaultBlockState().setValue(getPropertyForFace(enumdirection2), true), 2);
} else {
EnumDirection enumdirection3 = enumdirection.getOpposite();
if (flag && worldserver.isEmptyBlock(blockposition3) && isAcceptableNeighbour(worldserver, blockposition.relative(enumdirection1), enumdirection3)) {
- worldserver.setBlock(blockposition3, (IBlockData) this.defaultBlockState().setValue(getPropertyForFace(enumdirection3), true), 2);
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, source, blockposition3, (IBlockData) this.defaultBlockState().setValue(getPropertyForFace(enumdirection3), true), 2);
} else if (flag1 && worldserver.isEmptyBlock(blockposition4) && isAcceptableNeighbour(worldserver, blockposition.relative(enumdirection2), enumdirection3)) {
- worldserver.setBlock(blockposition4, (IBlockData) this.defaultBlockState().setValue(getPropertyForFace(enumdirection3), true), 2);
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, source, blockposition4, (IBlockData) this.defaultBlockState().setValue(getPropertyForFace(enumdirection3), true), 2);
} else if ((double) randomsource.nextFloat() < 0.05D && isAcceptableNeighbour(worldserver, blockposition2.above(), EnumDirection.UP)) {
- worldserver.setBlock(blockposition2, (IBlockData) this.defaultBlockState().setValue(BlockVine.UP, true), 2);
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, source, blockposition2, (IBlockData) this.defaultBlockState().setValue(BlockVine.UP, true), 2);
}
+ // CraftBukkit end
}
} else if (isAcceptableNeighbour(worldserver, blockposition2, enumdirection)) {
- worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(getPropertyForFace(enumdirection), true), 2);
+ CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, (IBlockData) iblockdata.setValue(getPropertyForFace(enumdirection), true), 2); // CraftBukkit
}
}
} else {
if (enumdirection == EnumDirection.UP && blockposition.getY() < worldserver.getMaxY()) {
if (this.canSupportAtFace(worldserver, blockposition, enumdirection)) {
- worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockVine.UP, true), 2);
+ CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, (IBlockData) iblockdata.setValue(BlockVine.UP, true), 2); // CraftBukkit
return;
}
@@ -246,7 +252,7 @@
}
if (this.hasHorizontalConnection(iblockdata2)) {
- worldserver.setBlock(blockposition1, iblockdata2, 2);
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition1, iblockdata2, 2); // CraftBukkit
}
return;
@@ -261,7 +267,7 @@
IBlockData iblockdata4 = this.copyRandomFaces(iblockdata, iblockdata3, randomsource);
if (iblockdata3 != iblockdata4 && this.hasHorizontalConnection(iblockdata4)) {
- worldserver.setBlock(blockposition2, iblockdata4, 2);
+ CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition2, iblockdata4, 2); // CraftBukkit
}
}
}

View File

@@ -0,0 +1,25 @@
--- a/net/minecraft/world/level/block/BlockWaterLily.java
+++ b/net/minecraft/world/level/block/BlockWaterLily.java
@@ -14,6 +14,10 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class BlockWaterLily extends BlockPlant {
public static final MapCodec<BlockWaterLily> CODEC = simpleCodec(BlockWaterLily::new);
@@ -32,6 +36,11 @@
protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
super.entityInside(iblockdata, world, blockposition, entity);
if (world instanceof WorldServer && entity instanceof AbstractBoat) {
+ // CraftBukkit start
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end
world.destroyBlock(new BlockPosition(blockposition), true, entity);
}

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/level/block/BlockWitherRose.java
+++ b/net/minecraft/world/level/block/BlockWitherRose.java
@@ -66,7 +66,7 @@
if (world instanceof WorldServer worldserver) {
if (world.getDifficulty() != EnumDifficulty.PEACEFUL && entity instanceof EntityLiving entityliving) {
if (!entityliving.isInvulnerableTo(worldserver, world.damageSources().wither())) {
- entityliving.addEffect(this.getBeeInteractionEffect());
+ entityliving.addEffect(this.getBeeInteractionEffect(), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.WITHER_ROSE); // CraftBukkit
}
}
}

View File

@@ -0,0 +1,50 @@
--- a/net/minecraft/world/level/block/BlockWitherSkull.java
+++ b/net/minecraft/world/level/block/BlockWitherSkull.java
@@ -26,6 +26,10 @@
import net.minecraft.world.level.block.state.pattern.ShapeDetectorBuilder;
import net.minecraft.world.level.block.state.predicate.BlockStatePredicate;
+// CraftBukkit start
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+// CraftBukkit end
+
public class BlockWitherSkull extends BlockSkull {
public static final MapCodec<BlockWitherSkull> CODEC = simpleCodec(BlockWitherSkull::new);
@@ -58,6 +62,7 @@
}
public static void checkSpawn(World world, BlockPosition blockposition, TileEntitySkull tileentityskull) {
+ if (world.captureBlockStates) return; // CraftBukkit
if (!world.isClientSide) {
IBlockData iblockdata = tileentityskull.getBlockState();
boolean flag = iblockdata.is(Blocks.WITHER_SKELETON_SKULL) || iblockdata.is(Blocks.WITHER_SKELETON_WALL_SKULL);
@@ -69,12 +74,18 @@
EntityWither entitywither = (EntityWither) EntityTypes.WITHER.create(world, EntitySpawnReason.TRIGGERED);
if (entitywither != null) {
- BlockPumpkinCarved.clearPatternBlocks(world, shapedetector_shapedetectorcollection);
+ // BlockPumpkinCarved.clearPatternBlocks(world, shapedetector_shapedetectorcollection); // CraftBukkit - move down
BlockPosition blockposition1 = shapedetector_shapedetectorcollection.getBlock(1, 2, 0).getPos();
entitywither.moveTo((double) blockposition1.getX() + 0.5D, (double) blockposition1.getY() + 0.55D, (double) blockposition1.getZ() + 0.5D, shapedetector_shapedetectorcollection.getForwards().getAxis() == EnumDirection.EnumAxis.X ? 0.0F : 90.0F, 0.0F);
entitywither.yBodyRot = shapedetector_shapedetectorcollection.getForwards().getAxis() == EnumDirection.EnumAxis.X ? 0.0F : 90.0F;
entitywither.makeInvulnerable();
+ // CraftBukkit start
+ if (!world.addFreshEntity(entitywither, SpawnReason.BUILD_WITHER)) {
+ return;
+ }
+ BlockPumpkinCarved.clearPatternBlocks(world, shapedetector_shapedetectorcollection); // CraftBukkit - from above
+ // CraftBukkit end
Iterator iterator = world.getEntitiesOfClass(EntityPlayer.class, entitywither.getBoundingBox().inflate(50.0D)).iterator();
while (iterator.hasNext()) {
@@ -83,7 +94,7 @@
CriterionTriggers.SUMMONED_ENTITY.trigger(entityplayer, (Entity) entitywither);
}
- world.addFreshEntity(entitywither);
+ // world.addFreshEntity(entitywither); // CraftBukkit - moved up
BlockPumpkinCarved.updatePatternBlocks(world, shapedetector_shapedetectorcollection);
}

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/level/block/BuddingAmethystBlock.java
+++ b/net/minecraft/world/level/block/BuddingAmethystBlock.java
@@ -45,7 +45,7 @@
if (block != null) {
IBlockData iblockdata2 = (IBlockData) ((IBlockData) block.defaultBlockState().setValue(AmethystClusterBlock.FACING, enumdirection)).setValue(AmethystClusterBlock.WATERLOGGED, iblockdata1.getFluidState().getType() == FluidTypes.WATER);
- worldserver.setBlockAndUpdate(blockposition1, iblockdata2);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition1, iblockdata2); // CraftBukkit
}
}

View File

@@ -0,0 +1,42 @@
--- a/net/minecraft/world/level/block/CaveVines.java
+++ b/net/minecraft/world/level/block/CaveVines.java
@@ -19,6 +19,13 @@
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.shapes.VoxelShape;
+// CraftBukkit start
+import java.util.Collections;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerHarvestBlockEvent;
+// CraftBukkit end
+
public interface CaveVines {
VoxelShape SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 16.0D, 15.0D);
@@ -26,7 +33,24 @@
static EnumInteractionResult use(@Nullable Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) {
if ((Boolean) iblockdata.getValue(CaveVines.BERRIES)) {
- Block.popResource(world, blockposition, new ItemStack(Items.GLOW_BERRIES, 1));
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, (IBlockData) iblockdata.setValue(CaveVines.BERRIES, false))) {
+ return EnumInteractionResult.SUCCESS;
+ }
+
+ if (entity instanceof EntityHuman) {
+ PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(world, blockposition, (EntityHuman) entity, net.minecraft.world.EnumHand.MAIN_HAND, Collections.singletonList(new ItemStack(Items.GLOW_BERRIES, 1)));
+ if (event.isCancelled()) {
+ return EnumInteractionResult.SUCCESS; // We need to return a success either way, because making it PASS or FAIL will result in a bug where cancelling while harvesting w/ block in hand places block
+ }
+ for (org.bukkit.inventory.ItemStack itemStack : event.getItemsHarvested()) {
+ Block.popResource(world, blockposition, CraftItemStack.asNMSCopy(itemStack));
+ }
+ } else {
+ Block.popResource(world, blockposition, new ItemStack(Items.GLOW_BERRIES, 1));
+ }
+ // CraftBukkit end
+
float f = MathHelper.randomBetween(world.random, 0.8F, 1.2F);
world.playSound((EntityHuman) null, blockposition, SoundEffects.CAVE_VINES_PICK_BERRIES, SoundCategory.BLOCKS, 1.0F, f);

View File

@@ -0,0 +1,10 @@
--- a/net/minecraft/world/level/block/CeilingHangingSignBlock.java
+++ b/net/minecraft/world/level/block/CeilingHangingSignBlock.java
@@ -159,6 +159,6 @@
@Nullable
@Override
public <T extends TileEntity> BlockEntityTicker<T> getTicker(World world, IBlockData iblockdata, TileEntityTypes<T> tileentitytypes) {
- return createTickerHelper(tileentitytypes, TileEntityTypes.HANGING_SIGN, TileEntitySign::tick);
+ return null; // Craftbukkit - remove unnecessary sign ticking
}
}

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/level/block/ChangeOverTimeBlock.java
+++ b/net/minecraft/world/level/block/ChangeOverTimeBlock.java
@@ -20,7 +20,7 @@
if (randomsource.nextFloat() < 0.05688889F) {
this.getNextState(iblockdata, worldserver, blockposition, randomsource).ifPresent((iblockdata1) -> {
- worldserver.setBlockAndUpdate(blockposition, iblockdata1);
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(worldserver, blockposition, iblockdata1); // CraftBukkit
});
}

View File

@@ -0,0 +1,84 @@
--- a/net/minecraft/world/level/block/CrafterBlock.java
+++ b/net/minecraft/world/level/block/CrafterBlock.java
@@ -40,6 +40,15 @@
import net.minecraft.world.phys.MovingObjectPositionBlock;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import net.minecraft.world.InventoryLargeChest;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.block.CrafterCraftEvent;
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
+import org.bukkit.inventory.Inventory;
+// CraftBukkit end
+
public class CrafterBlock extends BlockTileEntity {
public static final MapCodec<CrafterBlock> CODEC = simpleCodec(CrafterBlock::new);
@@ -189,6 +198,13 @@
RecipeHolder<RecipeCrafting> recipeholder = (RecipeHolder) optional.get();
ItemStack itemstack = ((RecipeCrafting) recipeholder.value()).assemble(craftinginput, worldserver.registryAccess());
+ // CraftBukkit start
+ CrafterCraftEvent event = CraftEventFactory.callCrafterCraftEvent(blockposition, worldserver, crafterblockentity, itemstack, recipeholder);
+ if (event.isCancelled()) {
+ return;
+ }
+ itemstack = CraftItemStack.asNMSCopy(event.getResult());
+ // CraftBukkit end
if (itemstack.isEmpty()) {
worldserver.levelEvent(1050, blockposition, 0);
} else {
@@ -227,7 +243,25 @@
ItemStack itemstack1 = itemstack.copy();
if (iinventory != null && (iinventory instanceof CrafterBlockEntity || itemstack.getCount() > iinventory.getMaxStackSize(itemstack))) {
+ // CraftBukkit start - InventoryMoveItemEvent
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack1);
+
+ Inventory destinationInventory;
+ // Have to special case large chests as they work oddly
+ if (iinventory instanceof InventoryLargeChest) {
+ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
+ } else {
+ destinationInventory = iinventory.getOwner().getInventory();
+ }
+
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(crafterblockentity.getOwner().getInventory(), oitemstack, destinationInventory, true);
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
+ itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
while (!itemstack1.isEmpty()) {
+ if (event.isCancelled()) {
+ break;
+ }
+ // CraftBukkit end
ItemStack itemstack2 = itemstack1.copyWithCount(1);
ItemStack itemstack3 = TileEntityHopper.addItem(crafterblockentity, iinventory, itemstack2, enumdirection.getOpposite());
@@ -238,7 +272,25 @@
itemstack1.shrink(1);
}
} else if (iinventory != null) {
+ // CraftBukkit start - InventoryMoveItemEvent
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack1);
+
+ Inventory destinationInventory;
+ // Have to special case large chests as they work oddly
+ if (iinventory instanceof InventoryLargeChest) {
+ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
+ } else {
+ destinationInventory = iinventory.getOwner().getInventory();
+ }
+
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(crafterblockentity.getOwner().getInventory(), oitemstack, destinationInventory, true);
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
+ itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
while (!itemstack1.isEmpty()) {
+ if (event.isCancelled()) {
+ break;
+ }
+ // CraftBukkit end
int i = itemstack1.getCount();
itemstack1 = TileEntityHopper.addItem(crafterblockentity, iinventory, itemstack1, enumdirection.getOpposite());

Some files were not shown because too many files have changed in this diff Show More