Add recipeBrewTime

== AT ==
public net.minecraft.world.inventory.BrewingStandMenu brewingStandData
This commit is contained in:
Tamion 2024-09-15 19:17:12 +02:00
parent cea3e6b65b
commit 8b8acbb898
6 changed files with 110 additions and 18 deletions

View file

@ -11,7 +11,7 @@
public class BrewingStandMenu extends AbstractContainerMenu { public class BrewingStandMenu extends AbstractContainerMenu {
@@ -35,21 +39,29 @@ @@ -35,29 +39,51 @@
public final ContainerData brewingStandData; public final ContainerData brewingStandData;
private final Slot ingredientSlot; private final Slot ingredientSlot;
@ -21,14 +21,16 @@
+ // CraftBukkit end + // CraftBukkit end
+ +
public BrewingStandMenu(int syncId, Inventory playerInventory) { public BrewingStandMenu(int syncId, Inventory playerInventory) {
this(syncId, playerInventory, new SimpleContainer(5), new SimpleContainerData(2)); - this(syncId, playerInventory, new SimpleContainer(5), new SimpleContainerData(2));
+ this(syncId, playerInventory, new SimpleContainer(5), new io.papermc.paper.inventory.BrewingSimpleContainerData()); // Paper - Add totalBrewTime
} }
public BrewingStandMenu(int syncId, Inventory playerInventory, Container inventory, ContainerData propertyDelegate) { public BrewingStandMenu(int syncId, Inventory playerInventory, Container inventory, ContainerData propertyDelegate) {
super(MenuType.BREWING_STAND, syncId); super(MenuType.BREWING_STAND, syncId);
+ this.player = playerInventory; // CraftBukkit + this.player = playerInventory; // CraftBukkit
checkContainerSize(inventory, 5); checkContainerSize(inventory, 5);
checkContainerDataCount(propertyDelegate, 2); - checkContainerDataCount(propertyDelegate, 2);
+ checkContainerDataCount(propertyDelegate, 3); // Paper - Add recipeBrewTime
this.brewingStand = inventory; this.brewingStand = inventory;
this.brewingStandData = propertyDelegate; this.brewingStandData = propertyDelegate;
PotionBrewing potionbrewer = playerInventory.player.level().potionBrewing(); PotionBrewing potionbrewer = playerInventory.player.level().potionBrewing();
@ -43,8 +45,23 @@
+ // Paper end - custom potion mixes + // Paper end - custom potion mixes
this.ingredientSlot = this.addSlot(new BrewingStandMenu.IngredientsSlot(potionbrewer, inventory, 3, 79, 17)); this.ingredientSlot = this.addSlot(new BrewingStandMenu.IngredientsSlot(potionbrewer, inventory, 3, 79, 17));
this.addSlot(new BrewingStandMenu.FuelSlot(inventory, 4, 17, 17)); this.addSlot(new BrewingStandMenu.FuelSlot(inventory, 4, 17, 17));
this.addDataSlots(propertyDelegate); - this.addDataSlots(propertyDelegate);
@@ -58,6 +70,7 @@ + // Paper start - Add recipeBrewTime
+ this.addDataSlots(new SimpleContainerData(2) {
+ @Override
+ public int get(final int index) {
+ if (index == 0) return 400 * propertyDelegate.get(index) / propertyDelegate.get(2);
+ return propertyDelegate.get(index);
+ }
+
+ @Override
+ public void set(final int index, final int value) {
+ propertyDelegate.set(index, value);
+ }
+ });
+ // Paper end - Add recipeBrewTime
this.addStandardInventorySlots(playerInventory, 8, 84);
}
@Override @Override
public boolean stillValid(Player player) { public boolean stillValid(Player player) {
@ -52,7 +69,7 @@
return this.brewingStand.stillValid(player); return this.brewingStand.stillValid(player);
} }
@@ -79,7 +92,7 @@ @@ -79,7 +105,7 @@
if (!this.moveItemStackTo(itemstack1, 3, 4, false)) { if (!this.moveItemStackTo(itemstack1, 3, 4, false)) {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
@ -61,7 +78,7 @@
if (!this.moveItemStackTo(itemstack1, 0, 3, false)) { if (!this.moveItemStackTo(itemstack1, 0, 3, false)) {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
@@ -128,13 +141,15 @@ @@ -128,13 +154,15 @@
private static class PotionSlot extends Slot { private static class PotionSlot extends Slot {
@ -79,7 +96,7 @@
} }
@Override @Override
@@ -153,8 +168,8 @@ @@ -153,8 +181,8 @@
super.onTake(player, stack); super.onTake(player, stack);
} }
@ -90,7 +107,7 @@
} }
@Override @Override
@@ -198,4 +213,17 @@ @@ -198,4 +226,17 @@
return BrewingStandMenu.EMPTY_SLOT_FUEL; return BrewingStandMenu.EMPTY_SLOT_FUEL;
} }
} }

View file

@ -29,7 +29,12 @@
public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer { public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer {
@@ -41,7 +54,37 @@ @@ -37,11 +50,42 @@
public static final int NUM_DATA_VALUES = 2;
private NonNullList<ItemStack> items;
public int brewTime;
+ public int recipeBrewTime = 400; // Paper - Add recipeBrewTime
private boolean[] lastPotionCount;
private Item ingredient; private Item ingredient;
public int fuel; public int fuel;
protected final ContainerData dataAccess; protected final ContainerData dataAccess;
@ -67,7 +72,39 @@
public BrewingStandBlockEntity(BlockPos pos, BlockState state) { public BrewingStandBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityType.BREWING_STAND, pos, state); super(BlockEntityType.BREWING_STAND, pos, state);
this.items = NonNullList.withSize(5, ItemStack.EMPTY); this.items = NonNullList.withSize(5, ItemStack.EMPTY);
@@ -107,8 +150,19 @@ @@ -57,6 +101,11 @@
case 1:
j = BrewingStandBlockEntity.this.fuel;
break;
+ // Paper start - Add recipeBrewTime
+ case 2:
+ j = BrewingStandBlockEntity.this.recipeBrewTime;
+ break;
+ // Paper end - Add recipeBrewTime
default:
j = 0;
}
@@ -72,13 +121,18 @@
break;
case 1:
BrewingStandBlockEntity.this.fuel = value;
+ // Paper start - Add recipeBrewTime
+ case 2:
+ BrewingStandBlockEntity.this.recipeBrewTime = value;
+ break;
+ // Paper end - Add recipeBrewTime
}
}
@Override
public int getCount() {
- return 2;
+ return 3; // Paper - Add recipeBrewTime
}
};
}
@@ -107,8 +161,19 @@
ItemStack itemstack = (ItemStack) blockEntity.items.get(4); ItemStack itemstack = (ItemStack) blockEntity.items.get(4);
if (blockEntity.fuel <= 0 && itemstack.is(ItemTags.BREWING_FUEL)) { if (blockEntity.fuel <= 0 && itemstack.is(ItemTags.BREWING_FUEL)) {
@ -89,7 +126,7 @@
setChanged(world, pos, state); setChanged(world, pos, state);
} }
@@ -116,12 +170,15 @@ @@ -116,12 +181,15 @@
boolean flag1 = blockEntity.brewTime > 0; boolean flag1 = blockEntity.brewTime > 0;
ItemStack itemstack1 = (ItemStack) blockEntity.items.get(3); ItemStack itemstack1 = (ItemStack) blockEntity.items.get(3);
@ -108,7 +145,7 @@
} else if (!flag || !itemstack1.is(blockEntity.ingredient)) { } else if (!flag || !itemstack1.is(blockEntity.ingredient)) {
blockEntity.brewTime = 0; blockEntity.brewTime = 0;
} }
@@ -129,7 +186,11 @@ @@ -129,7 +197,12 @@
setChanged(world, pos, state); setChanged(world, pos, state);
} else if (flag && blockEntity.fuel > 0) { } else if (flag && blockEntity.fuel > 0) {
--blockEntity.fuel; --blockEntity.fuel;
@ -116,12 +153,13 @@
+ // CraftBukkit start + // CraftBukkit start
+ BrewingStartEvent event = new BrewingStartEvent(CraftBlock.at(world, pos), CraftItemStack.asCraftMirror(itemstack1), 400); + BrewingStartEvent event = new BrewingStartEvent(CraftBlock.at(world, pos), CraftItemStack.asCraftMirror(itemstack1), 400);
+ world.getCraftServer().getPluginManager().callEvent(event); + world.getCraftServer().getPluginManager().callEvent(event);
+ blockEntity.brewTime = event.getTotalBrewTime(); // 400 -> event.getTotalBrewTime() + blockEntity.recipeBrewTime = event.getRecipeBrewTime(); // Paper - use recipe brew time from event
+ blockEntity.brewTime = event.getBrewingTime(); // 400 -> event.getTotalBrewTime() // Paper - use brewing time from event
+ // CraftBukkit end + // CraftBukkit end
blockEntity.ingredient = itemstack1.getItem(); blockEntity.ingredient = itemstack1.getItem();
setChanged(world, pos, state); setChanged(world, pos, state);
} }
@@ -185,14 +246,36 @@ @@ -185,14 +258,36 @@
} }
} }
@ -161,7 +199,7 @@
itemstack.shrink(1); itemstack.shrink(1);
ItemStack itemstack1 = itemstack.getItem().getCraftingRemainder(); ItemStack itemstack1 = itemstack.getItem().getCraftingRemainder();
@@ -200,12 +283,12 @@ @@ -200,12 +295,12 @@
if (itemstack.isEmpty()) { if (itemstack.isEmpty()) {
itemstack = itemstack1; itemstack = itemstack1;
} else { } else {
@ -177,7 +215,7 @@
} }
@Override @Override
@@ -231,12 +314,12 @@ @@ -231,12 +326,12 @@
@Override @Override
public boolean canPlaceItem(int slot, ItemStack stack) { public boolean canPlaceItem(int slot, ItemStack stack) {

View file

@ -0,0 +1,11 @@
package io.papermc.paper.inventory;
import net.minecraft.world.inventory.SimpleContainerData;
public class BrewingSimpleContainerData extends SimpleContainerData {
public BrewingSimpleContainerData() {
super(3);
this.set(2, 400);
}
}

View file

@ -41,6 +41,19 @@ public class CraftBrewingStand extends CraftContainer<BrewingStandBlockEntity> i
this.getSnapshot().brewTime = brewTime; this.getSnapshot().brewTime = brewTime;
} }
// Paper start - Add recipeBrewTime
@Override
public void setRecipeBrewTime(int recipeBrewTime) {
com.google.common.base.Preconditions.checkArgument(recipeBrewTime > 0, "recipeBrewTime must be positive");
this.getSnapshot().recipeBrewTime = recipeBrewTime;
}
@Override
public int getRecipeBrewTime() {
return this.getSnapshot().recipeBrewTime;
}
// Paper end - Add recipeBrewTime
@Override @Override
public int getFuelLevel() { public int getFuelLevel() {
return this.getSnapshot().fuel; return this.getSnapshot().fuel;

View file

@ -163,7 +163,7 @@ public class CraftContainer extends AbstractContainerMenu {
this.delegate = new EnchantmentMenu(windowId, bottom); this.delegate = new EnchantmentMenu(windowId, bottom);
break; break;
case BREWING: case BREWING:
this.delegate = new BrewingStandMenu(windowId, bottom, top, new SimpleContainerData(2)); this.delegate = new BrewingStandMenu(windowId, bottom, top, new io.papermc.paper.inventory.BrewingSimpleContainerData()); // Paper - Add recipeBrewTime
break; break;
case HOPPER: case HOPPER:
this.delegate = new HopperMenu(windowId, bottom, top); this.delegate = new HopperMenu(windowId, bottom, top);

View file

@ -35,4 +35,17 @@ public class CraftBrewingStandView extends CraftInventoryView<BrewingStandMenu,
Preconditions.checkArgument(brewingTicks > 0, "The given brewing ticks must be greater than 0"); Preconditions.checkArgument(brewingTicks > 0, "The given brewing ticks must be greater than 0");
this.container.setData(BrewingStandBlockEntity.DATA_BREW_TIME, brewingTicks); this.container.setData(BrewingStandBlockEntity.DATA_BREW_TIME, brewingTicks);
} }
// Paper start - Add recipeBrewTime
@Override
public void setRecipeBrewTime(int recipeBrewTime) {
com.google.common.base.Preconditions.checkArgument(recipeBrewTime > 0, "recipeBrewTime must be positive");
this.container.brewingStandData.set(2, recipeBrewTime);
}
@Override
public int getRecipeBrewTime() {
return this.container.brewingStandData.get(2);
}
// Paper end - Add recipeBrewTime
} }