Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history


# Conflicts:
#	build.gradle.kts
#	src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java
  • Loading branch information
Timongcraft committed Jan 13, 2024
2 parents cbabb05 + d83cc8c commit f3717a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.moulberry.axiom"
version = "1.5.6.1"
version = "1.5.7"
description = "Serverside component for Axiom on Paper"

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.ai.village.poi.PoiType;
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand All @@ -32,10 +34,8 @@
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -93,8 +93,6 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk

ServerPlayer player = ((CraftPlayer)bukkitPlayer).getHandle();

Action interactAction = breaking ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK;

org.bukkit.inventory.ItemStack heldItem;
if (hand == InteractionHand.MAIN_HAND) {
heldItem = bukkitPlayer.getInventory().getItemInMainHand();
Expand All @@ -107,31 +105,21 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk

BlockFace blockFace = CraftBlock.notchToBlockFace(blockHit.getDirection());

CraftWorld world = player.level().getWorld();

// Call interact event
if (new PlayerInteractEvent(bukkitPlayer, interactAction, heldItem, blockClicked, blockFace).callEvent()) {
updateBlocks(player, bukkitPlayer, world, updateNeighbors, blocks);

org.bukkit.block.Block bukkitBlock = bukkitPlayer.getWorld().getBlockAt(blockClicked.getX(), blockClicked.getY(), blockClicked.getZ());

boolean cancelled;
if (interactAction.isLeftClick()) {
cancelled = !new BlockBreakEvent(bukkitBlock, bukkitPlayer).callEvent();
} else {
cancelled = CraftEventFactory.callBlockPlaceEvent(player.serverLevel(), player, player.getUsedItemHand(), bukkitBlock.getState(), blockClicked.getX(), blockClicked.getY(), blockClicked.getZ()).isCancelled();
PlayerInteractEvent playerInteractEvent = new PlayerInteractEvent(bukkitPlayer,
breaking ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK, heldItem, blockClicked, blockFace);
if (!playerInteractEvent.callEvent()) {
if (sequenceId >= 0) {
player.connection.ackBlockChangesUpTo(sequenceId);
}

if (cancelled)
updateBlocks(player, bukkitPlayer, world, updateNeighbors, blocks);
return;
}

if (sequenceId >= 0) {
player.connection.ackBlockChangesUpTo(sequenceId);
}
}
CraftWorld world = player.level().getWorld();

BlockPlaceContext blockPlaceContext = new BlockPlaceContext(player, hand, player.getItemInHand(hand), blockHit);

private void updateBlocks(ServerPlayer player, Player bukkitPlayer, CraftWorld world, boolean updateNeighbors, Map<BlockPos, BlockState> blocks) {
// Update blocks
if (updateNeighbors) {
int count = 0;
for (Map.Entry<BlockPos, BlockState> entry : blocks.entrySet()) {
Expand Down Expand Up @@ -267,6 +255,14 @@ private void updateBlocks(ServerPlayer player, Player bukkitPlayer, CraftWorld w
}
}
}

if (!breaking) {
BlockItem.updateCustomBlockEntityTag(player.level(), player, blockPlaceContext.getClickedPos(), player.getItemInHand(hand));
}

if (sequenceId >= 0) {
player.connection.ackBlockChangesUpTo(sequenceId);
}
}

}

0 comments on commit f3717a6

Please sign in to comment.