Skip to content

Commit

Permalink
feat: brewing stand
Browse files Browse the repository at this point in the history
refactor: recipe
  • Loading branch information
IWareQ committed Jan 12, 2025
1 parent 9bd3b34 commit 07a8312
Show file tree
Hide file tree
Showing 42 changed files with 684 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.allaymc.api.block.interfaces;

import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.component.BlockEntityHolderComponent;
import org.allaymc.api.blockentity.interfaces.BlockEntityBrewingStand;

public interface BlockBrewingStandBehavior extends BlockBehavior {
public interface BlockBrewingStandBehavior extends BlockBehavior, BlockEntityHolderComponent<BlockEntityBrewingStand> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.allaymc.api.blockentity.component;

/**
* @author IWareQ
*/
public interface BlockEntityBrewingStandBaseComponent extends BlockEntityBaseComponent {
int getBrewTime();

void setBrewTime(int time);

int getFuelAmount();

void setFuelAmount(int amount);

int getFuelTotal();

void setFuelTotal(int amount);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.allaymc.api.blockentity.interfaces;

import org.allaymc.api.blockentity.BlockEntity;
import org.allaymc.api.blockentity.component.BlockEntityBrewingStandBaseComponent;

/**
* @author IWareQ
*/
public interface BlockEntityBrewingStand extends BlockEntity, BlockEntityBrewingStandBaseComponent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public final class BlockEntityTypes {
public static BlockEntityType<BlockEntityEnchantTable> ENCHANT_TABLE;
public static BlockEntityType<BlockEntityJukebox> JUKEBOX;
public static BlockEntityType<BlockEntityBeacon> BEACON;
public static BlockEntityType<BlockEntityBrewingStand> BREWING_STAND;
}
42 changes: 34 additions & 8 deletions api/src/main/java/org/allaymc/api/container/FullContainerType.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ public record FullContainerType<T extends Container>(
.mapNetworkSlotIndex(27, BeaconContainer.BEACON_PAYMENT_SLOT)
.build();

public static final FullContainerType<BrewingStandContainer> BREWING_STAND = builder()
.id(ContainerType.BREWING_STAND)
.size(5)
.mapSlotToType(BrewingStandContainer.REAGENT_SLOT, ContainerSlotType.BREWING_INPUT)
.mapRangedSlotToType(1, 3, ContainerSlotType.BREWING_RESULT)
.mapSlotToType(BrewingStandContainer.FUEL_SLOT, ContainerSlotType.BREWING_FUEL)
.build();

public FullContainerType(int id, ContainerSlotType[] slotTypeTable, Set<ContainerSlotType> heldSlotTypes, BiMap<Integer, Integer> networkSlotIndexMapper) {
this.id = id;
this.slotTypeTable = slotTypeTable;
Expand Down Expand Up @@ -179,25 +187,38 @@ public FullContainerTypeBuilder size(int size) {
}

public FullContainerTypeBuilder mapRangedSlotToType(int left, int right, ContainerSlotType type) {
if (slotTypeTable == null) throw new IllegalStateException("The size must be set firstly!");
if (left > right) throw new IllegalArgumentException("Left must smaller than right!");
if (left > slotTypeTable.length || right > slotTypeTable.length)
if (slotTypeTable == null) {
throw new IllegalStateException("The size must be set firstly!");
}
if (left > right) {
throw new IllegalArgumentException("Left must smaller than right!");
}
if (left > slotTypeTable.length || right > slotTypeTable.length) {
throw new IllegalArgumentException("Left or right bigger than size!");
}

heldSlotTypes.add(type);
for (int i = left; i <= right; i++) slotTypeTable[i] = type;
for (int i = left; i <= right; i++) {
slotTypeTable[i] = type;
}
return this;
}

public FullContainerTypeBuilder mapAllSlotToType(ContainerSlotType type) {
if (slotTypeTable == null) throw new IllegalStateException("The size must be set firstly!");
if (slotTypeTable == null) {
throw new IllegalStateException("The size must be set firstly!");
}

heldSlotTypes.add(type);
Arrays.fill(slotTypeTable, type);
return this;
}

public FullContainerTypeBuilder mapSlotToType(int slot, ContainerSlotType type) {
if (slotTypeTable == null) throw new IllegalStateException("The size must be set firstly!");
if (slotTypeTable == null) {
throw new IllegalStateException("The size must be set firstly!");
}

heldSlotTypes.add(type);
slotTypeTable[slot] = type;
return this;
Expand All @@ -214,8 +235,13 @@ public FullContainerTypeBuilder mapNetworkSlotIndex(int networkSlotIndex, int sl
}

public FullContainerTypeBuilder mapRangedNetworkSlotIndex(int left, int right, int slot) {
if (left > right) throw new IllegalArgumentException("Left must smaller than right!");
for (int i = left, j = 0; i <= right; i++, j++) networkSlotIndexMapper.put(i, slot + j);
if (left > right) {
throw new IllegalArgumentException("Left must smaller than right!");
}

for (int i = left, j = 0; i <= right; i++, j++) {
networkSlotIndexMapper.put(i, slot + j);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.allaymc.api.container.impl;

import org.allaymc.api.container.FullContainerType;
import org.allaymc.api.item.ItemStack;
import org.jetbrains.annotations.Range;

/**
* @author IWareQ
*/
public class BrewingStandContainer extends BlockContainer {
public static final int REAGENT_SLOT = 0;
public static final int FUEL_SLOT = 4;

public BrewingStandContainer() {
super(FullContainerType.BREWING_STAND);
}

public ItemStack getReagent() {
return getItemStack(REAGENT_SLOT);
}

public void setReagent(ItemStack itemStack) {
setItemStack(REAGENT_SLOT, itemStack);
}

public ItemStack getFuel() {
return getItemStack(FUEL_SLOT);
}

public void setFuel(ItemStack itemStack) {
setItemStack(FUEL_SLOT, itemStack);
}

public ItemStack getResult(@Range(from = 0, to = 2) int slot) {
return getItemStack(slot + 1);
}

public void setResult(@Range(from = 0, to = 2) int slot, ItemStack itemStack) {
setItemStack(slot + 1, itemStack);
}
}
30 changes: 20 additions & 10 deletions api/src/main/java/org/allaymc/api/i18n/TrKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,6 @@ public interface TrKeys {
*/
String A_EXTENSION_MAINCLASS_TYPEINVALID = "allay:extension.mainclass.typeinvalid";

/**
* Loaded %1 furnace recipes
*/
String A_FURNACERECIPE_LOADED = "allay:furnacerecipe.loaded";

/**
* Loading furnace recipes...
*/
String A_FURNACERECIPE_LOADING = "allay:furnacerecipe.loading";

/**
* Chunk
*/
Expand Down Expand Up @@ -562,6 +552,26 @@ public interface TrKeys {
*/
String A_RECIPE_LOADING = "allay:recipe.loading";

/**
* Loading furnace recipes...
*/
String A_RECIPE_FURNACE_LOADING = "allay:recipe.furnace.loading";

/**
* Loaded %1 furnace recipes
*/
String A_RECIPE_FURNACE_LOADED = "allay:recipe.furnace.loaded";

/**
* Loading potion mix recipes...
*/
String A_RECIPE_POTIONMIX_LOADING = "allay:recipe.potionmix.loading";

/**
* Loaded %1 potion mix recipes
*/
String A_RECIPE_POTIONMIX_LOADED = "allay:recipe.potionmix.loaded";

/**
* §eYou are running a development version. The development version may have unexpected bugs, please do not use it in a production environment!
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.allaymc.api.item.ItemStack;
import org.allaymc.api.item.type.ItemType;

import java.util.Objects;

/**
* Represents a default item descriptor.
* <p>
Expand All @@ -31,11 +33,31 @@ public boolean match(ItemStack itemStack) {
(meta == WILDCARD_META || itemStack.getMeta() == meta);
}

public ItemStack createItemStack() {
return itemType.createItemStack(1, meta);
}

@Override
public org.cloudburstmc.protocol.bedrock.data.inventory.descriptor.ItemDescriptor toNetwork() {
return new org.cloudburstmc.protocol.bedrock.data.inventory.descriptor.DefaultDescriptor(
itemType.toNetworkDefinition(),
meta
);
}

@Override
public String toString() {
return itemType.getIdentifier() + ":" + meta;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof DefaultDescriptor that)) return false;
return meta == that.meta && Objects.equals(itemType, that.itemType);
}

@Override
public int hashCode() {
return Objects.hash(itemType, meta);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.allaymc.api.item.recipe;

import org.allaymc.api.item.recipe.impl.BaseRecipe;
import org.allaymc.api.utils.Identified;

/**
* Represents an identified recipe.
*
* @author daoge_cmd
*/
public interface IdentifiedRecipe extends Recipe, Identified {
public interface IdentifiedRecipe extends BaseRecipe, Identified {
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.allaymc.api.item.recipe;

import org.allaymc.api.item.recipe.impl.BaseRecipe;

import java.util.concurrent.atomic.AtomicInteger;

/**
* Represents a network recipe.
*
* @author daoge_cmd
*/
public interface NetworkRecipe extends Recipe {
public interface NetworkRecipe extends BaseRecipe {
AtomicInteger NETWORK_ID_COUNTER = new AtomicInteger(1);

static int assignNetworkId() {
Expand Down
13 changes: 2 additions & 11 deletions api/src/main/java/org/allaymc/api/item/recipe/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import org.allaymc.api.item.ItemStack;
import org.allaymc.api.item.recipe.input.Input;
import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.CraftingDataType;
import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.RecipeData;

/**
* Represents a recipe.
*
* @author daoge_cmd
*/
public interface Recipe {
public interface Recipe<T> {
/**
* Check if the input matches the recipe.
*
Expand All @@ -27,17 +25,10 @@ public interface Recipe {
*/
ItemStack[] getOutputs();

/**
* Get the type of this recipe.
*
* @return the type of this recipe.
*/
CraftingDataType getType();

/**
* Create the network data of this recipe.
*
* @return the network data of this recipe.
*/
RecipeData toNetworkRecipeData();
T toNetworkData();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.allaymc.api.item.recipe;

import org.allaymc.api.item.recipe.impl.BaseRecipe;

/**
* Represents a tagged recipe.
*
* @author daoge_cmd
*/
public interface TaggedRecipe extends Recipe {
public interface TaggedRecipe extends BaseRecipe {
/**
* Get the tag indicating the crafting type applicable to this recipe.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.allaymc.api.item.recipe;

import org.allaymc.api.item.recipe.impl.BaseRecipe;

import java.util.UUID;

/**
* Represents a unique recipe.
*
* @author daoge_cmd
*/
public interface UniqueRecipe extends Recipe {
public interface UniqueRecipe extends BaseRecipe {
/**
* Get the UUID of the recipe.
*
Expand Down
17 changes: 17 additions & 0 deletions api/src/main/java/org/allaymc/api/item/recipe/impl/BaseRecipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.allaymc.api.item.recipe.impl;

import org.allaymc.api.item.recipe.Recipe;
import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.CraftingDataType;
import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.RecipeData;

/**
* @author IWareQ
*/
public interface BaseRecipe extends Recipe<RecipeData> {
/**
* Get the type of this recipe.
*
* @return the type of this recipe.
*/
CraftingDataType getType();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.allaymc.api.item.recipe;
package org.allaymc.api.item.recipe.impl;

import lombok.AccessLevel;
import lombok.Getter;
import org.allaymc.api.item.ItemStack;
import org.allaymc.api.item.component.ItemBaseComponent;
import org.allaymc.api.item.recipe.IdentifiedRecipe;
import org.allaymc.api.item.recipe.NetworkRecipe;
import org.allaymc.api.item.recipe.TaggedRecipe;
import org.allaymc.api.item.recipe.UniqueRecipe;
import org.allaymc.api.utils.Identifier;
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.RecipeData;
Expand All @@ -18,7 +22,7 @@
* @author daoge_cmd
*/
@Getter
public abstract class CraftingRecipe implements Recipe, TaggedRecipe, UniqueRecipe, IdentifiedRecipe, NetworkRecipe {
public abstract class CraftingRecipe implements BaseRecipe, TaggedRecipe, UniqueRecipe, IdentifiedRecipe, NetworkRecipe {
protected Identifier identifier;
protected ItemStack[] outputs;
protected String tag;
Expand All @@ -40,7 +44,7 @@ protected CraftingRecipe(Identifier identifier, ItemStack[] outputs, String tag,
}

@Override
public RecipeData toNetworkRecipeData() {
public RecipeData toNetworkData() {
return networkRecipeDataCache;
}

Expand Down
Loading

0 comments on commit 07a8312

Please sign in to comment.