mirror of
https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git
synced 2024-11-26 00:26:14 +00:00
238 lines
12 KiB
Diff
238 lines
12 KiB
Diff
--- a/net/minecraft/world/level/block/entity/TileEntityFurnace.java
|
|
+++ b/net/minecraft/world/level/block/entity/TileEntityFurnace.java
|
|
@@ -42,6 +42,21 @@
|
|
import net.minecraft.world.level.block.state.IBlockData;
|
|
import net.minecraft.world.phys.Vec3D;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.craftbukkit.block.CraftBlock;
|
|
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemType;
|
|
+import org.bukkit.entity.HumanEntity;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.event.block.BlockExpEvent;
|
|
+import org.bukkit.event.inventory.FurnaceBurnEvent;
|
|
+import org.bukkit.event.inventory.FurnaceExtractEvent;
|
|
+import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
|
+import org.bukkit.event.inventory.FurnaceStartSmeltEvent;
|
|
+import org.bukkit.inventory.CookingRecipe;
|
|
+// CraftBukkit end
|
|
+
|
|
public abstract class TileEntityFurnace extends TileEntityContainer implements IWorldInventory, RecipeCraftingHolder, AutoRecipeOutput {
|
|
|
|
protected static final int SLOT_INPUT = 0;
|
|
@@ -112,9 +127,39 @@
|
|
}
|
|
};
|
|
this.recipesUsed = new Reference2IntOpenHashMap();
|
|
- this.quickCheck = CraftingManager.createCheck(recipes);
|
|
+ this.quickCheck = CraftingManager.createCheck((Recipes<RecipeCooking>) recipes); // CraftBukkit - decompile error // Eclipse fail
|
|
+ }
|
|
+
|
|
+ // CraftBukkit start - add fields and methods
|
|
+ private int maxStack = MAX_STACK;
|
|
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
|
+
|
|
+ public List<ItemStack> getContents() {
|
|
+ return this.items;
|
|
+ }
|
|
+
|
|
+ public void onOpen(CraftHumanEntity who) {
|
|
+ transaction.add(who);
|
|
+ }
|
|
+
|
|
+ public void onClose(CraftHumanEntity who) {
|
|
+ transaction.remove(who);
|
|
+ }
|
|
+
|
|
+ public List<HumanEntity> getViewers() {
|
|
+ return transaction;
|
|
}
|
|
|
|
+ @Override
|
|
+ public int getMaxStackSize() {
|
|
+ return maxStack;
|
|
+ }
|
|
+
|
|
+ public void setMaxStackSize(int size) {
|
|
+ maxStack = size;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
private boolean isLit() {
|
|
return this.litTime > 0;
|
|
}
|
|
@@ -180,7 +225,7 @@
|
|
RecipeHolder recipeholder;
|
|
|
|
if (flag2) {
|
|
- recipeholder = (RecipeHolder) tileentityfurnace.quickCheck.getRecipeFor(singlerecipeinput, worldserver).orElse((Object) null);
|
|
+ recipeholder = (RecipeHolder) tileentityfurnace.quickCheck.getRecipeFor(singlerecipeinput, worldserver).orElse(null); // CraftBukkit - decompile error
|
|
} else {
|
|
recipeholder = null;
|
|
}
|
|
@@ -188,9 +233,20 @@
|
|
int i = tileentityfurnace.getMaxStackSize();
|
|
|
|
if (!tileentityfurnace.isLit() && canBurn(worldserver.registryAccess(), recipeholder, singlerecipeinput, tileentityfurnace.items, i)) {
|
|
- tileentityfurnace.litTime = tileentityfurnace.getBurnDuration(worldserver.fuelValues(), itemstack);
|
|
+ // CraftBukkit start
|
|
+ CraftItemStack fuel = CraftItemStack.asCraftMirror(itemstack);
|
|
+
|
|
+ FurnaceBurnEvent furnaceBurnEvent = new FurnaceBurnEvent(CraftBlock.at(worldserver, blockposition), fuel, tileentityfurnace.getBurnDuration(worldserver.fuelValues(), itemstack));
|
|
+ worldserver.getCraftServer().getPluginManager().callEvent(furnaceBurnEvent);
|
|
+
|
|
+ if (furnaceBurnEvent.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ tileentityfurnace.litTime = furnaceBurnEvent.getBurnTime();
|
|
tileentityfurnace.litDuration = tileentityfurnace.litTime;
|
|
- if (tileentityfurnace.isLit()) {
|
|
+ if (tileentityfurnace.isLit() && furnaceBurnEvent.isBurning()) {
|
|
+ // CraftBukkit end
|
|
flag1 = true;
|
|
if (flag3) {
|
|
Item item = itemstack.getItem();
|
|
@@ -204,11 +260,23 @@
|
|
}
|
|
|
|
if (tileentityfurnace.isLit() && canBurn(worldserver.registryAccess(), recipeholder, singlerecipeinput, tileentityfurnace.items, i)) {
|
|
+ // CraftBukkit start
|
|
+ if (recipeholder != null && tileentityfurnace.cookingProgress == 0) {
|
|
+ CraftItemStack source = CraftItemStack.asCraftMirror(tileentityfurnace.items.get(0));
|
|
+ CookingRecipe<?> recipe = (CookingRecipe<?>) recipeholder.toBukkitRecipe();
|
|
+
|
|
+ FurnaceStartSmeltEvent event = new FurnaceStartSmeltEvent(CraftBlock.at(worldserver, blockposition), source, recipe);
|
|
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ tileentityfurnace.cookingTotalTime = event.getTotalCookTime();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
++tileentityfurnace.cookingProgress;
|
|
if (tileentityfurnace.cookingProgress == tileentityfurnace.cookingTotalTime) {
|
|
tileentityfurnace.cookingProgress = 0;
|
|
tileentityfurnace.cookingTotalTime = getTotalCookTime(worldserver, tileentityfurnace);
|
|
- if (burn(worldserver.registryAccess(), recipeholder, singlerecipeinput, tileentityfurnace.items, i)) {
|
|
+ if (burn(tileentityfurnace.level, tileentityfurnace.worldPosition, worldserver.registryAccess(), recipeholder, singlerecipeinput, tileentityfurnace.items, i)) { // CraftBukkit
|
|
tileentityfurnace.setRecipeUsed(recipeholder);
|
|
}
|
|
|
|
@@ -247,17 +315,44 @@
|
|
}
|
|
}
|
|
|
|
- private static boolean burn(IRegistryCustom iregistrycustom, @Nullable RecipeHolder<? extends RecipeCooking> recipeholder, SingleRecipeInput singlerecipeinput, NonNullList<ItemStack> nonnulllist, int i) {
|
|
+ private static boolean burn(World world, BlockPosition blockposition, IRegistryCustom iregistrycustom, @Nullable RecipeHolder<? extends RecipeCooking> recipeholder, SingleRecipeInput singlerecipeinput, NonNullList<ItemStack> nonnulllist, int i) { // CraftBukkit
|
|
if (recipeholder != null && canBurn(iregistrycustom, recipeholder, singlerecipeinput, nonnulllist, i)) {
|
|
ItemStack itemstack = (ItemStack) nonnulllist.get(0);
|
|
ItemStack itemstack1 = ((RecipeCooking) recipeholder.value()).assemble(singlerecipeinput, iregistrycustom);
|
|
ItemStack itemstack2 = (ItemStack) nonnulllist.get(2);
|
|
|
|
+ // CraftBukkit start - fire FurnaceSmeltEvent
|
|
+ CraftItemStack source = CraftItemStack.asCraftMirror(itemstack);
|
|
+ org.bukkit.inventory.ItemStack result = CraftItemStack.asBukkitCopy(itemstack1);
|
|
+
|
|
+ FurnaceSmeltEvent furnaceSmeltEvent = new FurnaceSmeltEvent(CraftBlock.at(world, blockposition), source, result);
|
|
+ world.getCraftServer().getPluginManager().callEvent(furnaceSmeltEvent);
|
|
+
|
|
+ if (furnaceSmeltEvent.isCancelled()) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ result = furnaceSmeltEvent.getResult();
|
|
+ itemstack1 = CraftItemStack.asNMSCopy(result);
|
|
+
|
|
+ if (!itemstack1.isEmpty()) {
|
|
+ if (itemstack2.isEmpty()) {
|
|
+ nonnulllist.set(2, itemstack1.copy());
|
|
+ } else if (CraftItemStack.asCraftMirror(itemstack2).isSimilar(result)) {
|
|
+ itemstack2.grow(itemstack1.getCount());
|
|
+ } else {
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /*
|
|
if (itemstack2.isEmpty()) {
|
|
nonnulllist.set(2, itemstack1.copy());
|
|
} else if (ItemStack.isSameItemSameComponents(itemstack2, itemstack1)) {
|
|
itemstack2.grow(1);
|
|
}
|
|
+ */
|
|
+ // CraftBukkit end
|
|
|
|
if (itemstack.is(Blocks.WET_SPONGE.asItem()) && !((ItemStack) nonnulllist.get(1)).isEmpty() && ((ItemStack) nonnulllist.get(1)).is(Items.BUCKET)) {
|
|
nonnulllist.set(1, new ItemStack(Items.WATER_BUCKET));
|
|
@@ -275,6 +370,7 @@
|
|
}
|
|
|
|
private static int getTotalCookTime(WorldServer worldserver, TileEntityFurnace tileentityfurnace) {
|
|
+ if (worldserver == null) return 200; // CraftBukkit - SPIGOT-4302
|
|
SingleRecipeInput singlerecipeinput = new SingleRecipeInput(tileentityfurnace.getItem(0));
|
|
|
|
return (Integer) tileentityfurnace.quickCheck.getRecipeFor(singlerecipeinput, worldserver).map((recipeholder) -> {
|
|
@@ -365,8 +461,8 @@
|
|
@Override
|
|
public void awardUsedRecipes(EntityHuman entityhuman, List<ItemStack> list) {}
|
|
|
|
- public void awardUsedRecipesAndPopExperience(EntityPlayer entityplayer) {
|
|
- List<RecipeHolder<?>> list = this.getRecipesToAwardAndPopExperience(entityplayer.serverLevel(), entityplayer.position());
|
|
+ public void awardUsedRecipesAndPopExperience(EntityPlayer entityplayer, ItemStack itemstack, int amount) { // CraftBukkit
|
|
+ List<RecipeHolder<?>> list = this.getRecipesToAwardAndPopExperience(entityplayer.serverLevel(), entityplayer.position(), this.worldPosition, entityplayer, itemstack, amount); // CraftBukkit
|
|
|
|
entityplayer.awardRecipes(list);
|
|
Iterator iterator = list.iterator();
|
|
@@ -383,22 +479,28 @@
|
|
}
|
|
|
|
public List<RecipeHolder<?>> getRecipesToAwardAndPopExperience(WorldServer worldserver, Vec3D vec3d) {
|
|
+ // CraftBukkit start
|
|
+ return this.getRecipesToAwardAndPopExperience(worldserver, vec3d, this.worldPosition, null, null, 0);
|
|
+ }
|
|
+
|
|
+ public List<RecipeHolder<?>> getRecipesToAwardAndPopExperience(WorldServer worldserver, Vec3D vec3d, BlockPosition blockposition, EntityPlayer entityplayer, ItemStack itemstack, int amount) {
|
|
+ // CraftBukkit end
|
|
List<RecipeHolder<?>> list = Lists.newArrayList();
|
|
ObjectIterator objectiterator = this.recipesUsed.reference2IntEntrySet().iterator();
|
|
|
|
while (objectiterator.hasNext()) {
|
|
Entry<ResourceKey<IRecipe<?>>> entry = (Entry) objectiterator.next();
|
|
|
|
- worldserver.recipeAccess().byKey((ResourceKey) entry.getKey()).ifPresent((recipeholder) -> {
|
|
+ worldserver.recipeAccess().byKey(entry.getKey()).ifPresent((recipeholder) -> { // CraftBukkit - decompile error
|
|
list.add(recipeholder);
|
|
- createExperience(worldserver, vec3d, entry.getIntValue(), ((RecipeCooking) recipeholder.value()).experience());
|
|
+ createExperience(worldserver, vec3d, entry.getIntValue(), ((RecipeCooking) recipeholder.value()).experience(), blockposition, entityplayer, itemstack, amount); // CraftBukkit
|
|
});
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
- private static void createExperience(WorldServer worldserver, Vec3D vec3d, int i, float f) {
|
|
+ private static void createExperience(WorldServer worldserver, Vec3D vec3d, int i, float f, BlockPosition blockposition, EntityHuman entityhuman, ItemStack itemstack, int amount) { // CraftBukkit
|
|
int j = MathHelper.floor((float) i * f);
|
|
float f1 = MathHelper.frac((float) i * f);
|
|
|
|
@@ -406,6 +508,17 @@
|
|
++j;
|
|
}
|
|
|
|
+ // CraftBukkit start - fire FurnaceExtractEvent / BlockExpEvent
|
|
+ BlockExpEvent event;
|
|
+ if (amount != 0) {
|
|
+ event = new FurnaceExtractEvent((Player) entityhuman.getBukkitEntity(), CraftBlock.at(worldserver, blockposition), CraftItemType.minecraftToBukkit(itemstack.getItem()), amount, j);
|
|
+ } else {
|
|
+ event = new BlockExpEvent(CraftBlock.at(worldserver, blockposition), j);
|
|
+ }
|
|
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
|
|
+ j = event.getExpToDrop();
|
|
+ // CraftBukkit end
|
|
+
|
|
EntityExperienceOrb.award(worldserver, vec3d, j);
|
|
}
|
|
|