Skip to content

Commit

Permalink
Merge pull request #70 from GrowthcraftCE/development
Browse files Browse the repository at this point in the history
Release for Growthcraft 9.1.3
  • Loading branch information
Alatyami authored Nov 13, 2023
2 parents a44e5a1 + 55d1f59 commit e49f6dd
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 87 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Growthcraft 9 for Minecraft 1.20.1 (Forge)

[![Growthcraft Version](https://img.shields.io/badge/Growthcraft-9.1.2-orange.svg)](https://github.com/GrowthcraftCE/Growthcraft-1.20)
[![Growthcraft Version](https://img.shields.io/badge/Growthcraft-9.1.3-orange.svg)](https://github.com/GrowthcraftCE/Growthcraft-1.20)
[![](http://cf.way2muchnoise.eu/versions/growthcraft-community-edition_latest.svg)](https://minecraft.curseforge.com/projects/growthcraft-community-edition/)
[![](http://cf.way2muchnoise.eu/short_growthcraft-community-edition.svg)](https://minecraft.curseforge.com/projects/growthcraft-community-edition/)
[![Forge Version](https://img.shields.io/badge/Minecraft%20Forge-47.2.0-yellow.svg)](http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.20.1.html)
Expand All @@ -22,8 +22,8 @@ to our GitHub wiki documentation. As of version 9 we have included an in-game ma
### Growthcraft 9 (Minecraft 1.20.1)

End of Support: TBD
Latest Version: 9.0.7
Stable Version: 9.1.2
Latest Version: 9.1.2
Stable Version: 9.1.3

### Growthcraft 8 (Minecraft 1.19.4)

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod_id=growthcraft
mod_archive_base=growthcraft
mod_name=Growthcraft
mod_license=GNU General Public License v3.0
mod_version=9.1.2
mod_version=9.1.3
mod_group_id=growthcraft
mod_authors=Alatyami
mod_description=Growthcraft is a realistic and immersive Forge mod that adds various new elements to the game of Minecraft.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/growthcraft/core/shared/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Reference {
public static final String MODID = "growthcraft";
public static final String NAME = "Growthcraft";
public static final String NAME_SHORT = "core";
public static final String VERSION = "9.1.2";
public static final String VERSION = "9.1.3";

private Reference() { /* Prevent default public constructor */ }

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/growthcraft/lib/utils/CraftingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@ public static NonNullList<Ingredient> readIngredients(JsonArray ingredientArray)
return nonnulllist;
}

public static boolean doesFluidMatch(FluidStack controlFluidStack, FluidStack testFluidStack) {
boolean inputFluidTypeMatches = controlFluidStack.getFluid() == testFluidStack.getFluid();
boolean inputFluidAmountMatches = controlFluidStack.getAmount() == testFluidStack.getAmount();
return inputFluidTypeMatches && inputFluidAmountMatches;
}
private CraftingUtils() { /* Prevent automatic public constructor */ }
}
17 changes: 12 additions & 5 deletions src/main/java/growthcraft/milk/block/MixingVatBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import growthcraft.milk.block.entity.MixingVatBlockEntity;
import growthcraft.milk.init.GrowthcraftMilkBlockEntities;
import growthcraft.milk.init.GrowthcraftMilkFluids;
import growthcraft.milk.init.GrowthcraftMilkTags;
import growthcraft.milk.init.config.GrowthcraftMilkConfig;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -36,8 +35,10 @@
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;

import static net.minecraft.world.phys.shapes.BooleanOp.OR;
Expand Down Expand Up @@ -124,7 +125,8 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, Block
}

@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult hitResult) {
@ParametersAreNonnullByDefault
public @NotNull InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult hitResult) {
if (level.isClientSide) {
return InteractionResult.SUCCESS;
}
Expand Down Expand Up @@ -185,13 +187,18 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
}

return fluidInteractionResult ? InteractionResult.SUCCESS : InteractionResult.FAIL;
} else if (player.getItemInHand(interactionHand).is(GrowthcraftMilkTags.Items.TAG_MIXING_VAT_TOOLS)) {
// TODO Handle tool activation of MixingVat.
} else if (!player.getItemInHand(interactionHand).isEmpty()
&& (player.getItemInHand(interactionHand).is(blockEntity.getActivationTool().getItem())
|| player.getItemInHand(interactionHand).is(blockEntity.getResultActivationTool().getItem()))
) {
// Try and activate the recipe.
if(blockEntity.activateRecipe(player.getItemInHand(interactionHand))) {
player.getItemInHand(interactionHand).shrink(1);
if (GrowthcraftMilkConfig.isConsumeMixingVatActivator())
player.getItemInHand(interactionHand).shrink(1);
return InteractionResult.SUCCESS;
}

// Process the Cheese Curds extraction.
if(!blockEntity.getInventoryHandler().getStackInSlot(3).isEmpty()
&& blockEntity.activateResult(player, player.getItemInHand(interactionHand))) {
player.getItemInHand(interactionHand).shrink(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public class MixingVatBlockEntity extends BlockEntity implements BlockEntityTick
protected void onContentsChanged(int slot) {
setChanged();
}

@Override
public int getSlotLimit(int slot) {
return 1;
}
};

private LazyOptional<IItemHandler> inventoryHandler = LazyOptional.empty();
Expand Down Expand Up @@ -478,7 +483,7 @@ public boolean activateRecipe(ItemStack stack) {
&& isHeated() == this.requiresHeatSource;

// Reset the activation tool if recipe is activated
if (activated) this.activationTool = ItemStack.EMPTY;
if (this.activated) this.activationTool = ItemStack.EMPTY;

return this.activated;
}
Expand Down
53 changes: 24 additions & 29 deletions src/main/java/growthcraft/milk/recipe/MixingVatFluidRecipe.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
package growthcraft.milk.recipe;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import growthcraft.lib.utils.CraftingUtils;
import growthcraft.lib.utils.RecipeUtils;
import growthcraft.milk.GrowthcraftMilk;
import growthcraft.milk.shared.Reference;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.fluids.FluidStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MixingVatFluidRecipe implements Recipe<SimpleContainer> {
private final ResourceLocation recipeId;
private final RecipeUtils.Category category;
private final ItemStack activationTool;
private final List<ItemStack> ingredients;
private final NonNullList<Ingredient> ingredients;

private final FluidStack inputFluidStack;
private final int processingTime;

Expand All @@ -40,15 +44,15 @@ public class MixingVatFluidRecipe implements Recipe<SimpleContainer> {

public MixingVatFluidRecipe(ResourceLocation recipeId, RecipeUtils.Category category,
FluidStack inputFluidStack, FluidStack reagentFluidStack,
List<ItemStack> ingredients, int processingTime,
NonNullList<Ingredient> inputIngredients, int processingTime,
FluidStack outputFluidStack, FluidStack wasteFluidStack,
ItemStack activationTool,
boolean requiresHeat) {
this.recipeId = recipeId;
this.category = category;
this.inputFluidStack = inputFluidStack;
this.reagentFluidStack = reagentFluidStack;
this.ingredients = ingredients;
this.ingredients = inputIngredients;
this.processingTime = processingTime;
this.outputFluidStack = outputFluidStack;
this.wasteFluidStack = wasteFluidStack;
Expand All @@ -57,25 +61,19 @@ public MixingVatFluidRecipe(ResourceLocation recipeId, RecipeUtils.Category cate
}

@Override
public boolean matches(SimpleContainer container, Level level) {
public boolean matches(@NotNull SimpleContainer container, @NotNull Level level) {
return false;
}

public boolean matches(FluidStack testBaseFluidStack, FluidStack testReagentFluidStack,
List<ItemStack> testIngredients, boolean hasHeatSource) {

boolean inputFluidTypeMatches = testBaseFluidStack.getFluid() == this.getInputFluidStack().getFluid();
boolean inputFluidAmountMatches = testBaseFluidStack.getAmount() == this.getInputFluidStack().getAmount();

boolean reagentFluidTypeMatches = testReagentFluidStack.getFluid() == this.getReagentFluidStack().getFluid();
boolean reagentFluidAmountMatches = testReagentFluidStack.getAmount() == this.getReagentFluidStack().getAmount();

boolean fluidMatches = inputFluidTypeMatches && inputFluidAmountMatches
&& reagentFluidTypeMatches && reagentFluidAmountMatches;
boolean fluidMatches = CraftingUtils.doesFluidMatch(testBaseFluidStack, this.getInputFluidStack())
&& CraftingUtils.doesFluidMatch(reagentFluidStack, this.getReagentFluidStack());

boolean ingredientMatches = false;

if (this.getIngredientList().size() == testIngredients.size()) {
if (this.getIngredients().size() == testIngredients.size()) {
int itemCount = this.getIngredientList().size();
int matchCount = 0;
for (int i = 0; i < this.getIngredientList().size(); i++) {
Expand Down Expand Up @@ -142,8 +140,13 @@ public boolean activationToolValid(ItemStack tool) {
return this.activationTool.getItem() == tool.getItem();
}

@Override
public @NotNull NonNullList<Ingredient> getIngredients() {
return this.ingredients;
}

public List<ItemStack> getIngredientList() {
return ingredients;
return Arrays.stream(ingredients.get(0).getItems()).toList();
}

public List<Item> getIngredientItems() {
Expand Down Expand Up @@ -203,15 +206,7 @@ public MixingVatFluidRecipe fromJson(ResourceLocation recipeId, JsonObject json)
ItemStack activationTool = CraftingHelper.getItemStack(
GsonHelper.getAsJsonObject(json, "activation_tool"), false);

List<ItemStack> ingredients = new ArrayList<>();
JsonArray jsonIngredients = GsonHelper.getAsJsonArray(json, "ingredients");

if (jsonIngredients.size() <= maxIngredients) {
for (int i = 0; i < jsonIngredients.size(); i++) {
ItemStack itemStack = CraftingHelper.getItemStack(jsonIngredients.get(i).getAsJsonObject(), false);
ingredients.add(itemStack);
}
}
NonNullList<Ingredient> inputIngredient = CraftingUtils.readIngredients(GsonHelper.getAsJsonArray(json, "ingredients"));

FluidStack reagentFluid = CraftingUtils.getFluidStack(
GsonHelper.getAsJsonObject(json, "reagent_fluid"));
Expand All @@ -221,7 +216,7 @@ public MixingVatFluidRecipe fromJson(ResourceLocation recipeId, JsonObject json)
GsonHelper.getAsJsonObject(json, "result_fluid_waste"));

return new MixingVatFluidRecipe(recipeId, RecipeUtils.Category.FLUID,
inputFluid, reagentFluid, ingredients, processingTime, resultFluid, wasteFluid, activationTool, requiresHeat);
inputFluid, reagentFluid, inputIngredient, processingTime, resultFluid, wasteFluid, activationTool, requiresHeat);

}

Expand All @@ -237,10 +232,10 @@ public MixingVatFluidRecipe fromJson(ResourceLocation recipeId, JsonObject json)
ItemStack activationTool = buffer.readItem();

int ingredientSize = buffer.readVarInt();
NonNullList<Ingredient> ingredients = NonNullList.withSize(ingredientSize, Ingredient.EMPTY);

List<ItemStack> ingredients = new ArrayList<>();
for (int i = 0; i < ingredientSize; i++) {
ingredients.add(buffer.readItem());
ingredients.set(i, Ingredient.fromNetwork(buffer));
}

FluidStack reagentFluidStack = buffer.readFluidStack();
Expand Down Expand Up @@ -268,8 +263,8 @@ public void toNetwork(FriendlyByteBuf buffer, MixingVatFluidRecipe recipe) {

buffer.writeVarInt(recipe.getIngredientList().size());

for (int i = 0; i < recipe.getIngredientList().size(); i++) {
buffer.writeItemStack(recipe.getIngredientList().get(i), false);
for (Ingredient ingredient : recipe.getIngredients()) {
ingredient.toNetwork(buffer);
}

buffer.writeFluidStack(recipe.getReagentFluidStack());
Expand Down
Loading

0 comments on commit e49f6dd

Please sign in to comment.