Skip to content

Commit

Permalink
Fixed server side crashes, closes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
Buuz135 committed Jan 15, 2024
1 parent 3c88a2c commit 97db4c3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
org.gradle.jvmargs=-Xmx2G
modGroup=com.buuz135
modVersion=0.5.0
modVersion=0.5.1
modBaseName=sushigocrafting
minecraftVersion=1.20.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.buuz135.sushigocrafting.api.impl.FoodIngredient;
import net.minecraft.world.item.Item;

import java.util.function.Supplier;

public interface IFoodIngredient {

Item getItem();
Expand All @@ -26,6 +28,6 @@ default boolean isEmpty() {

DietType getDietType();

IFoodIngredientRenderer getRenderer();
Supplier<IFoodIngredientRenderer> getRenderer();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import com.buuz135.sushigocrafting.api.IIngredientEffect;
import com.buuz135.sushigocrafting.api.impl.effect.AddIngredientEffect;
import com.buuz135.sushigocrafting.api.impl.effect.ModifyIngredientEffect;
import com.buuz135.sushigocrafting.api.impl.renderer.CubeFoodIngredientRenderer;
import com.buuz135.sushigocrafting.api.impl.renderer.FlatSheetFoodIngredientRenderer;
import com.buuz135.sushigocrafting.api.impl.renderer.StackFoodIngredientRenderer;
import com.buuz135.sushigocrafting.client.FoodRenderers;
import com.buuz135.sushigocrafting.proxy.SushiContent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
Expand All @@ -17,42 +15,41 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;

import java.awt.*;
import java.util.function.Supplier;

public class FoodIngredient implements IFoodIngredient {

public static FoodIngredient EMPTY = new FoodIngredient("empty", null, 0, IIngredientConsumer.WEIGHT, null, null, 0, 0, DietType.SUGARS, null);
public static FoodIngredient RICE = new FoodIngredient("rice", SushiContent.Items.COOKED_RICE, 30, IIngredientConsumer.WEIGHT, null,
new ModifyIngredientEffect(1.75f, 0), 0, 2, DietType.GRAINS, new FlatSheetFoodIngredientRenderer(0.01f, new Color(230, 237, 232)));
new ModifyIngredientEffect(1.75f, 0), 0, 2, DietType.GRAINS, () -> FoodRenderers.RICE);
public static FoodIngredient NORI = new FoodIngredient("nori", SushiContent.Items.NORI_SHEET, 1, IIngredientConsumer.STACK, null,
null, 1, 1, DietType.VEGETABLES, new FlatSheetFoodIngredientRenderer(0.005f, new Color(19, 28, 13)));
null, 1, 1, DietType.VEGETABLES, () -> FoodRenderers.NORI);
public static FoodIngredient TUNA_FILLET = new FoodIngredient("tuna", SushiContent.Items.RAW_TUNA_FILLET, 30, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "raw_fishes/tuna"))),
new AddIngredientEffect(SushiContent.Effects.ACQUIRED_TASTE, 30, 0), 3, 1, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(168, 39, 47)));
new AddIngredientEffect(SushiContent.Effects.ACQUIRED_TASTE, 30, 0), 3, 1, DietType.PROTEINS, () -> FoodRenderers.TUNA_FILLET);
public static FoodIngredient SALMON_FILLET = new FoodIngredient("salmon", SushiContent.Items.RAW_SALMON_FILLET, 30, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "raw_fishes/salmon"))),
new AddIngredientEffect(SushiContent.Effects.SMALL_BITES, 30, 0), 3, 1, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(255, 117, 59)));
new AddIngredientEffect(SushiContent.Effects.SMALL_BITES, 30, 0), 3, 1, DietType.PROTEINS, () -> FoodRenderers.SALMON_FILLET);
public static FoodIngredient AVOCADO = new FoodIngredient("avocado", SushiContent.Items.AVOCADO_SLICES, 45, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "fruits/avocado"))),
new ModifyIngredientEffect(1.20f, 1), 2, 2, DietType.FRUITS, new CubeFoodIngredientRenderer(0.01f, new Color(160, 179, 79)));
new ModifyIngredientEffect(1.20f, 1), 2, 2, DietType.FRUITS, () -> FoodRenderers.AVOCADO);
public static FoodIngredient CUCUMBER = new FoodIngredient("cucumber", SushiContent.Items.CUCUMBER_SLICES, 15, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "crops/cucumber"))),
new ModifyIngredientEffect(1.25f, 0), 2, 2, DietType.VEGETABLES, new CubeFoodIngredientRenderer(0.01f, new Color(227, 241, 199)));
new ModifyIngredientEffect(1.25f, 0), 2, 2, DietType.VEGETABLES, () -> FoodRenderers.CUCUMBER);
public static FoodIngredient SESAME = new FoodIngredient("sesame", SushiContent.Items.SESAME_SEED, 6, IIngredientConsumer.WEIGHT, null,
new ModifyIngredientEffect(2, 0), 1, 1, DietType.GRAINS, null);
public static FoodIngredient CRAB = new FoodIngredient("crab", SushiContent.Items.IMITATION_CRAB, 30, IIngredientConsumer.WEIGHT, () -> Ingredient.of(Items.COD),
new AddIngredientEffect(() -> MobEffects.MOVEMENT_SPEED, 3, 0), 2, 1, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(214, 34, 43)));
new AddIngredientEffect(() -> MobEffects.MOVEMENT_SPEED, 3, 0), 2, 1, DietType.PROTEINS, () -> FoodRenderers.CRAB);
public static FoodIngredient WAKAME = new FoodIngredient("wakame", () -> Items.SEAGRASS, 1, IIngredientConsumer.STACK, null,
null, 0, 1, DietType.VEGETABLES, new CubeFoodIngredientRenderer(0.01f, new Color(82, 127, 29)));
null, 0, 1, DietType.VEGETABLES, () -> FoodRenderers.WAKAME);
public static FoodIngredient TOBIKO = new FoodIngredient("tobiko", SushiContent.Items.TOBIKO, 12, IIngredientConsumer.WEIGHT, null,
new ModifyIngredientEffect(1.50f, 0), 1, 2, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(179, 18, 26)));
new ModifyIngredientEffect(1.50f, 0), 1, 2, DietType.PROTEINS, () -> FoodRenderers.TOBIKO);
public static FoodIngredient CHEESE = new FoodIngredient("cheese", SushiContent.Items.CHEESE, 12, IIngredientConsumer.WEIGHT, null,
new AddIngredientEffect(() -> MobEffects.SATURATION, 15, 0), 1, 2, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(237, 208, 125)));
new AddIngredientEffect(() -> MobEffects.SATURATION, 15, 0), 1, 2, DietType.PROTEINS, () -> FoodRenderers.CHEESE);
public static FoodIngredient SHRIMP = new FoodIngredient("shrimp", SushiContent.Items.SHRIMP, 30, IIngredientConsumer.WEIGHT, null,
new AddIngredientEffect(SushiContent.Effects.STEADY_HANDS, 60, 0), 2, 1, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(200, 91, 89)));
new AddIngredientEffect(SushiContent.Effects.STEADY_HANDS, 60, 0), 2, 1, DietType.PROTEINS, () -> FoodRenderers.SHRIMP);
public static FoodIngredient CHICKEN = new FoodIngredient("chicken", () -> Items.COOKED_CHICKEN, 30, IIngredientConsumer.WEIGHT, null,
new AddIngredientEffect(() -> MobEffects.SLOW_FALLING, 10, 0), 2, 1, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(255, 149, 1)));
new AddIngredientEffect(() -> MobEffects.SLOW_FALLING, 10, 0), 2, 1, DietType.PROTEINS, () -> FoodRenderers.CHICKEN);
public static FoodIngredient SOY_SAUCE = new FoodIngredient("soy_sauce", SushiContent.Items.SOY_SAUCE, 4, IIngredientConsumer.WEIGHT, null,
new ModifyIngredientEffect(1, 1), 0, 0, DietType.GRAINS, new StackFoodIngredientRenderer(SushiContent.Items.SOY_SAUCE, 0.92f, 0f, 0.15f, -20f, 0f));
new ModifyIngredientEffect(1, 1), 0, 0, DietType.GRAINS, () -> FoodRenderers.SOY_SAUCE);
public static FoodIngredient WASABI = new FoodIngredient("wasabi", SushiContent.Items.WASABI_PASTE, 4, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "crops/wasabi_root"))),
new AddIngredientEffect(() -> MobEffects.FIRE_RESISTANCE, 10, 0), 0, 0, DietType.VEGETABLES, new StackFoodIngredientRenderer(SushiContent.Items.WASABI_PASTE, 0.035f, -0.02f, 0.2f, 20, -90));
new AddIngredientEffect(() -> MobEffects.FIRE_RESISTANCE, 10, 0), 0, 0, DietType.VEGETABLES, () -> FoodRenderers.WASABI);

private final Supplier<? extends Item> item;
private final String name;
Expand All @@ -64,9 +61,9 @@ public class FoodIngredient implements IFoodIngredient {
private final int saturationValue;
private final DietType dietType;

private final IFoodIngredientRenderer renderer;
private final Supplier<IFoodIngredientRenderer> renderer;

public FoodIngredient(String name, Supplier<? extends Item> item, int defaultAmount, IIngredientConsumer ingredientConsumer, Supplier<Ingredient> ingredientSupplier, IIngredientEffect effect, int foodValue, int saturationValue, DietType dietType, IFoodIngredientRenderer renderer) {
public FoodIngredient(String name, Supplier<? extends Item> item, int defaultAmount, IIngredientConsumer ingredientConsumer, Supplier<Ingredient> ingredientSupplier, IIngredientEffect effect, int foodValue, int saturationValue, DietType dietType, Supplier<IFoodIngredientRenderer> renderer) {
this.name = name;
this.item = item;
this.defaultAmount = defaultAmount;
Expand Down Expand Up @@ -130,7 +127,7 @@ public IIngredientConsumer getIngredientConsumer() {
}

@Override
public IFoodIngredientRenderer getRenderer() {
public Supplier<IFoodIngredientRenderer> getRenderer() {
return renderer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.buuz135.sushigocrafting.client;

import com.buuz135.sushigocrafting.api.IFoodIngredientRenderer;
import com.buuz135.sushigocrafting.api.impl.renderer.CubeFoodIngredientRenderer;
import com.buuz135.sushigocrafting.api.impl.renderer.FlatSheetFoodIngredientRenderer;
import com.buuz135.sushigocrafting.api.impl.renderer.StackFoodIngredientRenderer;
import com.buuz135.sushigocrafting.proxy.SushiContent;

import java.awt.*;

public class FoodRenderers {

public static IFoodIngredientRenderer RICE = new FlatSheetFoodIngredientRenderer(0.01f, new Color(230, 237, 232));
public static IFoodIngredientRenderer NORI = new FlatSheetFoodIngredientRenderer(0.005f, new Color(19, 28, 13));
public static IFoodIngredientRenderer TUNA_FILLET = new CubeFoodIngredientRenderer(0.01f, new Color(168, 39, 47));
public static IFoodIngredientRenderer SALMON_FILLET = new CubeFoodIngredientRenderer(0.01f, new Color(255, 117, 59));
public static IFoodIngredientRenderer AVOCADO = new CubeFoodIngredientRenderer(0.01f, new Color(160, 179, 79));
public static IFoodIngredientRenderer CUCUMBER = new CubeFoodIngredientRenderer(0.01f, new Color(227, 241, 199));
public static IFoodIngredientRenderer CRAB = new CubeFoodIngredientRenderer(0.01f, new Color(214, 34, 43));
public static IFoodIngredientRenderer WAKAME = new CubeFoodIngredientRenderer(0.01f, new Color(82, 127, 29));
public static IFoodIngredientRenderer TOBIKO = new CubeFoodIngredientRenderer(0.01f, new Color(179, 18, 26));
public static IFoodIngredientRenderer CHEESE = new CubeFoodIngredientRenderer(0.01f, new Color(237, 208, 125));
public static IFoodIngredientRenderer SHRIMP = new CubeFoodIngredientRenderer(0.01f, new Color(200, 91, 89));
public static IFoodIngredientRenderer CHICKEN = new CubeFoodIngredientRenderer(0.01f, new Color(255, 149, 1));
public static IFoodIngredientRenderer SOY_SAUCE = new StackFoodIngredientRenderer(SushiContent.Items.SOY_SAUCE, 0.92f, 0f, 0.15f, -20f, 0f);
public static IFoodIngredientRenderer WASABI = new StackFoodIngredientRenderer(SushiContent.Items.WASABI_PASTE, 0.035f, -0.02f, 0.2f, 20, -90);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void render(RollerTile tileEntityIn, float partialTicks, PoseStack matrix
if (!ingredient.isEmpty()) {
var renderer = ingredient.getRenderer();
if (renderer != null) {
var offset = renderer.render(matrix, bufferIn, 0, combinedLightIn, combinedOverlayIn);
var offset = renderer.get().render(matrix, bufferIn, 0, combinedLightIn, combinedOverlayIn);
matrix.translate(0, offset.getSecond(), offset.getFirst());
}
}
Expand All @@ -56,7 +56,7 @@ public void render(RollerTile tileEntityIn, float partialTicks, PoseStack matrix
if (!ingredient.isEmpty()) {
var renderer = ingredient.getRenderer();
if (renderer != null) {
var offset = renderer.render(matrix, bufferIn, tileEntityIn.getWeightTracker().getWeights().get(i), combinedLightIn, combinedOverlayIn);
var offset = renderer.get().render(matrix, bufferIn, tileEntityIn.getWeightTracker().getWeights().get(i), combinedLightIn, combinedOverlayIn);
matrix.translate(0, offset.getSecond(), offset.getFirst());
}
}
Expand Down

0 comments on commit 97db4c3

Please sign in to comment.