mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 03:15:07 +00:00
Move pure daisy to json, clean up block input handling slightly
Change input format for mana infusion catalysts Shorten JEI pure daisy windows a bit to fit more at once
This commit is contained in:
1 parent
e7d1bc2b4b
commit
15d0a8a219
124 files changed
+817
-263
No files matched your search
@@ -32,10 +32,7 @@ import vazkii.botania.api.internal.IInternalMethodHandler;
|
||||
import vazkii.botania.api.item.IExoflameHeatable;
|
||||
import vazkii.botania.api.item.IFloatingFlower;
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.api.recipe.RecipeManaInfusion;
|
||||
import vazkii.botania.api.recipe.RecipePetals;
|
||||
import vazkii.botania.api.recipe.RecipePureDaisy;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
import vazkii.botania.common.core.handler.PixieHandler;
|
||||
|
||||
@@ -61,7 +58,6 @@ public final class BotaniaAPI {
|
||||
* These maps are not meant to be mutated!
|
||||
*/
|
||||
public static Map<ResourceLocation, RecipePetals> petalRecipes = Collections.emptyMap();
|
||||
public static Map<ResourceLocation, RecipePureDaisy> pureDaisyRecipes = Collections.emptyMap();
|
||||
public static Map<ResourceLocation, RecipeRuneAltar> runeAltarRecipes = Collections.emptyMap();
|
||||
public static Map<ResourceLocation, RecipeBrew> brewRecipes = Collections.emptyMap();
|
||||
|
||||
|
||||
@@ -153,15 +153,9 @@ public class RecipeManaInfusion implements IRecipe<IInventory> {
|
||||
ItemStack output = CraftingHelper.getItemStack(JSONUtils.getJsonObject(json, "output"), true);
|
||||
int mana = JSONUtils.getInt(json, "mana");
|
||||
String group = JSONUtils.getString(json, "group", "");
|
||||
String catalyst = JSONUtils.getString(json, "catalyst", "");
|
||||
BlockState catalystState = null;
|
||||
if (!catalyst.isEmpty()) {
|
||||
try {
|
||||
BlockStateParser parser = new BlockStateParser(new StringReader(catalyst), false).parse(false);
|
||||
catalystState = parser.getState();
|
||||
} catch (CommandSyntaxException e) {
|
||||
throw new JsonParseException("Failure reading catalyst state", e);
|
||||
}
|
||||
if (json.has("catalyst")) {
|
||||
catalystState = StateIngredient.readBlockState(json.getAsJsonObject("catalyst"));
|
||||
}
|
||||
|
||||
RecipeManaInfusion ret = new RecipeManaInfusion(id, output, ing, mana, group);
|
||||
|
||||
@@ -9,29 +9,38 @@
|
||||
package vazkii.botania.api.recipe;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
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.network.PacketBuffer;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
import vazkii.botania.api.subtile.TileEntitySpecialFlower;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
|
||||
public class RecipePureDaisy {
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class RecipePureDaisy implements IRecipe<IInventory> {
|
||||
|
||||
public static final int DEFAULT_TIME = 150;
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final Object input;
|
||||
private final StateIngredient input;
|
||||
private final BlockState outputState;
|
||||
private final int time;
|
||||
|
||||
public RecipePureDaisy(ResourceLocation id, Object input, BlockState state) {
|
||||
public RecipePureDaisy(ResourceLocation id, StateIngredient input, BlockState state) {
|
||||
this(id, input, state, DEFAULT_TIME);
|
||||
}
|
||||
|
||||
@@ -43,37 +52,19 @@ public class RecipePureDaisy {
|
||||
* total time.
|
||||
* The Pure Daisy only ticks one block at a time in a round robin fashion.
|
||||
*/
|
||||
public RecipePureDaisy(ResourceLocation id, Object input, BlockState state, int time) {
|
||||
public RecipePureDaisy(ResourceLocation id, StateIngredient input, BlockState state, int time) {
|
||||
Preconditions.checkArgument(time >= 0, "Time must be nonnegative");
|
||||
this.id = id;
|
||||
this.input = input;
|
||||
this.outputState = state;
|
||||
this.time = time;
|
||||
if (input != null
|
||||
&& !(input instanceof Block)
|
||||
&& !(input instanceof BlockState)
|
||||
&& !(input instanceof Tag && checkBlockTag((Tag) input))) {
|
||||
throw new IllegalArgumentException("input must be a Tag<Block>, Block, or IBlockState");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkBlockTag(Tag<?> tag) {
|
||||
return tag.getAllElements().stream().allMatch(o -> o instanceof Block);
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets called every tick, please be careful with your checks.
|
||||
*/
|
||||
public boolean matches(World world, BlockPos pos, TileEntitySpecialFlower pureDaisy, BlockState state) {
|
||||
if (input instanceof Block) {
|
||||
return state.getBlock() == input;
|
||||
}
|
||||
|
||||
if (input instanceof BlockState) {
|
||||
return state == input;
|
||||
}
|
||||
|
||||
return ((Tag<Block>) input).contains(state.getBlock());
|
||||
return input.test(state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,7 +79,7 @@ public class RecipePureDaisy {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object getInput() {
|
||||
public StateIngredient getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -104,41 +95,61 @@ public class RecipePureDaisy {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void write(PacketBuffer buf) {
|
||||
buf.writeResourceLocation(id);
|
||||
if (input instanceof Tag) {
|
||||
buf.writeVarInt(0);
|
||||
buf.writeResourceLocation(((Tag) input).getId());
|
||||
} else if (input instanceof Block) {
|
||||
buf.writeVarInt(1);
|
||||
buf.writeVarInt(Registry.BLOCK.getId((Block) input));
|
||||
} else {
|
||||
buf.writeVarInt(2);
|
||||
buf.writeVarInt(Block.getStateId((BlockState) input));
|
||||
}
|
||||
buf.writeVarInt(Block.getStateId(outputState));
|
||||
buf.writeVarInt(time);
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return ModRecipeTypes.PURE_DAISY_SERIALIZER;
|
||||
}
|
||||
|
||||
public static RecipePureDaisy read(PacketBuffer buf) {
|
||||
ResourceLocation id = buf.readResourceLocation();
|
||||
Object input;
|
||||
switch (buf.readVarInt()) {
|
||||
case 0:
|
||||
input = new BlockTags.Wrapper(buf.readResourceLocation());
|
||||
break;
|
||||
case 1:
|
||||
input = Registry.BLOCK.getByValue(buf.readVarInt());
|
||||
break;
|
||||
case 2:
|
||||
input = Block.getStateById(buf.readVarInt());
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unknown input discriminator");
|
||||
}
|
||||
BlockState output = Block.getStateById(buf.readVarInt());
|
||||
int time = buf.readVarInt();
|
||||
return new RecipePureDaisy(id, input, output, time);
|
||||
@Override
|
||||
public IRecipeType<?> getType() {
|
||||
return ModRecipeTypes.PURE_DAISY_TYPE;
|
||||
}
|
||||
|
||||
// Ignored IRecipe overrides
|
||||
@Override
|
||||
public boolean matches(IInventory p_77569_1_, World p_77569_2_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(IInventory p_77572_1_) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit(int p_194133_1_, int p_194133_2_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<RecipePureDaisy> {
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipePureDaisy read(@Nonnull ResourceLocation id, JsonObject object) {
|
||||
StateIngredient input = StateIngredient.deserialize(object.getAsJsonObject("input"));
|
||||
BlockState output = StateIngredient.readBlockState(object.getAsJsonObject("output"));
|
||||
int time = JSONUtils.getInt(object, "time", DEFAULT_TIME);
|
||||
return new RecipePureDaisy(id, input, output, time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@Nonnull PacketBuffer buf, RecipePureDaisy recipe) {
|
||||
recipe.input.write(buf);
|
||||
buf.writeVarInt(Block.getStateId(recipe.outputState));
|
||||
buf.writeVarInt(recipe.time);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RecipePureDaisy read(@Nonnull ResourceLocation id, @Nonnull PacketBuffer buf) {
|
||||
StateIngredient input = StateIngredient.read(buf);
|
||||
BlockState output = Block.getStateById(buf.readVarInt());
|
||||
int time = buf.readVarInt();
|
||||
return new RecipePureDaisy(id, input, output, time);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,24 +20,16 @@ import java.util.function.Consumer;
|
||||
* handlers as stateless as possible.
|
||||
*/
|
||||
public class RegisterRecipesEvent extends Event {
|
||||
private final Consumer<RecipePureDaisy> pureDaisy;
|
||||
private final Consumer<RecipeBrew> brew;
|
||||
private final Consumer<RecipePetals> apothecary;
|
||||
private final Consumer<RecipeRuneAltar> runeAltar;
|
||||
|
||||
public RegisterRecipesEvent(Consumer<RecipePureDaisy> pureDaisy,
|
||||
Consumer<RecipeBrew> brew,
|
||||
Consumer<RecipePetals> apothecary, Consumer<RecipeRuneAltar> runeAltar) {
|
||||
this.pureDaisy = pureDaisy;
|
||||
public RegisterRecipesEvent(Consumer<RecipeBrew> brew, Consumer<RecipePetals> apothecary, Consumer<RecipeRuneAltar> runeAltar) {
|
||||
this.brew = brew;
|
||||
this.apothecary = apothecary;
|
||||
this.runeAltar = runeAltar;
|
||||
}
|
||||
|
||||
public Consumer<RecipePureDaisy> pureDaisy() {
|
||||
return pureDaisy;
|
||||
}
|
||||
|
||||
public Consumer<RecipeBrew> brew() {
|
||||
return brew;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* This class is distributed as part of the Botania Mod.
|
||||
* Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*/
|
||||
package vazkii.botania.api.recipe;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.mojang.datafixers.Dynamic;
|
||||
import com.mojang.datafixers.types.JsonOps;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.NBTDynamicOps;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class StateIngredient implements Predicate<BlockState> {
|
||||
|
||||
public static StateIngredient of(Block block) {
|
||||
return new OfBlock(block);
|
||||
}
|
||||
|
||||
public static StateIngredient of(BlockState state) {
|
||||
return new OfState(state);
|
||||
}
|
||||
|
||||
public static StateIngredient of(Tag<Block> tag) {
|
||||
return new OfTag(tag);
|
||||
}
|
||||
|
||||
public static StateIngredient of(ResourceLocation id) {
|
||||
return new OfTag(id);
|
||||
}
|
||||
|
||||
public static StateIngredient deserialize(JsonObject object) {
|
||||
switch (JSONUtils.getString(object, "type")) {
|
||||
case "tag":
|
||||
return new OfTag(new BlockTags.Wrapper(new ResourceLocation(JSONUtils.getString(object, "tag"))));
|
||||
case "block":
|
||||
return new OfBlock(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(JSONUtils.getString(object, "block"))));
|
||||
case "state":
|
||||
return new OfState(readBlockState(object));
|
||||
default:
|
||||
throw new JsonParseException("Unknown type!");
|
||||
}
|
||||
}
|
||||
|
||||
public static StateIngredient read(PacketBuffer buffer) {
|
||||
switch (buffer.readVarInt()) {
|
||||
case 0:
|
||||
return new OfTag(buffer.readResourceLocation());
|
||||
case 1:
|
||||
return new OfBlock(buffer.readRegistryIdUnsafe(ForgeRegistries.BLOCKS));
|
||||
case 2:
|
||||
return new OfState(Block.getStateById(buffer.readVarInt()));
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown input discriminator!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data about the block state to the provided json object.
|
||||
*/
|
||||
public static JsonObject serializeBlockState(BlockState state) {
|
||||
CompoundNBT nbt = NBTUtil.writeBlockState(state);
|
||||
renameTag(nbt, "Name", "name");
|
||||
renameTag(nbt, "Properties", "properties");
|
||||
Dynamic<INBT> dyn = new Dynamic<>(NBTDynamicOps.INSTANCE, nbt);
|
||||
return dyn.convert(JsonOps.INSTANCE).getValue().getAsJsonObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the block state from the provided json object.
|
||||
*/
|
||||
public static BlockState readBlockState(JsonObject object) {
|
||||
CompoundNBT nbt = (CompoundNBT) new Dynamic<>(JsonOps.INSTANCE, object).convert(NBTDynamicOps.INSTANCE).getValue();
|
||||
renameTag(nbt, "name", "Name");
|
||||
renameTag(nbt, "properties", "Properties");
|
||||
return NBTUtil.readBlockState(nbt);
|
||||
}
|
||||
|
||||
private static void renameTag(CompoundNBT nbt, String oldName, String newName) {
|
||||
INBT tag = nbt.get(oldName);
|
||||
if (tag != null) {
|
||||
nbt.remove(oldName);
|
||||
nbt.put(newName, tag);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract JsonObject serialize();
|
||||
|
||||
public abstract void write(PacketBuffer buffer);
|
||||
|
||||
public abstract List<BlockState> getDisplayed();
|
||||
|
||||
private static class OfBlock extends StateIngredient {
|
||||
private final net.minecraft.block.Block block;
|
||||
|
||||
private OfBlock(net.minecraft.block.Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockState blockState) {
|
||||
return block == blockState.getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject serialize() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("type", "block");
|
||||
object.addProperty("block", block.getRegistryName().toString());
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer) {
|
||||
buffer.writeVarInt(1);
|
||||
buffer.writeRegistryIdUnsafe(ForgeRegistries.BLOCKS, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> getDisplayed() {
|
||||
return Collections.singletonList(block.getDefaultState());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class OfState extends StateIngredient {
|
||||
private final BlockState state;
|
||||
|
||||
private OfState(BlockState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockState blockState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject serialize() {
|
||||
JsonObject object = serializeBlockState(state);
|
||||
object.addProperty("type", "state");
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer) {
|
||||
buffer.writeVarInt(2);
|
||||
buffer.writeVarInt(Block.getStateId(state));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> getDisplayed() {
|
||||
return Collections.singletonList(state);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class OfTag extends StateIngredient {
|
||||
private final Tag<Block> tag;
|
||||
|
||||
public OfTag(Tag<Block> tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public OfTag(ResourceLocation id) {
|
||||
this(new BlockTags.Wrapper(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockState state) {
|
||||
return tag.contains(state.getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject serialize() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("type", "tag");
|
||||
object.addProperty("tag", tag.getId().toString());
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer) {
|
||||
buffer.writeVarInt(0);
|
||||
buffer.writeResourceLocation(tag.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> getDisplayed() {
|
||||
return tag.getAllElements().stream().map(Block::getDefaultState).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,7 @@ import vazkii.botania.common.block.tile.mana.TilePool;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.crafting.AbstractElvenTradeRecipe;
|
||||
import vazkii.botania.common.crafting.LexiconElvenTradeRecipe;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
import vazkii.botania.common.crafting.recipe.AncientWillRecipe;
|
||||
import vazkii.botania.common.crafting.recipe.CompositeLensRecipe;
|
||||
import vazkii.botania.common.crafting.recipe.TerraPickTippingRecipe;
|
||||
@@ -121,7 +122,7 @@ public class JEIBotaniaPlugin implements IModPlugin {
|
||||
@Override
|
||||
public void registerRecipes(@Nonnull IRecipeRegistration registry) {
|
||||
registry.addRecipes(BotaniaAPI.brewRecipes.values(), BreweryRecipeCategory.UID);
|
||||
registry.addRecipes(BotaniaAPI.pureDaisyRecipes.values(), PureDaisyRecipeCategory.UID);
|
||||
registry.addRecipes(Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.PURE_DAISY_TYPE).values(), PureDaisyRecipeCategory.UID);
|
||||
registry.addRecipes(BotaniaAPI.petalRecipes.values(), PetalApothecaryRecipeCategory.UID);
|
||||
registry.addRecipes(TileAlfPortal.elvenTradeRecipes(Minecraft.getInstance().world.getRecipeManager()), ElvenTradeRecipeCategory.UID);
|
||||
registry.addRecipes(BotaniaAPI.runeAltarRecipes.values(), RunicAltarRecipeCategory.UID);
|
||||
|
||||
+11
-6
@@ -28,6 +28,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import vazkii.botania.api.recipe.RecipePureDaisy;
|
||||
import vazkii.botania.api.recipe.StateIngredient;
|
||||
import vazkii.botania.common.block.ModSubtiles;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
@@ -46,7 +47,7 @@ public class PureDaisyRecipeCategory implements IRecipeCategory<RecipePureDaisy>
|
||||
private final IDrawable icon;
|
||||
|
||||
public PureDaisyRecipeCategory(IGuiHelper guiHelper) {
|
||||
background = guiHelper.createBlankDrawable(168, 64);
|
||||
background = guiHelper.createBlankDrawable(168, 46);
|
||||
localizedName = I18n.format("botania.nei.pureDaisy");
|
||||
overlay = guiHelper.createDrawable(new ResourceLocation("botania", "textures/gui/pure_daisy_overlay.png"),
|
||||
0, 0, 64, 46);
|
||||
@@ -85,11 +86,15 @@ public class PureDaisyRecipeCategory implements IRecipeCategory<RecipePureDaisy>
|
||||
|
||||
@Override
|
||||
public void setIngredients(RecipePureDaisy recipe, IIngredients iIngredients) {
|
||||
if (recipe.getInput() instanceof Tag) {
|
||||
Collection<Block> all = ((Tag<Block>) recipe.getInput()).getAllElements();
|
||||
iIngredients.setInputLists(VanillaTypes.ITEM, Collections.singletonList(all.stream().map(ItemStack::new).filter(s -> !s.isEmpty()).collect(Collectors.toList())));
|
||||
} else if (recipe.getInput() instanceof Block || recipe.getInput() instanceof BlockState) {
|
||||
BlockState state = recipe.getInput() instanceof BlockState ? (BlockState) recipe.getInput() : ((Block) recipe.getInput()).getDefaultState();
|
||||
StateIngredient input = recipe.getInput();
|
||||
if (input.getDisplayed().size() > 1) {
|
||||
iIngredients.setInputLists(VanillaTypes.ITEM, Collections.singletonList(input.getDisplayed().stream()
|
||||
.map(BlockState::getBlock)
|
||||
.map(ItemStack::new)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.collect(Collectors.toList())));
|
||||
} else {
|
||||
BlockState state = input.getDisplayed().get(0);
|
||||
Block b = state.getBlock();
|
||||
|
||||
if (b instanceof FlowingFluidBlock) {
|
||||
|
||||
@@ -10,6 +10,7 @@ package vazkii.botania.common.block.subtile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -23,6 +24,7 @@ import vazkii.botania.api.subtile.TileEntitySpecialFlower;
|
||||
import vazkii.botania.client.fx.SparkleParticleData;
|
||||
import vazkii.botania.client.fx.WispParticleData;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -118,9 +120,9 @@ public class SubTilePureDaisy extends TileEntitySpecialFlower {
|
||||
private RecipePureDaisy findRecipe(BlockPos coords) {
|
||||
BlockState state = getWorld().getBlockState(coords);
|
||||
|
||||
for (RecipePureDaisy recipe : BotaniaAPI.pureDaisyRecipes.values()) {
|
||||
if (recipe.matches(getWorld(), coords, this, state)) {
|
||||
return recipe;
|
||||
for (IRecipe<?> recipe : world.getRecipeManager().getRecipes(ModRecipeTypes.PURE_DAISY_TYPE).values()) {
|
||||
if (recipe instanceof RecipePureDaisy && ((RecipePureDaisy) recipe).matches(getWorld(), coords, this, state)) {
|
||||
return ((RecipePureDaisy) recipe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This class is distributed as part of the Botania Mod.
|
||||
* Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*/
|
||||
package vazkii.botania.common.crafting;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import vazkii.botania.api.recipe.RecipePureDaisy;
|
||||
import vazkii.botania.api.recipe.RegisterRecipesEvent;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID)
|
||||
public final class ModPureDaisyRecipes {
|
||||
@SubscribeEvent
|
||||
public static void register(RegisterRecipesEvent evt) {
|
||||
evt.pureDaisy().accept(new RecipePureDaisy(prefix("livingrock"), Tags.Blocks.STONE, ModBlocks.livingrock.getDefaultState()));
|
||||
evt.pureDaisy().accept(new RecipePureDaisy(prefix("livingwood"), BlockTags.LOGS, ModBlocks.livingwood.getDefaultState()));
|
||||
|
||||
evt.pureDaisy().accept(new RecipePureDaisy(prefix("cobblestone"), Tags.Blocks.NETHERRACK, Blocks.COBBLESTONE.getDefaultState()));
|
||||
evt.pureDaisy().accept(new RecipePureDaisy(prefix("sand"), Blocks.SOUL_SAND, Blocks.SAND.getDefaultState()));
|
||||
evt.pureDaisy().accept(new RecipePureDaisy(prefix("packed_ice"), Blocks.ICE, Blocks.PACKED_ICE.getDefaultState()));
|
||||
evt.pureDaisy().accept(new RecipePureDaisy(prefix("blue_ice"), Blocks.PACKED_ICE, Blocks.BLUE_ICE.getDefaultState()));
|
||||
evt.pureDaisy().accept(new RecipePureDaisy(prefix("obsidian"), ModBlocks.blazeBlock, Blocks.OBSIDIAN.getDefaultState()));
|
||||
evt.pureDaisy().accept(new RecipePureDaisy(prefix("snow_block"), Blocks.WATER, Blocks.SNOW_BLOCK.getDefaultState()));
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.api.recipe.RecipeManaInfusion;
|
||||
import vazkii.botania.api.recipe.RecipePureDaisy;
|
||||
import vazkii.botania.common.block.ModSubtiles;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
@@ -30,10 +29,14 @@ import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
public class ModRecipeTypes {
|
||||
public static final IRecipeType<RecipeManaInfusion> MANA_INFUSION_TYPE = new RecipeType<>();
|
||||
public static final IRecipeSerializer<RecipeManaInfusion> MANA_INFUSION_SERIALIZER = new RecipeManaInfusion.Serializer();
|
||||
|
||||
public static final IRecipeType<AbstractElvenTradeRecipe> ELVEN_TRADE_TYPE = new RecipeType<>();
|
||||
public static final IRecipeSerializer<RecipeElvenTrade> ELVEN_TRADE_SERIALIZER = new RecipeElvenTrade.Serializer();
|
||||
public static final SpecialRecipeSerializer<LexiconElvenTradeRecipe> LEXICON_ELVEN_TRADE_SERIALIZER = new SpecialRecipeSerializer<>(LexiconElvenTradeRecipe::new);
|
||||
|
||||
public static final IRecipeType<RecipePureDaisy> PURE_DAISY_TYPE = new RecipeType<>();
|
||||
public static final IRecipeSerializer<RecipePureDaisy> PURE_DAISY_SERIALIZER = new RecipePureDaisy.Serializer();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegistryEvent.Register<IRecipeSerializer<?>> evt) {
|
||||
ResourceLocation id = prefix("elven_trade");
|
||||
@@ -44,6 +47,10 @@ public class ModRecipeTypes {
|
||||
id = prefix("mana_infusion");
|
||||
Registry.register(Registry.RECIPE_TYPE, id, MANA_INFUSION_TYPE);
|
||||
evt.getRegistry().register(MANA_INFUSION_SERIALIZER.setRegistryName(id));
|
||||
|
||||
id = prefix("pure_daisy");
|
||||
Registry.register(Registry.RECIPE_TYPE, id, PURE_DAISY_TYPE);
|
||||
evt.getRegistry().register(PURE_DAISY_SERIALIZER.setRegistryName(id));
|
||||
}
|
||||
|
||||
private static class RecipeType<T extends IRecipe<?>> implements IRecipeType<T> {
|
||||
|
||||
@@ -22,9 +22,7 @@ import net.minecraftforge.fml.network.PacketDistributor;
|
||||
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
import vazkii.botania.api.recipe.RecipeManaInfusion;
|
||||
import vazkii.botania.api.recipe.RecipePetals;
|
||||
import vazkii.botania.api.recipe.RecipePureDaisy;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
import vazkii.botania.api.recipe.RegisterRecipesEvent;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
@@ -41,20 +39,17 @@ public class SyncHandler {
|
||||
public static class ReloadListener implements IResourceManagerReloadListener {
|
||||
@Override
|
||||
public void onResourceManagerReload(@Nullable IResourceManager manager) {
|
||||
Map<ResourceLocation, RecipePureDaisy> pureDaisy = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeBrew> brew = new HashMap<>();
|
||||
Map<ResourceLocation, RecipePetals> apothecary = new HashMap<>();
|
||||
Map<ResourceLocation, RecipeRuneAltar> runeAltar = new HashMap<>();
|
||||
|
||||
RegisterRecipesEvent evt = new RegisterRecipesEvent(
|
||||
r -> pureDaisy.put(r.getId(), r),
|
||||
r -> brew.put(r.getId(), r),
|
||||
r -> apothecary.put(r.getId(), r),
|
||||
r -> runeAltar.put(r.getId(), r)
|
||||
);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
|
||||
BotaniaAPI.pureDaisyRecipes = ImmutableMap.copyOf(pureDaisy);
|
||||
BotaniaAPI.brewRecipes = ImmutableMap.copyOf(brew);
|
||||
BotaniaAPI.petalRecipes = ImmutableMap.copyOf(apothecary);
|
||||
BotaniaAPI.runeAltarRecipes = ImmutableMap.copyOf(runeAltar);
|
||||
@@ -63,8 +58,7 @@ public class SyncHandler {
|
||||
}
|
||||
|
||||
private static PacketSyncRecipes syncPacket() {
|
||||
return new PacketSyncRecipes(BotaniaAPI.brewRecipes,
|
||||
BotaniaAPI.petalRecipes, BotaniaAPI.pureDaisyRecipes, BotaniaAPI.runeAltarRecipes);
|
||||
return new PacketSyncRecipes(BotaniaAPI.brewRecipes, BotaniaAPI.petalRecipes, BotaniaAPI.runeAltarRecipes);
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID, value = Dist.CLIENT)
|
||||
@@ -73,7 +67,6 @@ public class SyncHandler {
|
||||
public static void clientLogout(ClientPlayerNetworkEvent.LoggedOutEvent evt) {
|
||||
BotaniaAPI.brewRecipes = Collections.emptyMap();
|
||||
BotaniaAPI.petalRecipes = Collections.emptyMap();
|
||||
BotaniaAPI.pureDaisyRecipes = Collections.emptyMap();
|
||||
BotaniaAPI.runeAltarRecipes = Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.recipe.RecipeBrew;
|
||||
import vazkii.botania.api.recipe.RecipePetals;
|
||||
import vazkii.botania.api.recipe.RecipePureDaisy;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -27,13 +26,11 @@ import java.util.stream.Stream;
|
||||
public class PacketSyncRecipes {
|
||||
private Map<ResourceLocation, RecipeBrew> brew;
|
||||
private Map<ResourceLocation, RecipePetals> petal;
|
||||
private Map<ResourceLocation, RecipePureDaisy> pureDaisy;
|
||||
private Map<ResourceLocation, RecipeRuneAltar> runeAltar;
|
||||
|
||||
public PacketSyncRecipes(Map<ResourceLocation, RecipeBrew> brew, Map<ResourceLocation, RecipePetals> petal, Map<ResourceLocation, RecipePureDaisy> pureDaisy, Map<ResourceLocation, RecipeRuneAltar> runeAltar) {
|
||||
public PacketSyncRecipes(Map<ResourceLocation, RecipeBrew> brew, Map<ResourceLocation, RecipePetals> petal, Map<ResourceLocation, RecipeRuneAltar> runeAltar) {
|
||||
this.brew = brew;
|
||||
this.petal = petal;
|
||||
this.pureDaisy = pureDaisy;
|
||||
this.runeAltar = runeAltar;
|
||||
}
|
||||
|
||||
@@ -46,10 +43,6 @@ public class PacketSyncRecipes {
|
||||
for (RecipePetals recipe : petal.values()) {
|
||||
recipe.write(buf);
|
||||
}
|
||||
buf.writeVarInt(pureDaisy.size());
|
||||
for (RecipePureDaisy recipe : pureDaisy.values()) {
|
||||
recipe.write(buf);
|
||||
}
|
||||
buf.writeVarInt(runeAltar.size());
|
||||
for (RecipeRuneAltar recipe : runeAltar.values()) {
|
||||
recipe.write(buf);
|
||||
@@ -65,15 +58,11 @@ public class PacketSyncRecipes {
|
||||
Map<ResourceLocation, RecipePetals> petal = Stream.generate(() -> RecipePetals.read(buf))
|
||||
.limit(petalCount)
|
||||
.collect(Collectors.toMap(RecipePetals::getId, r -> r));
|
||||
int pureDaisyCount = buf.readVarInt();
|
||||
Map<ResourceLocation, RecipePureDaisy> pureDaisy = Stream.generate(() -> RecipePureDaisy.read(buf))
|
||||
.limit(pureDaisyCount)
|
||||
.collect(Collectors.toMap(RecipePureDaisy::getId, r -> r));
|
||||
int runeCount = buf.readVarInt();
|
||||
Map<ResourceLocation, RecipeRuneAltar> rune = Stream.generate(() -> RecipeRuneAltar.read(buf))
|
||||
.limit(runeCount)
|
||||
.collect(Collectors.toMap(RecipeRuneAltar::getId, r -> r));
|
||||
return new PacketSyncRecipes(brew, petal, pureDaisy, rune);
|
||||
return new PacketSyncRecipes(brew, petal, rune);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> ctx) {
|
||||
@@ -84,7 +73,6 @@ public class PacketSyncRecipes {
|
||||
}
|
||||
BotaniaAPI.brewRecipes = brew;
|
||||
BotaniaAPI.petalRecipes = petal;
|
||||
BotaniaAPI.pureDaisyRecipes = pureDaisy;
|
||||
BotaniaAPI.runeAltarRecipes = runeAltar;
|
||||
});
|
||||
}
|
||||
@@ -97,8 +85,7 @@ public class PacketSyncRecipes {
|
||||
private int loginIndex;
|
||||
|
||||
public Login() {
|
||||
this(new PacketSyncRecipes(BotaniaAPI.brewRecipes, BotaniaAPI.petalRecipes,
|
||||
BotaniaAPI.pureDaisyRecipes, BotaniaAPI.runeAltarRecipes));
|
||||
this(new PacketSyncRecipes(BotaniaAPI.brewRecipes, BotaniaAPI.petalRecipes, BotaniaAPI.runeAltarRecipes));
|
||||
}
|
||||
|
||||
public Login(PacketSyncRecipes packet) {
|
||||
|
||||
@@ -30,6 +30,7 @@ public class DataGenerators {
|
||||
evt.getGenerator().addProvider(new BlockstateProvider(evt.getGenerator(), evt.getExistingFileHelper()));
|
||||
evt.getGenerator().addProvider(new ElvenTradeProvider(evt.getGenerator()));
|
||||
evt.getGenerator().addProvider(new ManaInfusionProvider(evt.getGenerator()));
|
||||
evt.getGenerator().addProvider(new PureDaisyProvider(evt.getGenerator()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import net.minecraft.util.IItemProvider;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.Tags;
|
||||
|
||||
import vazkii.botania.api.recipe.StateIngredient;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.ModFluffBlocks;
|
||||
@@ -248,14 +249,7 @@ public class ManaInfusionProvider extends RecipeProvider {
|
||||
json.addProperty("group", group);
|
||||
}
|
||||
if (catalyst != null) {
|
||||
StringBuilder catalystStr = new StringBuilder(catalyst.getBlock().getRegistryName().toString());
|
||||
if (catalyst != catalyst.getBlock().getDefaultState()) {
|
||||
catalystStr.append('[');
|
||||
catalystStr.append(catalyst.getProperties().stream().map(prop -> prop.getName() + "=" + getName(prop, catalyst.get(prop)))
|
||||
.collect(Collectors.joining(",")));
|
||||
catalystStr.append(']');
|
||||
}
|
||||
json.addProperty("catalyst", catalystStr.toString());
|
||||
json.add("catalyst", StateIngredient.serializeBlockState(catalyst));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* This class is distributed as part of the Botania Mod.
|
||||
* Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*/
|
||||
package vazkii.botania.data;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.IFinishedRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraftforge.common.Tags;
|
||||
|
||||
import vazkii.botania.api.recipe.StateIngredient;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
|
||||
public class PureDaisyProvider extends RecipeProvider {
|
||||
public PureDaisyProvider(DataGenerator generator) {
|
||||
super(generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRecipes(Consumer<IFinishedRecipe> consumer) {
|
||||
|
||||
consumer.accept(new FinishedRecipe(id("livingrock"), StateIngredient.of(Tags.Blocks.STONE), ModBlocks.livingrock.getDefaultState()));
|
||||
consumer.accept(new FinishedRecipe(id("livingwood"), StateIngredient.of(BlockTags.LOGS), ModBlocks.livingwood.getDefaultState()));
|
||||
|
||||
consumer.accept(new FinishedRecipe(id("cobblestone"), StateIngredient.of(Tags.Blocks.NETHERRACK), Blocks.COBBLESTONE.getDefaultState()));
|
||||
consumer.accept(new FinishedRecipe(id("sand"), StateIngredient.of(Blocks.SOUL_SAND), Blocks.SAND.getDefaultState()));
|
||||
consumer.accept(new FinishedRecipe(id("packed_ice"), StateIngredient.of(Blocks.ICE), Blocks.PACKED_ICE.getDefaultState()));
|
||||
consumer.accept(new FinishedRecipe(id("blue_ice"), StateIngredient.of(Blocks.PACKED_ICE), Blocks.BLUE_ICE.getDefaultState()));
|
||||
consumer.accept(new FinishedRecipe(id("obsidian"), StateIngredient.of(ModBlocks.blazeBlock), Blocks.OBSIDIAN.getDefaultState()));
|
||||
consumer.accept(new FinishedRecipe(id("snow_block"), StateIngredient.of(Blocks.WATER), Blocks.SNOW_BLOCK.getDefaultState()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Botania Pure Daisy recipes";
|
||||
}
|
||||
|
||||
private static ResourceLocation id(String path) {
|
||||
return prefix("pure_daisy/" + path);
|
||||
}
|
||||
|
||||
private static class FinishedRecipe implements IFinishedRecipe {
|
||||
public static final int DEFAULT_TIME = 150;
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final StateIngredient input;
|
||||
private final BlockState outputState;
|
||||
private final int time;
|
||||
|
||||
private FinishedRecipe(ResourceLocation id, StateIngredient input, BlockState state) {
|
||||
this(id, input, state, DEFAULT_TIME);
|
||||
}
|
||||
|
||||
private FinishedRecipe(ResourceLocation id, StateIngredient input, BlockState state, int time) {
|
||||
Preconditions.checkArgument(time >= 0, "Time must be nonnegative");
|
||||
this.id = id;
|
||||
this.input = input;
|
||||
this.outputState = state;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonObject json) {
|
||||
json.add("input", input.serialize());
|
||||
json.add("output", StateIngredient.serializeBlockState(outputState));
|
||||
if (time != DEFAULT_TIME) {
|
||||
json.addProperty("time", time);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return ModRecipeTypes.PURE_DAISY_SERIALIZER;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JsonObject getAdvancementJson() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getAdvancementID() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user