-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Original code by 404Setup <153366651+404Setup@users.noreply.github.com> You can find the original code on https://github.com/LevelTranic/LevelBukkit try fix: PaperMC/Folia#217 It seems possible that this fix will not work in this core This fix may work, but its implementation is not elegant, so it will not be submitted upstream
- Loading branch information
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
patches/server/0031-The-anvil-becomes-a-drop-at-Y0.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: 404Setup <153366651+404Setup@users.noreply.github.com> | ||
Date: Sun, 9 Jun 2024 21:03:51 +0800 | ||
Subject: [PATCH] The anvil becomes a drop at Y0 | ||
|
||
Original code by 404Setup <153366651+404Setup@users.noreply.github.com> | ||
You can find the original code on https://github.com/LevelTranic/LevelBukkit | ||
|
||
try fix: https://github.com/PaperMC/Folia/issues/217 | ||
|
||
This fix may work, but its implementation is not elegant, so it will not be submitted upstream | ||
|
||
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java | ||
index d504d10fbe45dfe3f2f3d08d2473df6cd18f6dcf..0fba97efe0d061107eee870ad1f8775faf6759f7 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java | ||
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java | ||
@@ -1,7 +1,6 @@ | ||
package net.minecraft.world.entity.item; | ||
|
||
import com.mojang.logging.LogUtils; | ||
-import java.util.Iterator; | ||
import java.util.function.Predicate; | ||
import javax.annotation.Nullable; | ||
import net.minecraft.CrashReportCategory; | ||
@@ -18,6 +17,7 @@ import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; | ||
import net.minecraft.network.syncher.EntityDataAccessor; | ||
import net.minecraft.network.syncher.EntityDataSerializers; | ||
import net.minecraft.network.syncher.SynchedEntityData; | ||
+import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.tags.BlockTags; | ||
import net.minecraft.tags.FluidTags; | ||
@@ -28,7 +28,6 @@ import net.minecraft.world.entity.EntitySelector; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.MoverType; | ||
import net.minecraft.world.item.ItemStack; | ||
-import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.item.context.DirectionalPlaceContext; | ||
import net.minecraft.world.level.ClipContext; | ||
import net.minecraft.world.level.GameRules; | ||
@@ -182,12 +181,24 @@ public class FallingBlockEntity extends Entity { | ||
} else { | ||
BlockState iblockdata = this.level().getBlockState(blockposition); | ||
|
||
+ boolean isAnvil = (iblockdata.getBlock().equals(Blocks.ANVIL) || | ||
+ iblockdata.getBlock().equals(Blocks.CHIPPED_ANVIL) || | ||
+ iblockdata.getBlock().equals(Blocks.DAMAGED_ANVIL)); | ||
+ | ||
+ boolean isAllowedPos = (isAnvil && (blockposition.getY() == 0 || blockposition.getY() == -1)); | ||
+ | ||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.7D, -0.5D, 0.7D)); | ||
if (!iblockdata.is(Blocks.MOVING_PISTON)) { | ||
if (!this.cancelDrop) { | ||
- boolean flag2 = iblockdata.canBeReplaced((BlockPlaceContext) (new DirectionalPlaceContext(this.level(), blockposition, Direction.DOWN, ItemStack.EMPTY, Direction.UP))); | ||
+ // LevelBukkit start: try fix: https://github.com/PaperMC/Folia/issues/217 | ||
+ if (one.tranic.levelpowered.vine.config.VineConfig.LevelBukkit.getTryFixAnvilDrop() && isAllowedPos) | ||
+ iblockdata = Blocks.VOID_AIR.defaultBlockState(); | ||
+ boolean flag2 = iblockdata.canBeReplaced(new DirectionalPlaceContext(this.level(), blockposition, Direction.DOWN, ItemStack.EMPTY, Direction.UP)); | ||
boolean flag3 = FallingBlock.isFree(this.level().getBlockState(blockposition.below())) && (!flag || !flag1); | ||
boolean flag4 = this.blockState.canSurvive(this.level(), blockposition) && !flag3; | ||
+ if (isAllowedPos && one.tranic.levelpowered.vine.config.VineConfig.LevelBukkit.getTryFixAnvilDropLogger()) | ||
+ MinecraftServer.LOGGER.info("BlockState at {}: {}, Can be replaced: {}", blockposition, iblockdata, flag2); | ||
+ // LevelBukkit end: try fix: https://github.com/PaperMC/Folia/issues/217 | ||
|
||
if (flag2 && flag4) { | ||
if (this.blockState.hasProperty(BlockStateProperties.WATERLOGGED) && this.level().getFluidState(blockposition).getType() == Fluids.WATER) { | ||
@@ -212,11 +223,8 @@ public class FallingBlockEntity extends Entity { | ||
|
||
if (tileentity != null) { | ||
CompoundTag nbttagcompound = tileentity.saveWithoutMetadata(this.level().registryAccess()); | ||
- Iterator iterator = this.blockData.getAllKeys().iterator(); | ||
- | ||
- while (iterator.hasNext()) { | ||
- String s = (String) iterator.next(); | ||
|
||
+ for (String s : this.blockData.getAllKeys()) { | ||
nbttagcompound.put(s, this.blockData.get(s).copy()); | ||
} | ||
|
||
@@ -229,12 +237,18 @@ public class FallingBlockEntity extends Entity { | ||
tileentity.setChanged(); | ||
} | ||
} | ||
+ // LevelBukkit start: try fix: https://github.com/PaperMC/Folia/issues/217 | ||
} else if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { | ||
+ if (isAllowedPos && one.tranic.levelpowered.vine.config.VineConfig.LevelBukkit.getTryFixAnvilDropLogger()) | ||
+ MinecraftServer.LOGGER.info("Dropping at y=0 or other position, blockState: {}, position: {}, with setBlock is false", this.blockState, blockposition); | ||
this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause | ||
this.callOnBrokenAfterFall(block, blockposition); | ||
this.spawnAtLocation((ItemLike) block); | ||
} | ||
} else { | ||
+ if (isAllowedPos && one.tranic.levelpowered.vine.config.VineConfig.LevelBukkit.getTryFixAnvilDropLogger()) | ||
+ MinecraftServer.LOGGER.info("Dropping at y=0 or other position, blockState: {}, position: {}", this.blockState, blockposition); | ||
+ // LevelBukkit end: try fix: https://github.com/PaperMC/Folia/issues/217 | ||
this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause | ||
if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { | ||
this.callOnBrokenAfterFall(block, blockposition); | ||
@@ -347,9 +361,9 @@ public class FallingBlockEntity extends Entity { | ||
} | ||
|
||
// Paper start - Expand FallingBlock API | ||
- if (nbt.contains("Paper.AutoExpire")) { | ||
+ if (nbt.contains("Paper.AutoExpire")) { | ||
this.autoExpire = nbt.getBoolean("Paper.AutoExpire"); | ||
- } | ||
+ } | ||
// Paper end - Expand FallingBlock API | ||
} | ||
|
9014e24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trust me, this is not a good idea