From a73919357bf7a945cfd47f2da2f2f62e1f9434d8 Mon Sep 17 00:00:00 2001 From: LordGrimmauld Date: Fri, 10 Jul 2020 13:48:59 +0200 Subject: [PATCH] fluid reading for the processing recipes and its serializer --- .../com/simibubi/create/AllRecipeTypes.java | 23 ++--- .../create/compat/jei/ConversionRecipe.java | 19 ++-- .../jei/category/CreateRecipeCategory.java | 4 +- .../compat/jei/category/CrushingCategory.java | 4 +- .../compat/jei/category/MillingCategory.java | 2 +- .../MysteriousItemConversionCategory.java | 2 +- .../jei/category/PolishingCategory.java | 2 +- .../compat/jei/category/PressingCategory.java | 4 +- .../compat/jei/category/SawingCategory.java | 4 +- .../jei/category/SplashingCategory.java | 2 +- .../crusher/AbstractCrushingRecipe.java | 2 +- .../components/crusher/CrushingRecipe.java | 9 +- .../CrushingWheelControllerTileEntity.java | 2 +- .../components/fan/SplashingRecipe.java | 12 ++- .../components/millstone/MillingRecipe.java | 12 ++- .../millstone/MillstoneTileEntity.java | 2 +- .../mixer/MechanicalMixerTileEntity.java | 68 ++++++++----- .../components/mixer/MixingRecipe.java | 42 ++++++-- .../press/MechanicalPressTileEntity.java | 7 +- .../components/press/PressingRecipe.java | 13 ++- .../components/saw/CuttingRecipe.java | 12 ++- .../components/saw/SawTileEntity.java | 2 +- .../fluids/CombinedFluidHandler.java | 12 +-- .../processing/BasinOperatingTileEntity.java | 4 +- .../processing/BasinTileEntity.java | 12 ++- ...peList.java => CombinedItemFluidList.java} | 22 +++-- .../processing/ProcessingOutput.java | 6 +- .../processing/ProcessingRecipe.java | 65 +++++++++--- .../ProcessingRecipeSerializer.java | 99 +++++++++++++++---- .../curiosities/tools/SandPaperItem.java | 7 +- .../tools/SandPaperPolishingRecipe.java | 21 ++-- .../content/logistics/InWorldProcessing.java | 2 +- 32 files changed, 349 insertions(+), 150 deletions(-) rename src/main/java/com/simibubi/create/content/contraptions/processing/{MultiIngredientTypeList.java => CombinedItemFluidList.java} (50%) diff --git a/src/main/java/com/simibubi/create/AllRecipeTypes.java b/src/main/java/com/simibubi/create/AllRecipeTypes.java index 87fcec136..28c52641a 100644 --- a/src/main/java/com/simibubi/create/AllRecipeTypes.java +++ b/src/main/java/com/simibubi/create/AllRecipeTypes.java @@ -49,30 +49,31 @@ public enum AllRecipeTypes { public > T getType() { return (T) type; } - - private AllRecipeTypes(Supplier> supplier) { + + AllRecipeTypes(Supplier> supplier) { this(supplier, null); } - private AllRecipeTypes(Supplier> supplier, - IRecipeType> existingType) { + AllRecipeTypes(Supplier> supplier, + IRecipeType> existingType) { this.supplier = supplier; this.type = existingType; } public static void register(RegistryEvent.Register> event) { ShapedRecipe.setCraftingSize(9, 9); - + for (AllRecipeTypes r : AllRecipeTypes.values()) { if (r.type == null) r.type = customType(Lang.asId(r.name())); - + r.serializer = r.supplier.get(); ResourceLocation location = new ResourceLocation(Create.ID, Lang.asId(r.name())); - event.getRegistry().register(r.serializer.setRegistryName(location)); + event.getRegistry() + .register(r.serializer.setRegistryName(location)); } } - + private static > IRecipeType customType(String id) { return Registry.register(Registry.RECIPE_TYPE, new ResourceLocation(Create.ID, id), new IRecipeType() { public String toString() { @@ -80,10 +81,10 @@ public enum AllRecipeTypes { } }); } - - private static Supplier> processingSerializer(IRecipeFactory> factory) { + + private static Supplier> processingSerializer( + IRecipeFactory> factory) { return () -> new ProcessingRecipeSerializer<>(factory); } - } diff --git a/src/main/java/com/simibubi/create/compat/jei/ConversionRecipe.java b/src/main/java/com/simibubi/create/compat/jei/ConversionRecipe.java index 069783c75..fe21c60d6 100644 --- a/src/main/java/com/simibubi/create/compat/jei/ConversionRecipe.java +++ b/src/main/java/com/simibubi/create/compat/jei/ConversionRecipe.java @@ -1,8 +1,11 @@ package com.simibubi.create.compat.jei; -import java.util.Arrays; +import java.util.Collections; import java.util.List; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.processing.ProcessingIngredient; @@ -13,6 +16,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.wrapper.RecipeWrapper; /** @@ -21,24 +25,27 @@ import net.minecraftforge.items.wrapper.RecipeWrapper; * @author simibubi * */ +@ParametersAreNonnullByDefault public class ConversionRecipe extends ProcessingRecipe { public ConversionRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration) { + List results, int processingDuration, @Nullable List fluidIngredients, + @Nullable List fluidResults) { super(AllRecipeTypes.CONVERSION, id, group, ingredients, results, processingDuration); } static int counter = 0; public static ConversionRecipe create(ItemStack from, ItemStack to) { - List ingredients = Arrays.asList(new ProcessingIngredient(Ingredient.fromStacks(from))); - List outputs = Arrays.asList(new ProcessingOutput(to, 1)); + List ingredients = + Collections.singletonList(new ProcessingIngredient(Ingredient.fromStacks(from))); + List outputs = Collections.singletonList(new ProcessingOutput(to, 1)); return new ConversionRecipe(new ResourceLocation(Create.ID, "conversion_" + counter++), ingredients, outputs); } public ConversionRecipe(ResourceLocation id, List ingredients, - List results) { - this(id, "conversions", ingredients, results, -1); + List results) { + this(id, "conversions", ingredients, results, -1, null, null); } @Override diff --git a/src/main/java/com/simibubi/create/compat/jei/category/CreateRecipeCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/CreateRecipeCategory.java index 59e5a866d..832841461 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/CreateRecipeCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/CreateRecipeCategory.java @@ -59,10 +59,10 @@ public abstract class CreateRecipeCategory> implements IRec if (!(recipe instanceof ProcessingRecipe)) return jeiSlot; ProcessingRecipe processingRecipe = (ProcessingRecipe) recipe; - List rollableResults = processingRecipe.getRollableResults(); + List rollableResults = processingRecipe.getRollableItemResults(); if (rollableResults.size() <= index) return jeiSlot; - if (processingRecipe.getRollableResults().get(index).getChance() == 1) + if (processingRecipe.getRollableItemResults().get(index).getChance() == 1) return jeiSlot; return AllGuiTextures.JEI_CHANCE_SLOT; } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/CrushingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/CrushingCategory.java index 5e95a3c2c..088456e68 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/CrushingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/CrushingCategory.java @@ -41,7 +41,7 @@ public class CrushingCategory extends CreateRecipeCategory results = recipe.getRollableResults(); + List results = recipe.getRollableItemResults(); int size = results.size(); int offset = -size * 19 / 2; for (int outputIndex = 0; outputIndex < size; outputIndex++) { @@ -54,7 +54,7 @@ public class CrushingCategory extends CreateRecipeCategory results = recipe.getRollableResults(); + List results = recipe.getRollableItemResults(); AllGuiTextures.JEI_SLOT.draw(50, 2); AllGuiTextures.JEI_DOWN_ARROW.draw(72, 7); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/MillingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/MillingCategory.java index 90ddeacc8..79985ef23 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/MillingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/MillingCategory.java @@ -43,7 +43,7 @@ public class MillingCategory extends CreateRecipeCategory results = recipe.getRollableResults(); + List results = recipe.getRollableItemResults(); boolean single = results.size() == 1; for (int outputIndex = 0; outputIndex < results.size(); outputIndex++) { int xOffset = outputIndex % 2 == 0 ? 0 : 19; diff --git a/src/main/java/com/simibubi/create/compat/jei/category/MysteriousItemConversionCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/MysteriousItemConversionCategory.java index 42a1cdde0..36514730c 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/MysteriousItemConversionCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/MysteriousItemConversionCategory.java @@ -41,7 +41,7 @@ public class MysteriousItemConversionCategory extends CreateRecipeCategory results = recipe.getRollableResults(); + List results = recipe.getRollableItemResults(); itemStacks.init(0, true, 26, 16); itemStacks.set(0, Arrays.asList(recipe.getIngredients().get(0).getMatchingStacks())); itemStacks.init(1, false, 131, 16); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java index 3b3399f27..0fd563557 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java @@ -43,7 +43,7 @@ public class PolishingCategory extends CreateRecipeCategory results = recipe.getRollableResults(); + List results = recipe.getRollableItemResults(); itemStacks.init(0, true, 26, 28); itemStacks.set(0, Arrays.asList(recipe.getIngredients().get(0).getMatchingStacks())); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/PressingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/PressingCategory.java index f1260b4fd..b635f5625 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/PressingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/PressingCategory.java @@ -41,7 +41,7 @@ public class PressingCategory extends CreateRecipeCategory { itemStacks.init(0, true, 26, 50); itemStacks.set(0, Arrays.asList(recipe.getIngredients().get(0).getMatchingStacks())); - List results = recipe.getRollableResults(); + List results = recipe.getRollableItemResults(); for (int outputIndex = 0; outputIndex < results.size(); outputIndex++) { itemStacks.init(outputIndex + 1, false, 131 + 19 * outputIndex, 50); itemStacks.set(outputIndex + 1, results.get(outputIndex).getStack()); @@ -54,7 +54,7 @@ public class PressingCategory extends CreateRecipeCategory { public void draw(PressingRecipe recipe, double mouseX, double mouseY) { AllGuiTextures.JEI_SLOT.draw(26, 50); getRenderedSlot(recipe, 0).draw(131, 50); - if (recipe.getRollableResults().size() > 1) + if (recipe.getRollableItemResults().size() > 1) getRenderedSlot(recipe, 1).draw(131 + 19, 50); AllGuiTextures.JEI_SHADOW.draw(61, 41); AllGuiTextures.JEI_LONG_ARROW.draw(52, 54); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java index 52de5db32..c5b331f8c 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java @@ -40,7 +40,7 @@ public class SawingCategory extends CreateRecipeCategory { itemStacks.init(0, true, 43, 4); itemStacks.set(0, Arrays.asList(recipe.getIngredients().get(0).getMatchingStacks())); - List results = recipe.getRollableResults(); + List results = recipe.getRollableItemResults(); for (int outputIndex = 0; outputIndex < results.size(); outputIndex++) { int xOffset = outputIndex % 2 == 0 ? 0 : 19; int yOffset = (outputIndex / 2) * -19; @@ -55,7 +55,7 @@ public class SawingCategory extends CreateRecipeCategory { @Override public void draw(CuttingRecipe recipe, double mouseX, double mouseY) { AllGuiTextures.JEI_SLOT.draw(43, 4); - int size = recipe.getRollableResults().size(); + int size = recipe.getRollableItemResults().size(); for (int i = 0; i < size; i++) { int xOffset = i % 2 == 0 ? 0 : 19; int yOffset = (i / 2) * -19; diff --git a/src/main/java/com/simibubi/create/compat/jei/category/SplashingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/SplashingCategory.java index 9fe2eb3c6..89ca987c2 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/SplashingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/SplashingCategory.java @@ -42,7 +42,7 @@ public class SplashingCategory extends ProcessingViaFanCategory .get(0) .getMatchingStacks())); - List results = recipe.getRollableResults(); + List results = recipe.getRollableItemResults(); boolean single = results.size() == 1; for (int outputIndex = 0; outputIndex < results.size(); outputIndex++) { int xOffset = outputIndex % 2 == 0 ? 0 : 19; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/AbstractCrushingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/AbstractCrushingRecipe.java index 2ee5d5f1d..bd99f7740 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/AbstractCrushingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/AbstractCrushingRecipe.java @@ -13,7 +13,7 @@ import net.minecraftforge.items.wrapper.RecipeWrapper; public abstract class AbstractCrushingRecipe extends ProcessingRecipe { public AbstractCrushingRecipe(AllRecipeTypes recipeType, ResourceLocation id, String group, - List ingredients, List results, int processingDuration) { + List ingredients, List results, int processingDuration) { super(recipeType, id, group, ingredients, results, processingDuration); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingRecipe.java index 9f77db133..407c0ad3b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingRecipe.java @@ -8,12 +8,14 @@ import com.simibubi.create.content.contraptions.processing.ProcessingOutput; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.wrapper.RecipeWrapper; public class CrushingRecipe extends AbstractCrushingRecipe { public CrushingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration) { + List results, int processingDuration, List fluidIngredients, + List fluidResults) { super(AllRecipeTypes.CRUSHING, id, group, ingredients, results, processingDuration); } @@ -21,9 +23,10 @@ public class CrushingRecipe extends AbstractCrushingRecipe { public boolean matches(RecipeWrapper inv, World worldIn) { if (inv.isEmpty()) return false; - return ingredients.get(0).test(inv.getStackInSlot(0)); + return ingredients.get(0) + .test(inv.getStackInSlot(0)); } - + @Override protected int getMaxOutputCount() { return 7; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelControllerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelControllerTileEntity.java index 8141fcf36..3f5eeec54 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelControllerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelControllerTileEntity.java @@ -191,7 +191,7 @@ public class CrushingWheelControllerTileEntity extends SmartTileEntity { inventory.clear(); for (int roll = 0; roll < rolls; roll++) { List rolledResults = recipe.get() - .rollResults(); + .rollResults().getItemStacks(); for (int i = 0; i < rolledResults.size(); i++) { ItemStack stack = rolledResults.get(i); ItemHelper.addToList(stack, list); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java index 47da85aa0..d873ae952 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/SplashingRecipe.java @@ -11,11 +11,16 @@ import com.simibubi.create.content.logistics.InWorldProcessing.SplashingInv; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidStack; +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault public class SplashingRecipe extends ProcessingRecipe { public SplashingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration) { + List results, int processingDuration, List fluidIngredients, + List fluidResults) { super(AllRecipeTypes.SPLASHING, id, group, ingredients, results, processingDuration); } @@ -23,9 +28,10 @@ public class SplashingRecipe extends ProcessingRecipe ingredients, - List results, int processingDuration) { + List results, int processingDuration, List fluidIngredients, + List fluidResults) { super(AllRecipeTypes.MILLING, id, group, ingredients, results, processingDuration); } @@ -22,9 +27,10 @@ public class MillingRecipe extends AbstractCrushingRecipe { public boolean matches(RecipeWrapper inv, World worldIn) { if (inv.isEmpty()) return false; - return ingredients.get(0).test(inv.getStackInSlot(0)); + return ingredients.get(0) + .test(inv.getStackInSlot(0)); } - + @Override protected int getMaxOutputCount() { return 4; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneTileEntity.java index bccc88d6d..434c6883c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneTileEntity.java @@ -94,7 +94,7 @@ public class MillstoneTileEntity extends KineticTileEntity { ItemStack stackInSlot = inputInv.getStackInSlot(0); stackInSlot.shrink(1); inputInv.setStackInSlot(0, stackInSlot); - lastRecipe.rollResults().forEach(stack -> ItemHandlerHelper.insertItemStacked(outputInv, stack, false)); + lastRecipe.rollResults().forEachItemStack(stack -> ItemHandlerHelper.insertItemStacked(outputInv, stack, false)); sendData(); markDirty(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java index 76cf705ef..af4bd4f79 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerTileEntity.java @@ -1,14 +1,15 @@ package com.simibubi.create.content.contraptions.components.mixer; -import java.util.ArrayList; import java.util.Comparator; import java.util.LinkedList; import java.util.List; import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity; +import com.simibubi.create.content.contraptions.fluids.CombinedFluidHandler; import com.simibubi.create.content.contraptions.processing.BasinOperatingTileEntity; import com.simibubi.create.content.contraptions.processing.BasinTileEntity.BasinInventory; +import com.simibubi.create.content.contraptions.processing.CombinedItemFluidList; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.CenteredSideValueBoxTransform; import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour; @@ -29,7 +30,6 @@ import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import net.minecraftforge.items.IItemHandler; public class MechanicalMixerTileEntity extends BasinOperatingTileEntity { @@ -65,7 +65,7 @@ public class MechanicalMixerTileEntity extends BasinOperatingTileEntity { } public float getRenderedHeadOffset(float partialTicks) { - int localTick = 0; + int localTick; float offset = 0; if (running) { if (runningTicks < 20) { @@ -154,26 +154,45 @@ public class MechanicalMixerTileEntity extends BasinOperatingTileEntity { } public void renderParticles() { - IItemHandler itemHandler = basinItemInv.orElse(null); - BasinInventory inv = (BasinInventory) itemHandler; + if (world == null) + return; + basinItemInv.ifPresent(inv -> { + for (int slot = 0; slot < ((BasinInventory) inv).getInputHandler() + .getSlots(); slot++) { + ItemStack stackInSlot = inv.getStackInSlot(slot); + if (stackInSlot.isEmpty()) + continue; - for (int slot = 0; slot < inv.getInputHandler() - .getSlots(); slot++) { - ItemStack stackInSlot = itemHandler.getStackInSlot(slot); - if (stackInSlot.isEmpty()) - continue; + ItemParticleData data = new ItemParticleData(ParticleTypes.ITEM, stackInSlot); + float angle = world.rand.nextFloat() * 360; + Vec3d offset = new Vec3d(0, 0, 0.25f); + offset = VecHelper.rotate(offset, angle, Axis.Y); + Vec3d target = VecHelper.rotate(offset, getSpeed() > 0 ? 25 : -25, Axis.Y) + .add(0, .25f, 0); - ItemParticleData data = new ItemParticleData(ParticleTypes.ITEM, stackInSlot); - float angle = world.rand.nextFloat() * 360; - Vec3d offset = new Vec3d(0, 0, 0.25f); - offset = VecHelper.rotate(offset, angle, Axis.Y); - Vec3d target = VecHelper.rotate(offset, getSpeed() > 0 ? 25 : -25, Axis.Y) - .add(0, .25f, 0); + Vec3d center = offset.add(VecHelper.getCenterOf(pos)); + target = VecHelper.offsetRandomly(target.subtract(offset), world.rand, 1 / 128f); + world.addParticle(data, center.x, center.y - 2, center.z, target.x, target.y, target.z); + } + }); + + // Fluid Particles + /* + * basinFluidInv.ifPresent(fluidInv -> ((CombinedFluidHandler) + * fluidInv).forEachTank(fluidStack -> { if(fluidStack.isEmpty()) return; float + * angle = world.rand.nextFloat() * 360; Vec3d offset = new Vec3d(0, 0, 0.25f); + * offset = VecHelper.rotate(offset, angle, Axis.Y); Vec3d target = + * VecHelper.rotate(offset, getSpeed() > 0 ? 25 : -25, Axis.Y) .add(0, .25f, 0); + * + * Vec3d center = offset.add(VecHelper.getCenterOf(pos)); target = + * VecHelper.offsetRandomly(target.subtract(offset), world.rand, 1 / 128f); + * IParticleData data = new AirFlowParticleData(this.pos.down(2)); + * world.addParticle(data, center.x, center.y - 2, center.z, target.x, target.y, + * target.z); + * + * })); + */ - Vec3d center = offset.add(VecHelper.getCenterOf(pos)); - target = VecHelper.offsetRandomly(target.subtract(offset), world.rand, 1 / 128f); - world.addParticle(data, center.x, center.y - 2, center.z, target.x, target.y, target.z); - } } @Override @@ -195,14 +214,16 @@ public class MechanicalMixerTileEntity extends BasinOperatingTileEntity { .allMatch(ingredient -> (ingredient.isSimple() || ingredient.getMatchingStacks().length == 1))) return false; - List remaining = new ArrayList<>(); + CombinedItemFluidList remaining = new CombinedItemFluidList(); inputs.forEachItemStack(stack -> remaining.add(stack.copy())); + basinFluidInv.ifPresent( + fluidInv -> ((CombinedFluidHandler) fluidInv).forEachTank(fluidStack -> remaining.add(fluidStack.copy()))); // sort by leniency List sortedIngredients = new LinkedList<>(ingredients); sortedIngredients.sort(Comparator.comparingInt(i -> i.getMatchingStacks().length)); Ingredients: for (Ingredient ingredient : sortedIngredients) { - for (ItemStack stack : remaining) { + for (ItemStack stack : remaining.getItemStacks()) { if (stack.isEmpty()) continue; if (ingredient.test(stack)) { @@ -212,6 +233,9 @@ public class MechanicalMixerTileEntity extends BasinOperatingTileEntity { } return false; } + + if (!(recipe instanceof MixingRecipe)) + return true; return true; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixingRecipe.java index 58ee10ff0..adfac18fd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixingRecipe.java @@ -1,10 +1,14 @@ package com.simibubi.create.content.contraptions.components.mixer; + import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import javax.annotation.Nonnull; + import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.processing.BasinTileEntity.BasinInputInventory; import com.simibubi.create.content.contraptions.processing.ProcessingIngredient; @@ -17,36 +21,45 @@ import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidStack; public class MixingRecipe extends ProcessingRecipe { public MixingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration) { + List results, int processingDuration) { super(AllRecipeTypes.MIXING, id, group, ingredients, results, processingDuration); } + public MixingRecipe(ResourceLocation id, String group, List ingredients, + List results, int processingDuration, List fluidIngredients, + List fluidResults) { + super(AllRecipeTypes.MIXING, id, group, ingredients, results, processingDuration, fluidIngredients, + fluidResults); + } + @Override protected int getMaxInputCount() { return 9; } - + @Override protected int getMaxOutputCount() { return 1; } - + @Override protected boolean canHaveCatalysts() { return true; } - + @Override - public boolean matches(BasinInputInventory inv, World worldIn) { + public boolean matches(BasinInputInventory inv, @Nonnull World worldIn) { if (inv.isEmpty()) return false; - NonNullList ingredients = getIngredients(); - if (!ingredients.stream().allMatch(Ingredient::isSimple)) + NonNullList ingredients = this.getIngredients(); + if (!ingredients.stream() + .allMatch(Ingredient::isSimple)) return false; List remaining = new ArrayList<>(); @@ -59,7 +72,7 @@ public class MixingRecipe extends ProcessingRecipe { // sort by leniency List sortedIngredients = new LinkedList<>(ingredients); - sortedIngredients.sort((i1, i2) -> i1.getMatchingStacks().length - i2.getMatchingStacks().length); + sortedIngredients.sort(Comparator.comparingInt(i -> i.getMatchingStacks().length)); Ingredients: for (Ingredient ingredient : sortedIngredients) { for (ItemStack stack : remaining) { if (stack.isEmpty()) @@ -76,7 +89,16 @@ public class MixingRecipe extends ProcessingRecipe { public static MixingRecipe of(IRecipe recipe) { return new MixingRecipe(recipe.getId(), recipe.getGroup(), ProcessingIngredient.list(recipe.getIngredients()), - Arrays.asList(new ProcessingOutput(recipe.getRecipeOutput(), 1)), -1); + Collections.singletonList(new ProcessingOutput(recipe.getRecipeOutput(), 1)), -1); } + @Override + protected boolean canHaveFluidIngredient() { + return true; + } + + @Override + protected boolean canHaveFluidOutput() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java index e35e23ae7..94ffcfdd2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java @@ -6,8 +6,10 @@ import java.util.Optional; import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.content.contraptions.fluids.CombinedFluidHandler; import com.simibubi.create.content.contraptions.processing.BasinOperatingTileEntity; import com.simibubi.create.content.contraptions.processing.BasinTileEntity.BasinInventory; +import com.simibubi.create.content.contraptions.processing.CombinedItemFluidList; import com.simibubi.create.content.logistics.InWorldProcessing; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.item.ItemHelper; @@ -297,11 +299,12 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity { .allMatch(Ingredient::isSimple)) return false; - List remaining = new ArrayList<>(); + CombinedItemFluidList remaining = new CombinedItemFluidList(); inputs.forEachItemStack(stack -> remaining.add(stack.copy())); + basinFluidInv.ifPresent(fluidInv -> ((CombinedFluidHandler) fluidInv).forEachTank(fluidStack -> remaining.add(fluidStack.copy()))); Ingredients: for (Ingredient ingredient : ingredients) { - for (ItemStack stack : remaining) { + for (ItemStack stack : remaining.getItemStacks()) { if (stack.isEmpty()) continue; if (ingredient.test(stack)) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressingRecipe.java index c8efe3b34..a71395bc8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressingRecipe.java @@ -10,11 +10,16 @@ import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidStack; +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault public class PressingRecipe extends ProcessingRecipe { public PressingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration) { + List results, int processingDuration, List fluidIngredients, + List fluidResults) { super(AllRecipeTypes.PRESSING, id, group, ingredients, results, processingDuration); } @@ -22,12 +27,12 @@ public class PressingRecipe extends ProcessingRecipe { public CuttingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration) { + List results, int processingDuration, List fluidIngredients, + List fluidResults) { super(AllRecipeTypes.CUTTING, id, group, ingredients, results, processingDuration); } @@ -22,9 +27,10 @@ public class CuttingRecipe extends ProcessingRecipe { public boolean matches(RecipeWrapper inv, World worldIn) { if (inv.isEmpty()) return false; - return ingredients.get(0).test(inv.getStackInSlot(0)); + return ingredients.get(0) + .test(inv.getStackInSlot(0)); } - + @Override protected int getMaxOutputCount() { return 4; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java index 9fd313749..e127b162b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java @@ -248,7 +248,7 @@ public class SawTileEntity extends BlockBreakingKineticTileEntity { for (int roll = 0; roll < rolls; roll++) { List results = new LinkedList(); if (recipe instanceof CuttingRecipe) - results = ((CuttingRecipe) recipe).rollResults(); + results = ((CuttingRecipe) recipe).rollResults().getItemStacks(); else if (recipe instanceof StonecuttingRecipe) results.add(recipe.getRecipeOutput() .copy()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/CombinedFluidHandler.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/CombinedFluidHandler.java index 8d62457ea..d7ae0d73b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/CombinedFluidHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/CombinedFluidHandler.java @@ -1,6 +1,11 @@ package com.simibubi.create.content.contraptions.fluids; -import net.minecraft.fluid.Fluid; +import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import javax.annotation.Nonnull; + import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.ListNBT; import net.minecraft.util.math.MathHelper; @@ -8,11 +13,6 @@ import net.minecraftforge.common.util.NonNullConsumer; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; -import javax.annotation.Nonnull; -import java.util.Arrays; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - public class CombinedFluidHandler implements IFluidHandler { private final int capacity; private final FluidStack[] tanks; diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java index 492c3f106..18645dedd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinOperatingTileEntity.java @@ -37,7 +37,7 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { protected IRecipe lastRecipe; protected LazyOptional basinItemInv = LazyOptional.empty(); protected LazyOptional basinFluidInv = LazyOptional.empty(); - protected MultiIngredientTypeList inputs; + protected CombinedItemFluidList inputs; public BasinOperatingTileEntity(TileEntityType typeIn) { super(typeIn); @@ -59,7 +59,7 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity { } public void gatherInputs() { - inputs = new MultiIngredientTypeList(); + inputs = new CombinedItemFluidList(); basinItemInv.ifPresent(inv -> { IItemHandlerModifiable inputHandler = ((BasinInventory) inv).getInputHandler(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java index 78f4d7b95..f96fc6384 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java @@ -3,6 +3,8 @@ package com.simibubi.create.content.contraptions.processing; import java.util.List; import java.util.Optional; +import javax.annotation.Nonnull; + import com.simibubi.create.content.contraptions.fluids.CombinedFluidHandler; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; @@ -10,6 +12,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputB import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; @@ -24,8 +27,6 @@ import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.wrapper.CombinedInvWrapper; import net.minecraftforge.items.wrapper.RecipeWrapper; -import javax.annotation.Nonnull; - public class BasinTileEntity extends SmartTileEntity implements ITickableTileEntity { public boolean contentsChanged; @@ -121,7 +122,7 @@ public class BasinTileEntity extends SmartTileEntity implements ITickableTileEnt super.read(compound); inputItemInventory.deserializeNBT(compound.getCompound("InputItems")); outputItemInventory.deserializeNBT(compound.getCompound("OutputItems")); - if (compound.hasUniqueId("fluids")) + if (compound.contains("fluids")) fluidInventory .ifPresent(combinedFluidHandler -> combinedFluidHandler.readFromNBT(compound.getList("fluids", 10))); } @@ -131,7 +132,10 @@ public class BasinTileEntity extends SmartTileEntity implements ITickableTileEnt super.write(compound); compound.put("InputItems", inputItemInventory.serializeNBT()); compound.put("OutputItems", outputItemInventory.serializeNBT()); - fluidInventory.ifPresent(combinedFuidHandler -> compound.put("fluids", combinedFuidHandler.getListNBT())); + fluidInventory.ifPresent(combinedFuidHandler -> { + ListNBT nbt = combinedFuidHandler.getListNBT(); + compound.put("fluids", nbt); + }); return compound; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/MultiIngredientTypeList.java b/src/main/java/com/simibubi/create/content/contraptions/processing/CombinedItemFluidList.java similarity index 50% rename from src/main/java/com/simibubi/create/content/contraptions/processing/MultiIngredientTypeList.java rename to src/main/java/com/simibubi/create/content/contraptions/processing/CombinedItemFluidList.java index 1206bc283..f5eac96d6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/MultiIngredientTypeList.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/CombinedItemFluidList.java @@ -6,23 +6,31 @@ import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; import java.util.function.Consumer; -public class MultiIngredientTypeList { - private final ArrayList itemIngredients = new ArrayList<>(); - private final ArrayList fluidIngredients = new ArrayList<>(); +public class CombinedItemFluidList { + private final ArrayList itemStacks = new ArrayList<>(); + private final ArrayList fluidStacks = new ArrayList<>(); public void add(ItemStack itemstack) { - itemIngredients.add(itemstack); + itemStacks.add(itemstack); } public void add(FluidStack fluidStack) { - fluidIngredients.add(fluidStack); + fluidStacks.add(fluidStack); } public void forEachItemStack(Consumer itemStackConsumer) { - itemIngredients.forEach(itemStackConsumer); + itemStacks.forEach(itemStackConsumer); } public void forEachFluidStack(Consumer fluidStackConsumer) { - fluidIngredients.forEach(fluidStackConsumer); + fluidStacks.forEach(fluidStackConsumer); + } + + public ArrayList getItemStacks() { + return itemStacks; + } + + public ArrayList getFluidStacks() { + return fluidStacks; } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingOutput.java b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingOutput.java index aacc6d39c..186cf0b72 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingOutput.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingOutput.java @@ -7,9 +7,9 @@ import net.minecraft.network.PacketBuffer; public class ProcessingOutput { - private static Random r = new Random(); - private ItemStack stack; - private float chance; + private static final Random r = new Random(); + private final ItemStack stack; + private final float chance; public ProcessingOutput(ItemStack stack, float chance) { this.stack = stack; diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipe.java index ae665072a..8d93a2200 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipe.java @@ -1,12 +1,12 @@ package com.simibubi.create.content.contraptions.processing; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.Create; +import mcp.MethodsReturnNonnullByDefault; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; @@ -15,7 +15,13 @@ import net.minecraft.item.crafting.IRecipeType; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fluids.FluidStack; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault public abstract class ProcessingRecipe implements IRecipe { protected final List ingredients; private final List results; @@ -24,9 +30,11 @@ public abstract class ProcessingRecipe implements IRecipe< protected final ResourceLocation id; protected final String group; protected final int processingDuration; + protected final List fluidIngredients; + protected final List fluidResults; public ProcessingRecipe(AllRecipeTypes recipeType, ResourceLocation id, String group, - List ingredients, List results, int processingDuration) { + List ingredients, List results, int processingDuration) { this.type = recipeType.type; this.serializer = recipeType.serializer; this.id = id; @@ -34,20 +42,37 @@ public abstract class ProcessingRecipe implements IRecipe< this.ingredients = ingredients; this.results = results; this.processingDuration = processingDuration; + this.fluidIngredients = null; + this.fluidResults = null; + validate(recipeType); + } + + public ProcessingRecipe(AllRecipeTypes recipeType, ResourceLocation id, String group, + List ingredients, List results, int processingDuration, + @Nullable List fluidIngredients, @Nullable List fluidResults) { + this.type = recipeType.type; + this.serializer = recipeType.serializer; + this.id = id; + this.group = group; + this.ingredients = ingredients; + this.results = results; + this.processingDuration = processingDuration; + this.fluidIngredients = fluidIngredients; + this.fluidResults = fluidResults; validate(recipeType); } private void validate(AllRecipeTypes recipeType) { if (ingredients.size() > getMaxInputCount()) Create.logger.warn("Your custom " + recipeType.name() + " recipe (" + id.toString() + ") has more inputs (" - + ingredients.size() + ") than supported (" + getMaxInputCount() + ")."); + + ingredients.size() + ") than supported (" + getMaxInputCount() + ")."); if (results.size() > getMaxOutputCount()) Create.logger.warn("Your custom " + recipeType.name() + " recipe (" + id.toString() + ") has more outputs (" - + results.size() + ") than supported (" + getMaxOutputCount() + ")."); + + results.size() + ") than supported (" + getMaxOutputCount() + ")."); ingredients.forEach(i -> { if (i.isCatalyst() && !canHaveCatalysts()) Create.logger.warn("Your custom " + recipeType.name() + " recipe (" + id.toString() - + ") has a catalyst ingredient, which act like a regular ingredient in this type."); + + ") has a catalyst ingredient, which act like a regular ingredient in this type."); }); } @@ -62,14 +87,14 @@ public abstract class ProcessingRecipe implements IRecipe< return processingDuration; } - public List rollResults() { - List stacks = new ArrayList<>(); - for (ProcessingOutput output : getRollableResults()) { + public CombinedItemFluidList rollResults() { + CombinedItemFluidList results = new CombinedItemFluidList(); + for (ProcessingOutput output : getRollableItemResults()) { ItemStack stack = output.rollOutput(); if (!stack.isEmpty()) - stacks.add(stack); + results.add(stack); } - return stacks; + return results; } @Override @@ -84,7 +109,9 @@ public abstract class ProcessingRecipe implements IRecipe< @Override public ItemStack getRecipeOutput() { - return getRollableResults().isEmpty() ? ItemStack.EMPTY : getRollableResults().get(0).getStack(); + return getRollableItemResults().isEmpty() ? ItemStack.EMPTY + : getRollableItemResults().get(0) + .getStack(); } @Override @@ -119,15 +146,25 @@ public abstract class ProcessingRecipe implements IRecipe< return false; } - public List getRollableResults() { + public List getRollableItemResults() { return results; } - + public List getRollableIngredients() { return ingredients; } public List getPossibleOutputs() { - return getRollableResults().stream().map(output -> output.getStack()).collect(Collectors.toList()); + return getRollableItemResults().stream() + .map(ProcessingOutput::getStack) + .collect(Collectors.toList()); + } + + protected boolean canHaveFluidIngredient() { + return false; + } + + protected boolean canHaveFluidOutput() { + return false; } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeSerializer.java b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeSerializer.java index aff3b800f..a07dfb1e2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeSerializer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/ProcessingRecipeSerializer.java @@ -6,15 +6,23 @@ import java.util.List; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import mcp.MethodsReturnNonnullByDefault; +import net.minecraft.fluid.Fluid; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.network.PacketBuffer; import net.minecraft.util.JSONUtils; import net.minecraft.util.ResourceLocation; import net.minecraft.util.registry.Registry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.registries.ForgeRegistries; +import javax.annotation.ParametersAreNonnullByDefault; + +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault public class ProcessingRecipeSerializer> - extends net.minecraftforge.registries.ForgeRegistryEntry> implements IRecipeSerializer { + extends net.minecraftforge.registries.ForgeRegistryEntry> implements IRecipeSerializer { protected final IRecipeFactory factory; @@ -27,32 +35,58 @@ public class ProcessingRecipeSerializer> String s = JSONUtils.getString(json, "group", ""); List ingredients = new ArrayList<>(); + List fluidIngredients = new ArrayList<>(); for (JsonElement e : JSONUtils.getJsonArray(json, "ingredients")) { - int count = 1; - if (JSONUtils.hasField((JsonObject) e, "count")) { - count = JSONUtils.getInt(e.getAsJsonObject().get("count"), "count"); - } - for(int i = 0; i < count; i++) { - ingredients.add(ProcessingIngredient.parse(e.getAsJsonObject())); + JsonObject entry = e.getAsJsonObject(); + if (JSONUtils.hasField(entry, "fluid")) { + Fluid fluid = ForgeRegistries.FLUIDS + .getValue(ResourceLocation.tryCreate(JSONUtils.getString(entry.get("fluid"), "fluid"))); + int amount = 1; + if (JSONUtils.hasField((JsonObject) e, "amount")) { + amount = JSONUtils.getInt(entry.get("amount"), "amount"); + } + if (fluid != null && amount > 0) + fluidIngredients.add(new FluidStack(fluid, amount)); + } else { + int count = 1; + if (JSONUtils.hasField((JsonObject) e, "count")) { + count = JSONUtils.getInt(entry.get("count"), "count"); + } + for (int i = 0; i < count; i++) { + ingredients.add(ProcessingIngredient.parse(entry)); + } } } List results = new ArrayList<>(); + List fluidResults = new ArrayList<>(); for (JsonElement e : JSONUtils.getJsonArray(json, "results")) { - String s1 = JSONUtils.getString(e.getAsJsonObject().get("item"), "item"); - int i = JSONUtils.getInt(e.getAsJsonObject().get("count"), "count"); - float chance = 1; - if (JSONUtils.hasField((JsonObject) e, "chance")) - chance = JSONUtils.getFloat(e.getAsJsonObject().get("chance"), "chance"); - ItemStack itemstack = new ItemStack(Registry.ITEM.getOrDefault(new ResourceLocation(s1)), i); - results.add(new ProcessingOutput(itemstack, chance)); + JsonObject entry = e.getAsJsonObject(); + if (JSONUtils.hasField(entry, "fluid")) { + Fluid fluid = ForgeRegistries.FLUIDS + .getValue(ResourceLocation.tryCreate(JSONUtils.getString(entry.get("fluid"), "fluid"))); + int amount = 1; + if (JSONUtils.hasField((JsonObject) e, "amount")) { + amount = JSONUtils.getInt(entry.get("amount"), "amount"); + } + if (fluid != null && amount > 0) + fluidResults.add(new FluidStack(fluid, amount)); + } else { + String s1 = JSONUtils.getString(entry.get("item"), "item"); + int i = JSONUtils.getInt(entry.get("count"), "count"); + float chance = 1; + if (JSONUtils.hasField((JsonObject) e, "chance")) + chance = JSONUtils.getFloat(entry.get("chance"), "chance"); + ItemStack itemstack = new ItemStack(Registry.ITEM.getOrDefault(new ResourceLocation(s1)), i); + results.add(new ProcessingOutput(itemstack, chance)); + } } int duration = -1; if (JSONUtils.hasField(json, "processingTime")) duration = JSONUtils.getInt(json, "processingTime"); - return this.factory.create(recipeId, s, ingredients, results, duration); + return this.factory.create(recipeId, s, ingredients, results, duration, fluidIngredients, fluidResults); } public T read(ResourceLocation recipeId, PacketBuffer buffer) { @@ -63,14 +97,24 @@ public class ProcessingRecipeSerializer> for (int i = 0; i < ingredientCount; i++) ingredients.add(ProcessingIngredient.parse(buffer)); + int fluidInputCount = buffer.readInt(); + List fluidIngredients = new ArrayList<>(); + for (int i = 0; i < fluidInputCount; i++) + fluidIngredients.add(FluidStack.readFromPacket(buffer)); + List results = new ArrayList<>(); int outputCount = buffer.readInt(); for (int i = 0; i < outputCount; i++) results.add(ProcessingOutput.read(buffer)); + int fluidOutputCount = buffer.readInt(); + List fluidResults = new ArrayList<>(); + for (int i = 0; i < fluidOutputCount; i++) + fluidResults.add(FluidStack.readFromPacket(buffer)); + int duration = buffer.readInt(); - return this.factory.create(recipeId, s, ingredients, results, duration); + return this.factory.create(recipeId, s, ingredients, results, duration, fluidIngredients, fluidResults); } public void write(PacketBuffer buffer, T recipe) { @@ -78,16 +122,31 @@ public class ProcessingRecipeSerializer> buffer.writeInt(recipe.ingredients.size()); recipe.ingredients.forEach(i -> i.write(buffer)); + if (recipe.canHaveFluidIngredient() && recipe.fluidIngredients != null) { + buffer.writeInt(recipe.fluidIngredients.size()); + recipe.fluidIngredients.forEach(fluidStack -> fluidStack.writeToPacket(buffer)); + } else { + buffer.writeInt(0); + } - buffer.writeInt(recipe.getRollableResults().size()); - recipe.getRollableResults().forEach(i -> i.write(buffer)); + buffer.writeInt(recipe.getRollableItemResults() + .size()); + recipe.getRollableItemResults() + .forEach(i -> i.write(buffer)); + if (recipe.canHaveFluidOutput() && recipe.fluidResults != null) { + buffer.writeInt(recipe.fluidResults.size()); + recipe.fluidResults.forEach(fluidStack -> fluidStack.writeToPacket(buffer)); + } else { + buffer.writeInt(0); + } buffer.writeInt(recipe.processingDuration); } public interface IRecipeFactory> { - T create(ResourceLocation id, String group, List ingredients, List results, - int duration); + T create(ResourceLocation recipeId, String s, List ingredients, + List results, int duration, List fluidIngredients, + List fluidResults); } } diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItem.java b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItem.java index c1c4c7f0f..d06c16b4c 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItem.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.curiosities.tools; import com.simibubi.create.foundation.utility.VecHelper; +import mcp.MethodsReturnNonnullByDefault; import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.item.ItemEntity; @@ -24,6 +25,10 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; +import javax.annotation.ParametersAreNonnullByDefault; + +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault public class SandPaperItem extends Item { public SandPaperItem(Properties properties) { @@ -68,8 +73,6 @@ public class SandPaperItem extends Item { return FAIL; BlockRayTraceResult ray = (BlockRayTraceResult) raytraceresult; Vec3d hitVec = ray.getHitVec(); - if (hitVec == null) - return FAIL; AxisAlignedBB bb = new AxisAlignedBB(hitVec, hitVec).grow(1f); ItemEntity pickUp = null; diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperPolishingRecipe.java b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperPolishingRecipe.java index b4e588e8a..b65e57c7e 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperPolishingRecipe.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperPolishingRecipe.java @@ -10,19 +10,21 @@ import com.simibubi.create.content.curiosities.tools.SandPaperPolishingRecipe.Sa import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.DamageSource; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.wrapper.RecipeWrapper; +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault public class SandPaperPolishingRecipe extends ProcessingRecipe { - public static DamageSource CURSED_POLISHING = new DamageSource("create.curse_polish").setExplosion(); - public SandPaperPolishingRecipe(ResourceLocation id, String group, List ingredients, - List results, int processingDuration) { + List results, int processingDuration, List fluidIngredients, + List fluidResults) { super(AllRecipeTypes.SANDPAPER_POLISHING, id, group, ingredients, results, processingDuration); } @@ -33,18 +35,21 @@ public class SandPaperPolishingRecipe extends ProcessingRecipe { public static ItemStack applyPolish(World world, Vec3d position, ItemStack stack, ItemStack sandPaperStack) { List> matchingRecipes = getMatchingRecipes(world, stack); if (!matchingRecipes.isEmpty()) - return matchingRecipes.get(0).getCraftingResult(new SandPaperInv(stack)).copy(); + return matchingRecipes.get(0) + .getCraftingResult(new SandPaperInv(stack)) + .copy(); return stack; } @Override public boolean matches(SandPaperInv inv, World worldIn) { - return ingredients.get(0).test(inv.getStackInSlot(0)); + return ingredients.get(0) + .test(inv.getStackInSlot(0)); } public static List> getMatchingRecipes(World world, ItemStack stack) { - return world.getRecipeManager().getRecipes(AllRecipeTypes.SANDPAPER_POLISHING.getType(), new SandPaperInv(stack), - world); + return world.getRecipeManager() + .getRecipes(AllRecipeTypes.SANDPAPER_POLISHING.getType(), new SandPaperInv(stack), world); } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java b/src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java index b2765dd7d..9aa814255 100644 --- a/src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java +++ b/src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java @@ -263,7 +263,7 @@ public class InWorldProcessing { if (recipe instanceof ProcessingRecipe) { stacks = new ArrayList<>(); for (int i = 0; i < stackIn.getCount(); i++) { - List rollResults = ((ProcessingRecipe) recipe).rollResults(); + List rollResults = ((ProcessingRecipe) recipe).rollResults().getItemStacks(); for (ItemStack stack : rollResults) { for (ItemStack previouslyRolled : stacks) { if (stack.isEmpty())