Cleanup
This commit is contained in:
parent
7431d8fc42
commit
b1b62db60c
5 changed files with 11 additions and 42 deletions
|
|
@ -2,34 +2,27 @@ package com.oitsjustjose.itemgator;
|
|||
|
||||
|
||||
import com.oitsjustjose.itemgator.common.data.RecipeTypeRegistry;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Mod(ItemGator.MOD_ID)
|
||||
public class ItemGator {
|
||||
public static final String MOD_ID = "itemgator";
|
||||
|
||||
private static ItemGator instance;
|
||||
public final Logger LOGGER = LogManager.getLogger();
|
||||
public final RecipeTypeRegistry CustomRecipeRegistry = new RecipeTypeRegistry();
|
||||
|
||||
private static ItemGator instance;
|
||||
|
||||
public ItemGator() {
|
||||
instance = this;
|
||||
|
||||
if (true) {
|
||||
DeferredRegister<Item> ItemRegistry = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID);
|
||||
ItemRegistry.register("beans", () -> new Item(new Item.Properties().stacksTo(3)));
|
||||
ItemRegistry.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
}
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
CustomRecipeRegistry.SERIALIZERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.oitsjustjose.itemgator.common.data.ingredient;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.oitsjustjose.itemgator.ItemGator;
|
||||
import com.oitsjustjose.itemgator.common.data.BaseRecipe;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
|
|
@ -31,14 +30,6 @@ public class IngredientRecipe extends BaseRecipe implements Recipe<RecipeWrapper
|
|||
ItemGator.getInstance().CustomRecipeRegistry.registerRecipe(this);
|
||||
}
|
||||
|
||||
public IngredientRecipe(ResourceLocation id, Ingredient ingredient, ItemStack substitute, String tag) {
|
||||
this.id = id;
|
||||
this.ingredient = ingredient;
|
||||
this.substitute = substitute;
|
||||
this.tags = Lists.newArrayList(tag);
|
||||
ItemGator.getInstance().CustomRecipeRegistry.registerRecipe(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@NotNull RecipeWrapper wrapper, @NotNull Level level) {
|
||||
var stack = wrapper.getItem(0);
|
||||
|
|
@ -97,13 +88,13 @@ public class IngredientRecipe extends BaseRecipe implements Recipe<RecipeWrapper
|
|||
@Override
|
||||
public ItemStack getOriginal(ItemStack substitute) {
|
||||
if (!substitute.hasTag()) {
|
||||
// TODO: WARNING
|
||||
ItemGator.getInstance().LOGGER.error("Provided substitute {} does not have a tag - that item is likely lost forever!", substitute.getDisplayName());
|
||||
return substitute;
|
||||
}
|
||||
|
||||
var tag = substitute.getTag();
|
||||
if (tag == null) {
|
||||
// TODO: WARNING
|
||||
ItemGator.getInstance().LOGGER.error("Provided substitute {} does not have a tag - that item is likely lost forever!", substitute.getDisplayName());
|
||||
return substitute;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,13 +13,10 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IngredientRecipeSerializer implements RecipeSerializer<IngredientRecipe> {
|
||||
@Override
|
||||
public @NotNull IngredientRecipe fromJson(@NotNull ResourceLocation id, @NotNull JsonObject obj) {
|
||||
// TODO: better validation
|
||||
|
||||
var input = Ingredient.fromJson(obj.get("input"), false);
|
||||
var substitute = ShapedRecipe.itemStackFromJson(obj.getAsJsonObject("substitute"));
|
||||
substitute.setCount(1);
|
||||
|
|
@ -38,7 +35,7 @@ public class IngredientRecipeSerializer implements RecipeSerializer<IngredientRe
|
|||
public void toNetwork(@NotNull FriendlyByteBuf buf, @NotNull IngredientRecipe recipe) {
|
||||
CraftingHelper.write(buf, recipe.getIngredient());
|
||||
buf.writeItemStack(recipe.getPlainSubstitute(), false);
|
||||
buf.writeUtf(recipe.getTags().stream().collect(Collectors.joining(",")));
|
||||
buf.writeUtf(String.join(",", recipe.getTags()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.oitsjustjose.itemgator.common.data.mod;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.oitsjustjose.itemgator.ItemGator;
|
||||
import com.oitsjustjose.itemgator.common.data.BaseRecipe;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
|
|
@ -31,14 +30,6 @@ public class ModRecipe extends BaseRecipe implements Recipe<RecipeWrapper> {
|
|||
ItemGator.getInstance().CustomRecipeRegistry.registerRecipe(this);
|
||||
}
|
||||
|
||||
public ModRecipe(ResourceLocation id, String mod, ItemStack substitute, String tag) {
|
||||
this.id = id;
|
||||
this.mod = mod;
|
||||
this.substitute = substitute;
|
||||
this.tags = Lists.newArrayList(tag);
|
||||
ItemGator.getInstance().CustomRecipeRegistry.registerRecipe(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@NotNull RecipeWrapper wrapper, @NotNull Level level) {
|
||||
var stack = wrapper.getItem(0);
|
||||
|
|
@ -98,13 +89,13 @@ public class ModRecipe extends BaseRecipe implements Recipe<RecipeWrapper> {
|
|||
@Override
|
||||
public ItemStack getOriginal(ItemStack substitute) {
|
||||
if (!substitute.hasTag()) {
|
||||
// TODO: WARNING
|
||||
ItemGator.getInstance().LOGGER.error("Provided substitute {} does not have a tag - that item is likely lost forever!", substitute.getDisplayName());
|
||||
return substitute;
|
||||
}
|
||||
|
||||
var tag = substitute.getTag();
|
||||
if (tag == null) {
|
||||
// TODO: WARNING
|
||||
ItemGator.getInstance().LOGGER.error("Provided substitute {} does not have a tag - that item is likely lost forever!", substitute.getDisplayName());
|
||||
return substitute;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,20 @@
|
|||
package com.oitsjustjose.itemgator.common.data.mod;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.ShapedRecipe;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModRecipeSerializer implements RecipeSerializer<ModRecipe> {
|
||||
@Override
|
||||
public @NotNull ModRecipe fromJson(@NotNull ResourceLocation id, @NotNull JsonObject obj) {
|
||||
// TODO: better validation
|
||||
|
||||
var mod = obj.get("mod").getAsString();
|
||||
var substitute = ShapedRecipe.itemStackFromJson(obj.getAsJsonObject("substitute"));
|
||||
substitute.setCount(1);
|
||||
|
|
@ -36,7 +33,7 @@ public class ModRecipeSerializer implements RecipeSerializer<ModRecipe> {
|
|||
public void toNetwork(@NotNull FriendlyByteBuf buf, @NotNull ModRecipe recipe) {
|
||||
buf.writeUtf(recipe.getMod());
|
||||
buf.writeItemStack(recipe.getPlainSubstitute(), false);
|
||||
buf.writeUtf(recipe.getTags().stream().collect(Collectors.joining(",")));
|
||||
buf.writeUtf(String.join(",", recipe.getTags()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in a new issue