forked from Creators-of-Create/Create
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Crushing wheels can now apply recipes to contained items - Added a new generic recipe type for processing - Improved Crushing Wheel model - Improved gui models of large wheels - Improved gui models of harvesters and drills - Added several crushing recipes - Fixed Water wheel updating rotation speeds incosistently
- Loading branch information
Showing
68 changed files
with
2,059 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/com/simibubi/create/modules/contraptions/base/ProcessingRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.simibubi.create.modules.contraptions.base; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.simibubi.create.AllRecipes; | ||
|
||
import net.minecraft.inventory.IInventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.crafting.IRecipe; | ||
import net.minecraft.item.crafting.IRecipeSerializer; | ||
import net.minecraft.item.crafting.IRecipeType; | ||
import net.minecraft.item.crafting.Ingredient; | ||
import net.minecraft.util.NonNullList; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
public abstract class ProcessingRecipe<T extends IInventory> implements IRecipe<T> { | ||
protected final List<Ingredient> ingredients; | ||
protected final List<StochasticOutput> results; | ||
private final IRecipeType<?> type; | ||
private final IRecipeSerializer<?> serializer; | ||
protected final ResourceLocation id; | ||
protected final String group; | ||
protected final int processingDuration; | ||
|
||
public ProcessingRecipe(AllRecipes recipeType, ResourceLocation id, String group, | ||
List<Ingredient> ingredients, List<StochasticOutput> results, int processingDuration) { | ||
this.type = recipeType.type; | ||
this.serializer = recipeType.serializer; | ||
this.id = id; | ||
this.group = group; | ||
this.ingredients = ingredients; | ||
this.results = results; | ||
this.processingDuration = processingDuration; | ||
} | ||
|
||
@Override | ||
public NonNullList<Ingredient> getIngredients() { | ||
NonNullList<Ingredient> nonnulllist = NonNullList.create(); | ||
nonnulllist.addAll(this.ingredients); | ||
return nonnulllist; | ||
} | ||
|
||
public int getProcessingDuration() { | ||
return processingDuration; | ||
} | ||
|
||
public List<StochasticOutput> getAllResults() { | ||
return results; | ||
} | ||
|
||
public List<ItemStack> rollResults() { | ||
List<ItemStack> stacks = new ArrayList<>(); | ||
for (StochasticOutput output : results) { | ||
ItemStack stack = output.rollOutput(); | ||
if (!stack.isEmpty()) | ||
stacks.add(stack); | ||
} | ||
return stacks; | ||
} | ||
|
||
@Override | ||
public ItemStack getCraftingResult(T inv) { | ||
return getRecipeOutput(); | ||
} | ||
|
||
@Override | ||
public boolean canFit(int width, int height) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ItemStack getRecipeOutput() { | ||
return results.isEmpty() ? ItemStack.EMPTY : results.get(0).getStack(); | ||
} | ||
|
||
@Override | ||
public ResourceLocation getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public IRecipeSerializer<?> getSerializer() { | ||
return serializer; | ||
} | ||
|
||
@Override | ||
public String getGroup() { | ||
return group; | ||
} | ||
|
||
@Override | ||
public IRecipeType<?> getType() { | ||
return type; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/com/simibubi/create/modules/contraptions/base/ProcessingRecipeSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.simibubi.create.modules.contraptions.base; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.crafting.IRecipeSerializer; | ||
import net.minecraft.item.crafting.Ingredient; | ||
import net.minecraft.network.PacketBuffer; | ||
import net.minecraft.util.JSONUtils; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
public class ProcessingRecipeSerializer<T extends ProcessingRecipe<?>> | ||
extends net.minecraftforge.registries.ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<T> { | ||
|
||
protected final IRecipeFactory<T> factory; | ||
|
||
public ProcessingRecipeSerializer(IRecipeFactory<T> factory) { | ||
this.factory = factory; | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
public T read(ResourceLocation recipeId, JsonObject json) { | ||
String s = JSONUtils.getString(json, "group", ""); | ||
|
||
List<Ingredient> ingredients = new ArrayList<>(); | ||
for (JsonElement e : JSONUtils.getJsonArray(json, "ingredients")) { | ||
ingredients.add(Ingredient.deserialize(e)); | ||
} | ||
|
||
List<StochasticOutput> results = 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 StochasticOutput(itemstack, chance)); | ||
} | ||
|
||
int duration = JSONUtils.getInt(json, "processingTime"); | ||
|
||
return this.factory.create(recipeId, s, ingredients, results, duration); | ||
} | ||
|
||
public T read(ResourceLocation recipeId, PacketBuffer buffer) { | ||
String s = buffer.readString(32767); | ||
|
||
List<Ingredient> ingredients = new ArrayList<>(); | ||
for (int i = 0; i < buffer.readInt(); i++) | ||
ingredients.add(Ingredient.read(buffer)); | ||
|
||
List<StochasticOutput> results = new ArrayList<>(); | ||
for (int i = 0; i < buffer.readInt(); i++) | ||
results.add(StochasticOutput.read(buffer)); | ||
|
||
int duration = buffer.readInt(); | ||
|
||
return this.factory.create(recipeId, s, ingredients, results, duration); | ||
} | ||
|
||
public void write(PacketBuffer buffer, T recipe) { | ||
buffer.writeString(recipe.group); | ||
|
||
buffer.writeInt(recipe.ingredients.size()); | ||
recipe.ingredients.forEach(i -> i.write(buffer)); | ||
|
||
buffer.writeInt(recipe.results.size()); | ||
recipe.results.forEach(i -> i.write(buffer)); | ||
|
||
buffer.writeInt(recipe.processingDuration); | ||
} | ||
|
||
public interface IRecipeFactory<T extends ProcessingRecipe<?>> { | ||
T create(ResourceLocation id, String group, List<Ingredient> ingredients, List<StochasticOutput> results, int duration); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/simibubi/create/modules/contraptions/base/StochasticOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.simibubi.create.modules.contraptions.base; | ||
|
||
import java.util.Random; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.network.PacketBuffer; | ||
|
||
public class StochasticOutput { | ||
|
||
private static Random r = new Random(); | ||
private ItemStack stack; | ||
private float chance; | ||
|
||
public StochasticOutput(ItemStack stack, float chance) { | ||
this.stack = stack; | ||
this.chance = chance; | ||
} | ||
|
||
public ItemStack getStack() { | ||
return stack; | ||
} | ||
|
||
public float getChance() { | ||
return chance; | ||
} | ||
|
||
public ItemStack rollOutput() { | ||
int outputAmount = stack.getCount(); | ||
for (int roll = 0; roll < stack.getCount(); roll++) | ||
if (r.nextFloat() > chance) | ||
outputAmount--; | ||
return outputAmount > 0 ? new ItemStack(stack.getItem(), outputAmount) : ItemStack.EMPTY; | ||
} | ||
|
||
public void write(PacketBuffer buf) { | ||
buf.writeItemStack(getStack()); | ||
buf.writeFloat(getChance()); | ||
} | ||
|
||
public static StochasticOutput read(PacketBuffer buf) { | ||
return new StochasticOutput(buf.readItemStack(), buf.readFloat()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/simibubi/create/modules/contraptions/receivers/CrushingRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.simibubi.create.modules.contraptions.receivers; | ||
|
||
import java.util.List; | ||
|
||
import com.simibubi.create.AllRecipes; | ||
import com.simibubi.create.modules.contraptions.base.ProcessingRecipe; | ||
import com.simibubi.create.modules.contraptions.base.StochasticOutput; | ||
import com.simibubi.create.modules.contraptions.receivers.CrushingWheelControllerTileEntity.Inventory; | ||
|
||
import net.minecraft.item.crafting.Ingredient; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.world.World; | ||
|
||
public class CrushingRecipe extends ProcessingRecipe<CrushingWheelControllerTileEntity.Inventory> { | ||
|
||
public CrushingRecipe(ResourceLocation id, String group, List<Ingredient> ingredients, | ||
List<StochasticOutput> results, int processingDuration) { | ||
super(AllRecipes.Crushing, id, group, ingredients, results, processingDuration); | ||
} | ||
|
||
@Override | ||
public boolean matches(Inventory inv, World worldIn) { | ||
if (inv.isEmpty()) | ||
return false; | ||
return ingredients.get(0).test(inv.getStackInSlot(0)); | ||
} | ||
|
||
} |
Oops, something went wrong.