mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
First pass at the coal generator, and its backing "solid_fuel" json recipes.
This commit is contained in:
parent
4d8f76a463
commit
4cb639a94a
11 changed files with 295 additions and 18 deletions
|
@ -710,6 +710,8 @@ a63b57c27d8548ddd13d64d18b098d4f5c127a30 data/actuallyadditions/recipes/restonia
|
|||
85d2537a973d520c9eaaf2f15109c265faa2df3a data/actuallyadditions/recipes/rice_slime_potion.json
|
||||
d4ca5d77d16ff6fdfc60e665694fdd97bce25463 data/actuallyadditions/recipes/shock_suppressor.json
|
||||
655fab699bb97ec252deb61d91fbef6f4738fe1c data/actuallyadditions/recipes/single_battery.json
|
||||
f4b41a12da3d0d24f155a6fb0fc170eeea9947b0 data/actuallyadditions/recipes/solid_fuel/charcoal.json
|
||||
ddae8379266c710a96811ab1d68bfb9973db7515 data/actuallyadditions/recipes/solid_fuel/coal.json
|
||||
8ebd738f3968564e22ba6841eb821e5064c78588 data/actuallyadditions/recipes/stone_aiot.json
|
||||
bc7a41d9f36cc43e146e0b727b6f439cc0d29343 data/actuallyadditions/recipes/teleport_staff.json
|
||||
bdf7dbf563485903e444400d341e56d0bf308481 data/actuallyadditions/recipes/tiny_torch.json
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"type": "actuallyadditions:solid_fuel",
|
||||
"item": {
|
||||
"item": "minecraft:charcoal"
|
||||
},
|
||||
"total_energy": 1600,
|
||||
"burn_time": 48000
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"type": "actuallyadditions:solid_fuel",
|
||||
"item": {
|
||||
"item": "minecraft:coal"
|
||||
},
|
||||
"total_energy": 1600,
|
||||
"burn_time": 48000
|
||||
}
|
|
@ -21,6 +21,7 @@ import de.ellpeck.actuallyadditions.api.lens.LensConversion;
|
|||
import de.ellpeck.actuallyadditions.api.recipe.*;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.SolidFuelRecipe;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -45,6 +46,8 @@ public final class ActuallyAdditionsAPI {
|
|||
public static final List<LensConversionRecipe> RECONSTRUCTOR_LENS_CONVERSION_RECIPES = new ArrayList<>();
|
||||
public static final List<EmpowererRecipe> EMPOWERER_RECIPES = new ArrayList<>();
|
||||
public static final Map<Item, IColorLensChanger> RECONSTRUCTOR_LENS_COLOR_CHANGERS = new HashMap<>();
|
||||
|
||||
public static final List<SolidFuelRecipe> SOLID_FUEL_RECIPES = new ArrayList<>();
|
||||
/**
|
||||
* Farmer behaviors are sorted when first accessed, this will not be done until after loading, but do not add behaviors at runtime.
|
||||
*/
|
||||
|
|
|
@ -36,6 +36,7 @@ public class ActuallyAdditionsData {
|
|||
generator.addProvider(new LaserRecipeGenerator(generator));
|
||||
generator.addProvider(new EmpoweringRecipeGenerator(generator));
|
||||
generator.addProvider(new CrushingRecipeGenerator(generator));
|
||||
generator.addProvider(new SolidFuelGenerator(generator));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package de.ellpeck.actuallyadditions.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.SolidFuelRecipe;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
import net.minecraft.data.IFinishedRecipe;
|
||||
import net.minecraft.data.RecipeProvider;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SolidFuelGenerator extends RecipeProvider {
|
||||
public SolidFuelGenerator(DataGenerator pGenerator) {
|
||||
super(pGenerator);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdvancement(DirectoryCache pCache, JsonObject pAdvancementJson, Path pPath) {
|
||||
//Nah
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildShapelessRecipes(Consumer<IFinishedRecipe> consumer) {
|
||||
addFuel(consumer, "coal", Items.COAL, 48000, 1600);
|
||||
addFuel(consumer, "charcoal", Items.CHARCOAL, 48000, 1600);
|
||||
}
|
||||
|
||||
private void addFuel(Consumer<IFinishedRecipe> consumer, String name, Item item, int energy, int burnTime) {
|
||||
consumer.accept(new SolidFuelRecipe.FinishedRecipe(new ResourceLocation(ActuallyAdditions.MODID, "solid_fuel/"+name), Ingredient.of(item), burnTime, energy));
|
||||
}
|
||||
private void addFuel(Consumer<IFinishedRecipe> consumer, String name, Ingredient item, int energy, int burnTime) {
|
||||
consumer.accept(new SolidFuelRecipe.FinishedRecipe(new ResourceLocation(ActuallyAdditions.MODID, "solid_fuel/"+name), item, burnTime, energy));
|
||||
}
|
||||
private void addFuel(Consumer<IFinishedRecipe> consumer, String name, ITag tag, int energy, int burnTime) {
|
||||
consumer.accept(new SolidFuelRecipe.FinishedRecipe(new ResourceLocation(ActuallyAdditions.MODID, "solid_fuel/"+name), Ingredient.of(tag), burnTime, energy));
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ public class ActuallyRecipes {
|
|||
public static final RegistryObject<IRecipeSerializer<?>> LASER_RECIPE = SERIALIZERS.register(LaserRecipe.NAME, LaserRecipe.Serializer::new);
|
||||
public static final RegistryObject<IRecipeSerializer<?>> EMPOWERING_RECIPE = SERIALIZERS.register(EmpowererRecipe.NAME, EmpowererRecipe.Serializer::new);
|
||||
public static final RegistryObject<IRecipeSerializer<?>> CRUSHING_RECIPE = SERIALIZERS.register(CrushingRecipe.NAME, CrushingRecipe.Serializer::new);
|
||||
public static final RegistryObject<IRecipeSerializer<?>> SOLID_FUEL_RECIPE = SERIALIZERS.register(SolidFuelRecipe.NAME, SolidFuelRecipe.Serializer::new);
|
||||
|
||||
|
||||
|
||||
|
@ -26,7 +27,7 @@ public class ActuallyRecipes {
|
|||
public static final IRecipeType<LaserRecipe> LASER = IRecipeType.register(ActuallyAdditions.MODID + ":laser");
|
||||
public static final IRecipeType<EmpowererRecipe> EMPOWERING = IRecipeType.register(ActuallyAdditions.MODID + ":empower");
|
||||
public static final IRecipeType<CrushingRecipe> CRUSHING = IRecipeType.register(ActuallyAdditions.MODID + ":crushing");
|
||||
//public static final IRecipeType<SolidFuelRecipe> SOLIDFUEL = IRecipeType.register(ActuallyAdditions.MODID + ":solid_fuel");
|
||||
public static final IRecipeType<SolidFuelRecipe> SOLID_FUEL = IRecipeType.register(ActuallyAdditions.MODID + ":solid_fuel");
|
||||
//public static final IRecipeType<LiquidFuelRecipe> LIQUIDFUEL = IRecipeType.register(ActuallyAdditions.MODID + ":liquid_fuel");
|
||||
//public static final IRecipeType<PressingRecipe> PRESSING = IRecipeType.register(ActuallyAdditions.MODID + ":pressing");
|
||||
//public static final IRecipeType<FermentingRecipe> FERMENTING = IRecipeType.register(ActuallyAdditions.MODID + ":fermenting");
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package de.ellpeck.actuallyadditions.mod.crafting;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class SingleItem implements IInventory {
|
||||
private final ItemStack itemStack;
|
||||
|
||||
public SingleItem(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int pIndex) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(int pIndex, int pCount) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItemNoUpdate(int pIndex) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int pIndex, ItemStack pStack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(PlayerEntity pPlayer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
package de.ellpeck.actuallyadditions.mod.crafting;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.IFinishedRecipe;
|
||||
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.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class SolidFuelRecipe implements IRecipe<SingleItem> {
|
||||
public static String NAME = "solid_fuel";
|
||||
private Ingredient itemIngredient;
|
||||
private int burnTime;
|
||||
private int totalEnergy;
|
||||
private ResourceLocation id;
|
||||
|
||||
public SolidFuelRecipe(ResourceLocation id, Ingredient itemIngredient, int totalEnergy, int burnTime) {
|
||||
this.itemIngredient = itemIngredient;
|
||||
this.burnTime = burnTime;
|
||||
this.totalEnergy = totalEnergy;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getBurnTime() {
|
||||
return burnTime;
|
||||
}
|
||||
|
||||
public int getTotalEnergy() {
|
||||
return totalEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(SingleItem pInv, @Nullable World pLevel) {
|
||||
return itemIngredient.test(pInv.getItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack assemble(SingleItem pInv) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraftInDimensions(int pWidth, int pHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResultItem() {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return ActuallyRecipes.SOLID_FUEL_RECIPE.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeType<?> getType() {
|
||||
return ActuallyRecipes.Types.SOLID_FUEL;
|
||||
}
|
||||
|
||||
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<SolidFuelRecipe> {
|
||||
@Override
|
||||
public SolidFuelRecipe fromJson(ResourceLocation pId, JsonObject pJson) {
|
||||
Ingredient itemIngredient = Ingredient.fromJson(pJson.get("item"));
|
||||
int totalEnergy = pJson.get("total_energy").getAsInt();
|
||||
int burnTime = pJson.get("burn_time").getAsInt();
|
||||
return new SolidFuelRecipe(pId, itemIngredient, totalEnergy, burnTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolidFuelRecipe fromNetwork(ResourceLocation pId, PacketBuffer pBuffer) {
|
||||
Ingredient itemIngredient = Ingredient.fromNetwork(pBuffer);
|
||||
int totalEnergy = pBuffer.readInt();
|
||||
int burnTime = pBuffer.readInt();
|
||||
return new SolidFuelRecipe(pId, itemIngredient, totalEnergy, burnTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toNetwork(PacketBuffer pBuffer, SolidFuelRecipe pRecipe) {
|
||||
pRecipe.itemIngredient.toNetwork(pBuffer);
|
||||
pBuffer.writeInt(pRecipe.totalEnergy);
|
||||
pBuffer.writeInt(pRecipe.burnTime);
|
||||
}
|
||||
}
|
||||
|
||||
public static class FinishedRecipe implements IFinishedRecipe {
|
||||
private Ingredient itemIngredient;
|
||||
private int burnTime;
|
||||
private int totalEnergy;
|
||||
private ResourceLocation id;
|
||||
|
||||
public FinishedRecipe(ResourceLocation id, Ingredient itemIngredient, int totalEnergy, int burnTime) {
|
||||
this.itemIngredient = itemIngredient;
|
||||
this.burnTime = burnTime;
|
||||
this.totalEnergy = totalEnergy;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeRecipeData(JsonObject pJson) {
|
||||
pJson.add("item", itemIngredient.toJson());
|
||||
pJson.addProperty("total_energy", totalEnergy);
|
||||
pJson.addProperty("burn_time", burnTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getType() {
|
||||
return ActuallyRecipes.SOLID_FUEL_RECIPE.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JsonObject serializeAdvancement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getAdvancementId() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,8 +10,11 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.tile;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.SingleItem;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.SolidFuelRecipe;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerCoalGenerator;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
||||
|
@ -30,11 +33,13 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.common.util.RecipeMatcher;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase.NBTType;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
public class TileEntityCoalGenerator extends TileEntityInventoryBase implements INamedContainerProvider, ISharingEnergyProvider {
|
||||
|
||||
|
@ -46,8 +51,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
|||
private int lastBurnTime;
|
||||
private int lastCurrentBurnTime;
|
||||
private int lastCompare;
|
||||
private ItemStack curStack = ItemStack.EMPTY;
|
||||
private int curBurn = -1;
|
||||
private SolidFuelRecipe currentRecipe = null;
|
||||
|
||||
public TileEntityCoalGenerator() {
|
||||
super(ActuallyBlocks.COAL_GENERATOR.getTileEntityType(), 1);
|
||||
|
@ -89,27 +93,27 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
|||
if (!this.level.isClientSide) {
|
||||
boolean flag = this.currentBurnTime > 0;
|
||||
|
||||
if (this.currentBurnTime > 0) {
|
||||
if (this.currentBurnTime > 0 && currentRecipe != null) {
|
||||
this.currentBurnTime--;
|
||||
int produce = ConfigIntValues.COAL_GENERATOR_CF_PRODUCTION.getValue();
|
||||
int produce = currentRecipe.getTotalEnergy() / currentRecipe.getBurnTime();
|
||||
if (produce > 0) {
|
||||
this.storage.addEnergyRaw(produce);
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack stack = this.inv.getStackInSlot(0);
|
||||
if (!stack.isEmpty() && stack != this.curStack) {
|
||||
this.curStack = stack;
|
||||
this.curBurn = ForgeHooks.getBurnTime(stack);
|
||||
} else if (stack.isEmpty()) {
|
||||
this.curStack = ItemStack.EMPTY;
|
||||
this.curBurn = -1;
|
||||
}
|
||||
|
||||
if (!this.isRedstonePowered && this.currentBurnTime <= 0 && this.curBurn > 0 && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()) {
|
||||
this.maxBurnTime = this.curBurn;
|
||||
this.currentBurnTime = this.curBurn;
|
||||
this.inv.setStackInSlot(0, StackUtil.shrinkForContainer(stack, 1));
|
||||
if (!this.isRedstonePowered && this.currentBurnTime <= 0 && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()) {
|
||||
ItemStack stack = this.inv.getStackInSlot(0);
|
||||
if (!stack.isEmpty()) {
|
||||
for (SolidFuelRecipe fuelRecipe : ActuallyAdditionsAPI.SOLID_FUEL_RECIPES) {
|
||||
if (fuelRecipe.matches(new SingleItem(stack), null)) {
|
||||
this.currentRecipe = fuelRecipe;
|
||||
this.maxBurnTime = fuelRecipe.getBurnTime();
|
||||
this.currentBurnTime = this.maxBurnTime;
|
||||
this.inv.setStackInSlot(0, StackUtil.shrinkForContainer(stack, 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag != this.currentBurnTime > 0 || this.lastCompare != this.getComparatorStrength()) {
|
||||
|
|
|
@ -22,5 +22,8 @@ public class ResourceReloader implements ISelectiveResourceReloadListener {
|
|||
RecipeManager recipeManager = data.getRecipeManager();
|
||||
ActuallyAdditionsAPI.EMPOWERER_RECIPES.clear();
|
||||
ActuallyAdditionsAPI.EMPOWERER_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.EMPOWERING));
|
||||
|
||||
ActuallyAdditionsAPI.SOLID_FUEL_RECIPES.clear();
|
||||
ActuallyAdditionsAPI.SOLID_FUEL_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.SOLID_FUEL));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue