Finish making some quality of life changes
This commit is contained in:
parent
8a395bd9d6
commit
30bbd059b3
63 changed files with 1256 additions and 908 deletions
|
@ -0,0 +1,99 @@
|
|||
package dev.zontreck.otemod.recipe;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
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.ItemStack;
|
||||
import net.minecraft.world.item.crafting.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CompressionChamberRecipe implements Recipe<SimpleContainer> {
|
||||
private final ResourceLocation id;
|
||||
private final ItemStack output;
|
||||
private final Ingredient input;
|
||||
|
||||
public CompressionChamberRecipe(ResourceLocation id, ItemStack output, Ingredient input)
|
||||
{
|
||||
this.id=id;
|
||||
this.output=output;
|
||||
this.input=input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(SimpleContainer simpleContainer, Level level) {
|
||||
if(level.isClientSide) return false;
|
||||
|
||||
return input.test(simpleContainer.getItem(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack assemble(SimpleContainer simpleContainer, RegistryAccess registryAccess) {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraftInDimensions(int i, int i1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResultItem(RegistryAccess registryAccess) {
|
||||
return output.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return Serializer.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType<?> getType() {
|
||||
return Type.INSTANCE;
|
||||
}
|
||||
|
||||
public static class Type implements RecipeType<CompressionChamberRecipe> {
|
||||
private Type(){}
|
||||
|
||||
public static final Type INSTANCE = new Type();
|
||||
public static final String ID = "compressing";
|
||||
}
|
||||
|
||||
public static class Serializer implements RecipeSerializer<CompressionChamberRecipe>
|
||||
{
|
||||
public static final Serializer INSTANCE = new Serializer();
|
||||
public static final ResourceLocation ID = new ResourceLocation(OTEMod.MOD_ID, Type.ID);
|
||||
|
||||
@Override
|
||||
public CompressionChamberRecipe fromJson(ResourceLocation resourceLocation, JsonObject jsonObject) {
|
||||
ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(jsonObject, "output"));
|
||||
|
||||
Ingredient input = Ingredient.fromJson(GsonHelper.getAsJsonObject(jsonObject, "input"));
|
||||
|
||||
return new CompressionChamberRecipe(resourceLocation, output, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable CompressionChamberRecipe fromNetwork(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf) {
|
||||
ItemStack output = friendlyByteBuf.readItem();
|
||||
|
||||
Ingredient input = Ingredient.fromNetwork(friendlyByteBuf);
|
||||
return new CompressionChamberRecipe(resourceLocation, output, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toNetwork(FriendlyByteBuf friendlyByteBuf, CompressionChamberRecipe compressionChamberRecipe) {
|
||||
friendlyByteBuf.writeItem(compressionChamberRecipe.output);
|
||||
compressionChamberRecipe.input.toNetwork(friendlyByteBuf);
|
||||
}
|
||||
}
|
||||
}
|
19
src/main/java/dev/zontreck/otemod/recipe/ModRecipes.java
Normal file
19
src/main/java/dev/zontreck/otemod/recipe/ModRecipes.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package dev.zontreck.otemod.recipe;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModRecipes {
|
||||
public static final DeferredRegister<RecipeSerializer<?>> SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, OTEMod.MOD_ID);
|
||||
|
||||
public static final RegistryObject<RecipeSerializer<CompressionChamberRecipe>> COMPRESSING_SERIALIZER = SERIALIZERS.register("compressing", ()->CompressionChamberRecipe.Serializer.INSTANCE);
|
||||
|
||||
public static void register(IEventBus bus)
|
||||
{
|
||||
SERIALIZERS.register(bus);
|
||||
}
|
||||
}
|
Reference in a new issue