#1450: Add CrafterCraftEvent
By: ploppyperson <nathat890@outlook.com> Also-by: md_5 <git@md-5.net>
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user