mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-01 12:41:50 +01:00
c5a10665b8
Spigot still maintains some partial implementation of "tick skipping", a practice in which the MinecraftServer.currentTick field is updated not by an increment of one per actual tick, but instead set to System.currentTimeMillis() / 50. This behaviour means that the tracked tick may "skip" a tick value in case a previous tick took more than the expected 50ms. To compensate for this in important paths, spigot/craftbukkit implements "wall-time". Instead of incrementing/decrementing ticks on block entities/entities by one for each call to their tick() method, they instead increment/decrement important values, like an ItemEntity's age or pickupDelay, by the difference of `currentTick - lastTick`, where `lastTick` is the value of `currentTick` during the last tick() call. These "fixes" however do not play nicely with minecraft's simulation distance as entities/block entities implementing the above behaviour would "catch up" their values when moving from a non-ticking chunk to a ticking one as their `lastTick` value remains stuck on the last tick in a ticking chunk and hence lead to a large "catch up" once ticked again. Paper completely removes the "tick skipping" behaviour (See patch "Further-improve-server-tick-loop"), making the above precautions completely unnecessary, which also rids paper of the previous described incompatibility with non-ticking chunks.
52 lines
3.1 KiB
Diff
52 lines
3.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Fri, 27 Nov 2020 17:14:27 -0800
|
|
Subject: [PATCH] Add PlayerStonecutterRecipeSelectEvent
|
|
|
|
Co-Authored-By: MiniDigger <admin@benndorf.dev>
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java b/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java
|
|
index 5b4f03128499b0c1a4b8c5f5ccd17e4bdb391e81..37e75c02c374314372630f4bda0b92519809f2a4 100644
|
|
--- a/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java
|
|
+++ b/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java
|
|
@@ -64,7 +64,7 @@ public class StonecutterMenu extends AbstractContainerMenu {
|
|
|
|
public StonecutterMenu(int syncId, Inventory playerInventory, final ContainerLevelAccess context) {
|
|
super(MenuType.STONECUTTER, syncId);
|
|
- this.selectedRecipeIndex = DataSlot.standalone();
|
|
+ this.selectedRecipeIndex = DataSlot.shared(new int[1], 0); // Paper - Add PlayerStonecutterRecipeSelectEvent
|
|
this.recipes = Lists.newArrayList();
|
|
this.input = ItemStack.EMPTY;
|
|
this.slotUpdateListener = () -> {
|
|
@@ -162,7 +162,30 @@ public class StonecutterMenu extends AbstractContainerMenu {
|
|
@Override
|
|
public boolean clickMenuButton(net.minecraft.world.entity.player.Player player, int id) {
|
|
if (this.isValidRecipeIndex(id)) {
|
|
- this.selectedRecipeIndex.set(id);
|
|
+ // Paper start - Add PlayerStonecutterRecipeSelectEvent
|
|
+ int recipeIndex = id;
|
|
+ this.selectedRecipeIndex.set(recipeIndex);
|
|
+ this.selectedRecipeIndex.checkAndClearUpdateFlag(); // mark as changed
|
|
+ if (this.isValidRecipeIndex(id)) {
|
|
+ io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent event = new io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent((Player) player.getBukkitEntity(), (org.bukkit.inventory.StonecutterInventory) getBukkitView().getTopInventory(), (org.bukkit.inventory.StonecuttingRecipe) this.getRecipes().get(id).toBukkitRecipe());
|
|
+ if (!event.callEvent()) {
|
|
+ player.containerMenu.sendAllDataToRemote();
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ net.minecraft.resources.ResourceLocation key = org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getStonecuttingRecipe().getKey());
|
|
+ if (!this.getRecipes().get(recipeIndex).id().equals(key)) { // If the recipe did NOT stay the same
|
|
+ for (int newRecipeIndex = 0; newRecipeIndex < this.getRecipes().size(); newRecipeIndex++) {
|
|
+ if (this.getRecipes().get(newRecipeIndex).id().equals(key)) {
|
|
+ recipeIndex = newRecipeIndex;
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ player.containerMenu.sendAllDataToRemote();
|
|
+ this.selectedRecipeIndex.set(recipeIndex); // set new index, so that listeners can read it
|
|
+ // Paper end - Add PlayerStonecutterRecipeSelectEvent
|
|
this.setupResultSlot();
|
|
}
|
|
|