mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
#1450: Add CrafterCraftEvent
By: ploppyperson <nathat890@outlook.com> Also-by: md_5 <git@md-5.net>
This commit is contained in:
parent
8317d4c799
commit
9a7508c3ab
4 changed files with 51 additions and 22 deletions
|
@ -1,18 +1,22 @@
|
|||
--- a/net/minecraft/world/item/crafting/IRecipeComplex.java
|
||||
+++ b/net/minecraft/world/item/crafting/IRecipeComplex.java
|
||||
@@ -3,6 +3,11 @@
|
||||
@@ -3,6 +3,15 @@
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import net.minecraft.core.IRegistryCustom;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftComplexRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public abstract class IRecipeComplex implements RecipeCrafting {
|
||||
|
||||
private final CraftingBookCategory category;
|
||||
@@ -25,4 +30,11 @@
|
||||
@@ -25,4 +34,17 @@
|
||||
public CraftingBookCategory category() {
|
||||
return this.category;
|
||||
}
|
||||
|
@ -20,7 +24,13 @@
|
|||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ return new org.bukkit.craftbukkit.inventory.CraftComplexRecipe(id, this);
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(getResultItem(IRegistryCustom.EMPTY));
|
||||
+
|
||||
+ CraftComplexRecipe recipe = new CraftComplexRecipe(id, result, this);
|
||||
+ recipe.setGroup(this.getGroup());
|
||||
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
|
||||
+
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
--- a/net/minecraft/world/level/block/CrafterBlock.java
|
||||
+++ b/net/minecraft/world/level/block/CrafterBlock.java
|
||||
@@ -39,6 +39,13 @@
|
||||
@@ -39,6 +39,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
|
||||
|
@ -14,7 +16,21 @@
|
|||
public class CrafterBlock extends BlockTileEntity {
|
||||
|
||||
public static final MapCodec<CrafterBlock> CODEC = simpleCodec(CrafterBlock::new);
|
||||
@@ -226,7 +233,25 @@
|
||||
@@ -188,6 +197,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 {
|
||||
@@ -226,7 +242,25 @@
|
||||
ItemStack itemstack1 = itemstack.copy();
|
||||
|
||||
if (iinventory != null && (iinventory instanceof CrafterBlockEntity || itemstack.getCount() > iinventory.getMaxStackSize(itemstack))) {
|
||||
|
@ -40,7 +56,7 @@
|
|||
ItemStack itemstack2 = itemstack1.copyWithCount(1);
|
||||
ItemStack itemstack3 = TileEntityHopper.addItem(crafterblockentity, iinventory, itemstack2, enumdirection.getOpposite());
|
||||
|
||||
@@ -237,7 +262,25 @@
|
||||
@@ -237,7 +271,25 @@
|
||||
itemstack1.shrink(1);
|
||||
}
|
||||
} else if (iinventory != null) {
|
||||
|
|
|
@ -61,6 +61,8 @@ import net.minecraft.world.inventory.RecipeBookType;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.context.ItemActionContext;
|
||||
import net.minecraft.world.item.crafting.RecipeCrafting;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import net.minecraft.world.level.ChunkCoordIntPair;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.GeneratorAccess;
|
||||
|
@ -156,6 +158,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
|||
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||
import org.bukkit.event.block.BlockShearEntityEvent;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
import org.bukkit.event.block.CrafterCraftEvent;
|
||||
import org.bukkit.event.block.EntityBlockFormEvent;
|
||||
import org.bukkit.event.block.FluidLevelChangeEvent;
|
||||
import org.bukkit.event.block.MoistureChangeEvent;
|
||||
|
@ -256,6 +259,7 @@ import org.bukkit.event.weather.LightningStrikeEvent;
|
|||
import org.bukkit.event.world.EntitiesLoadEvent;
|
||||
import org.bukkit.event.world.EntitiesUnloadEvent;
|
||||
import org.bukkit.event.world.LootGenerateEvent;
|
||||
import org.bukkit.inventory.CraftingRecipe;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
@ -1286,6 +1290,16 @@ public class CraftEventFactory {
|
|||
return CraftItemStack.asNMSCopy(bitem);
|
||||
}
|
||||
|
||||
public static CrafterCraftEvent callCrafterCraftEvent(BlockPosition pos, World world, InventoryCrafting inventoryCrafting, ItemStack result, RecipeHolder<RecipeCrafting> holder) {
|
||||
CraftBlock block = CraftBlock.at(world, pos);
|
||||
CraftItemStack itemStack = CraftItemStack.asCraftMirror(result);
|
||||
CraftingRecipe craftingRecipe = (CraftingRecipe) holder.toBukkitRecipe();
|
||||
|
||||
CrafterCraftEvent crafterCraftEvent = new CrafterCraftEvent(block, craftingRecipe, itemStack);
|
||||
Bukkit.getPluginManager().callEvent(crafterCraftEvent);
|
||||
return crafterCraftEvent;
|
||||
}
|
||||
|
||||
public static ProjectileLaunchEvent callProjectileLaunchEvent(Entity entity) {
|
||||
Projectile bukkitEntity = (Projectile) entity.getBukkitEntity();
|
||||
ProjectileLaunchEvent event = new ProjectileLaunchEvent(bukkitEntity);
|
||||
|
|
|
@ -1,36 +1,25 @@
|
|||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import net.minecraft.core.IRegistryCustom;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.crafting.IRecipeComplex;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.inventory.ComplexRecipe;
|
||||
import org.bukkit.inventory.CraftingRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CraftComplexRecipe implements CraftRecipe, ComplexRecipe {
|
||||
public class CraftComplexRecipe extends CraftingRecipe implements CraftRecipe, ComplexRecipe {
|
||||
|
||||
private final NamespacedKey key;
|
||||
private final IRecipeComplex recipe;
|
||||
|
||||
public CraftComplexRecipe(NamespacedKey key, IRecipeComplex recipe) {
|
||||
this.key = key;
|
||||
public CraftComplexRecipe(NamespacedKey key, ItemStack result, IRecipeComplex recipe) {
|
||||
super(key, result);
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResult() {
|
||||
return CraftItemStack.asCraftMirror(recipe.getResultItem(IRegistryCustom.EMPTY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToCraftingManager() {
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(key), recipe));
|
||||
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), recipe));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue