Skip to content

Commit

Permalink
Fixed #97
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Aug 13, 2023
1 parent e3cb49f commit bde893b
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public MixinCampfireBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blo
super(blockEntityType, blockPos, blockState);
}


// Banner - fix mixin(locals = LocalCapture.CAPTURE_FAILSOFT)
private static Optional<CampfireCookingRecipe> recipe;
private static CraftItemStack source;
private static org.bukkit.inventory.ItemStack result;
private static BlockCookEvent blockCookEvent;

/**
* @author wdog5
* @reason bukkit
Expand All @@ -53,36 +60,35 @@ public static void cookTick(Level world, BlockPos blockposition, BlockState iblo
boolean flag = false;

for (int i = 0; i < tileentitycampfire.getItems().size(); ++i) {
ItemStack itemstack = (ItemStack) tileentitycampfire.getItems().get(i);
ItemStack itemstack = tileentitycampfire.getItems().get(i);

if (!itemstack.isEmpty()) {
flag = true;
int j = tileentitycampfire.cookingProgress[i]++;

if (tileentitycampfire.cookingProgress[i] >= tileentitycampfire.cookingTime[i]) {
SimpleContainer inventorysubcontainer = new SimpleContainer(new ItemStack[]{itemstack});
Optional<CampfireCookingRecipe> recipe = ((MixinCampfireBlockEntity) (Object) tileentitycampfire).quickCheck.getRecipeFor( inventorysubcontainer, world);
ItemStack itemstack1 = (ItemStack) recipe.map((recipecampfire) -> {
Container inventorysubcontainer = new SimpleContainer(itemstack);
recipe = ((MixinCampfireBlockEntity) (Object) tileentitycampfire).quickCheck.getRecipeFor( inventorysubcontainer, world);
ItemStack itemStack2 = recipe.map((recipecampfire) -> {
// Paper end
return recipecampfire.assemble(inventorysubcontainer, world.registryAccess());
}).orElse(itemstack);

if (itemstack1.isItemEnabled(world.enabledFeatures())) {
if (itemStack2.isItemEnabled(world.enabledFeatures())) {
// CraftBukkit start - fire BlockCookEvent
CraftItemStack source = CraftItemStack.asCraftMirror(itemstack);
org.bukkit.inventory.ItemStack result = CraftItemStack.asBukkitCopy(itemstack1);
source = CraftItemStack.asCraftMirror(itemstack);
result = CraftItemStack.asBukkitCopy(itemStack2);

BlockCookEvent blockCookEvent = new BlockCookEvent(CraftBlock.at(world, blockposition), source, result, (org.bukkit.inventory.CookingRecipe<?>) recipe.map(CampfireCookingRecipe::toBukkitRecipe).orElse(null)); // Paper
blockCookEvent = new BlockCookEvent(CraftBlock.at(world, blockposition), source, result, (org.bukkit.inventory.CookingRecipe<?>) recipe.map(CampfireCookingRecipe::toBukkitRecipe).orElse(null)); // Paper
world.getCraftServer().getPluginManager().callEvent(blockCookEvent);

if (blockCookEvent.isCancelled()) {
return;
}

result = blockCookEvent.getResult();
itemstack1 = CraftItemStack.asNMSCopy(result);
itemStack2 = CraftItemStack.asNMSCopy(result);
// CraftBukkit end
Containers.dropItemStack(world, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack1);
Containers.dropItemStack(world, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemStack2);
tileentitycampfire.getItems().set(i, ItemStack.EMPTY);
world.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3);
world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.Context.of(iblockdata));
Expand Down

0 comments on commit bde893b

Please sign in to comment.