Merge
This commit is contained in:
parent
452fbf0497
commit
76804a4f09
4 changed files with 252 additions and 22 deletions
|
@ -5,10 +5,15 @@ import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.util.shape.VoxelShapes;
|
import net.minecraft.util.shape.VoxelShapes;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import ru.betterend.blocks.basis.BlockPedestal;
|
import ru.betterend.blocks.basis.BlockPedestal;
|
||||||
import ru.betterend.blocks.entities.InfusionPedestalEntity;
|
import ru.betterend.blocks.entities.InfusionPedestalEntity;
|
||||||
|
|
||||||
|
@ -21,6 +26,12 @@ public class InfusionPedestal extends BlockPedestal {
|
||||||
this.height = 1.08F;
|
this.height = 1.08F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||||
|
ActionResult result = super.onUse(state, world, pos, player, hand, hit);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity createBlockEntity(BlockView world) {
|
public BlockEntity createBlockEntity(BlockView world) {
|
||||||
return new InfusionPedestalEntity();
|
return new InfusionPedestalEntity();
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package ru.betterend.blocks.entities;
|
package ru.betterend.blocks.entities;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
|
||||||
import ru.betterend.rituals.InfusionRitual;
|
import ru.betterend.rituals.InfusionRitual;
|
||||||
|
|
||||||
public class InfusionPedestalEntity extends PedestalBlockEntity {
|
public class InfusionPedestalEntity extends PedestalBlockEntity {
|
||||||
|
@ -10,4 +13,13 @@ public class InfusionPedestalEntity extends PedestalBlockEntity {
|
||||||
return this.activeRitual != null;
|
return this.activeRitual != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromTag(BlockState state, CompoundTag tag) {
|
||||||
|
super.fromTag(state, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag toTag(CompoundTag tag) {
|
||||||
|
return super.toTag(tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,55 +1,232 @@
|
||||||
package ru.betterend.recipe.builders;
|
package ru.betterend.recipe.builders;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemConvertible;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
import net.minecraft.recipe.Ingredient;
|
||||||
import net.minecraft.recipe.Recipe;
|
import net.minecraft.recipe.Recipe;
|
||||||
import net.minecraft.recipe.RecipeSerializer;
|
import net.minecraft.recipe.RecipeSerializer;
|
||||||
import net.minecraft.recipe.RecipeType;
|
import net.minecraft.recipe.RecipeType;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.JsonHelper;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import ru.betterend.BetterEnd;
|
||||||
|
import ru.betterend.interfaces.CompoundSerializer;
|
||||||
|
import ru.betterend.recipe.EndRecipeManager;
|
||||||
import ru.betterend.rituals.InfusionRitual;
|
import ru.betterend.rituals.InfusionRitual;
|
||||||
|
|
||||||
public class InfusionRecipe implements Recipe<InfusionRitual> {
|
public class InfusionRecipe implements Recipe<InfusionRitual> {
|
||||||
|
|
||||||
@Override
|
public final static String GROUP = "infusion";
|
||||||
public boolean matches(InfusionRitual inv, World world) {
|
public final static RecipeType<InfusionRecipe> TYPE = EndRecipeManager.registerType(GROUP);
|
||||||
// TODO Auto-generated method stub
|
public final static Serializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new Serializer());
|
||||||
return false;
|
public final static Identifier ID = BetterEnd.makeID(GROUP);
|
||||||
|
|
||||||
|
private final Identifier id;
|
||||||
|
private Ingredient input;
|
||||||
|
private ItemStack output;
|
||||||
|
private int time = 1;
|
||||||
|
private Ingredient[] catalysts = new Ingredient[8];
|
||||||
|
|
||||||
|
private InfusionRecipe(Identifier id) {
|
||||||
|
this(id, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private InfusionRecipe(Identifier id, Ingredient input, ItemStack output) {
|
||||||
|
this.id = id;
|
||||||
|
this.input = input;
|
||||||
|
this.output = output;
|
||||||
|
Arrays.fill(catalysts, Ingredient.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInfusionTime() {
|
||||||
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack craft(InfusionRitual inv) {
|
public boolean matches(InfusionRitual inv, World world) {
|
||||||
// TODO Auto-generated method stub
|
boolean valid = this.input.test(inv.getStack(0));
|
||||||
return null;
|
if (!valid) return false;
|
||||||
|
for (int i = 1; i < 9; i++) {
|
||||||
|
valid &= this.catalysts[i].test(inv.getStack(i));
|
||||||
|
}
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack craft(InfusionRitual ritual) {
|
||||||
|
return this.output.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fits(int width, int height) {
|
public boolean fits(int width, int height) {
|
||||||
// TODO Auto-generated method stub
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getOutput() {
|
public ItemStack getOutput() {
|
||||||
// TODO Auto-generated method stub
|
return this.output;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier getId() {
|
public Identifier getId() {
|
||||||
// TODO Auto-generated method stub
|
return this.id;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecipeSerializer<?> getSerializer() {
|
public RecipeSerializer<?> getSerializer() {
|
||||||
// TODO Auto-generated method stub
|
return SERIALIZER;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecipeType<?> getType() {
|
public RecipeType<?> getType() {
|
||||||
// TODO Auto-generated method stub
|
return TYPE;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InfusionRecipe fromTag(CompoundTag tag) {
|
||||||
|
return SERIALIZER.fromTag(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag toTag(CompoundTag tag) {
|
||||||
|
return SERIALIZER.toTag(this, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private final static Builder INSTANCE = new Builder();
|
||||||
|
|
||||||
|
public static Builder create(String id) {
|
||||||
|
return create(BetterEnd.makeID(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder create(Identifier id) {
|
||||||
|
INSTANCE.id = id;
|
||||||
|
INSTANCE.input = null;
|
||||||
|
INSTANCE.output = null;
|
||||||
|
INSTANCE.time = 1;
|
||||||
|
|
||||||
|
Arrays.fill(INSTANCE.catalysts, Ingredient.EMPTY);
|
||||||
|
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Identifier id;
|
||||||
|
private Ingredient input;
|
||||||
|
private ItemStack output;
|
||||||
|
private int time = 1;
|
||||||
|
private Ingredient[] catalysts = new Ingredient[8];
|
||||||
|
|
||||||
|
private Builder() {
|
||||||
|
Arrays.fill(catalysts, Ingredient.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setInput(ItemConvertible input) {
|
||||||
|
this.input = Ingredient.ofItems(input);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setOutput(ItemStack output) {
|
||||||
|
this.output = output;
|
||||||
|
this.output.setCount(1);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setTime(int time) {
|
||||||
|
this.time = time;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addCatalyst(int slot, ItemConvertible item) {
|
||||||
|
if (slot > 7) return this;
|
||||||
|
this.catalysts[slot] = Ingredient.ofItems(item);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void build() {
|
||||||
|
if (input == null) {
|
||||||
|
BetterEnd.LOGGER.warning("Input for Infusion recipe can't be 'null', recipe {} will be ignored!", id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (output == null) {
|
||||||
|
BetterEnd.LOGGER.warning("Output for Infusion recipe can't be 'null', recipe {} will be ignored!", id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
InfusionRecipe recipe = new InfusionRecipe(id, input, output);
|
||||||
|
recipe.time = time;
|
||||||
|
int empty = 0;
|
||||||
|
for (int i = 0; i < catalysts.length; i++) {
|
||||||
|
if (catalysts[i].isEmpty()) empty++;
|
||||||
|
else recipe.catalysts[i] = catalysts[i];
|
||||||
|
}
|
||||||
|
if (empty == catalysts.length) {
|
||||||
|
BetterEnd.LOGGER.warning("At least one catalyst must be non empty, recipe {} will be ignored!", id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EndRecipeManager.addRecipe(TYPE, recipe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Serializer implements RecipeSerializer<InfusionRecipe> {
|
||||||
|
@Override
|
||||||
|
public InfusionRecipe read(Identifier id, JsonObject json) {
|
||||||
|
InfusionRecipe recipe = new InfusionRecipe(id);
|
||||||
|
recipe.input = Ingredient.fromJson(json.get("input"));
|
||||||
|
Identifier outId = new Identifier(JsonHelper.getString(json, "output"));
|
||||||
|
recipe.output = new ItemStack(Registry.ITEM.getOrEmpty(outId).orElseThrow(() -> {
|
||||||
|
return new IllegalStateException("Item: " + outId + " does not exists!");
|
||||||
|
}));
|
||||||
|
recipe.time = JsonHelper.getInt(json, "time", 1);
|
||||||
|
JsonArray catalysts = JsonHelper.asArray(json, "catalysts");
|
||||||
|
for (int i = 0; i < catalysts.size(); i++) {
|
||||||
|
ItemStack stack = new ItemStack(Registry.ITEM.getOrEmpty(outId).orElse(null));
|
||||||
|
recipe.catalysts[i] = Ingredient.ofStacks(
|
||||||
|
Arrays.stream(new ItemStack[] { stack }));
|
||||||
|
}
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InfusionRecipe read(Identifier id, PacketByteBuf buffer) {
|
||||||
|
InfusionRecipe recipe = new InfusionRecipe(id);
|
||||||
|
recipe.input = Ingredient.fromPacket(buffer);
|
||||||
|
recipe.output = buffer.readItemStack();
|
||||||
|
recipe.time = buffer.readVarInt();
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
recipe.catalysts[i] = Ingredient.fromPacket(buffer);
|
||||||
|
}
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(PacketByteBuf buffer, InfusionRecipe recipe) {
|
||||||
|
recipe.input.write(buffer);
|
||||||
|
buffer.writeItemStack(recipe.output);
|
||||||
|
buffer.writeVarInt(recipe.time);
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
recipe.catalysts[i].write(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public InfusionRecipe fromTag(CompoundTag tag) {
|
||||||
|
Identifier id = new Identifier(tag.getString("id"));
|
||||||
|
InfusionRecipe recipe = new InfusionRecipe(id);
|
||||||
|
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag toTag(InfusionRecipe recipe, CompoundTag tag) {
|
||||||
|
CompoundSerializer<?> inputSerializer = CompoundSerializer.class.cast(recipe.input);
|
||||||
|
tag.put("input", inputSerializer.toTag(new CompoundTag()));
|
||||||
|
tag.put("output", recipe.output.toTag(new CompoundTag()));
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,42 @@
|
||||||
package ru.betterend.rituals;
|
package ru.betterend.rituals;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.inventory.Inventory;
|
import net.minecraft.inventory.Inventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import ru.betterend.recipe.builders.InfusionRecipe;
|
||||||
|
|
||||||
public class InfusionRitual implements Inventory {
|
public class InfusionRitual implements Inventory {
|
||||||
|
|
||||||
|
private final World world;
|
||||||
|
private final BlockPos worldPos;
|
||||||
|
private InfusionRecipe activeRecipe;
|
||||||
|
private int progress = 0;
|
||||||
|
private int time = 0;
|
||||||
|
|
||||||
|
public InfusionRitual(World world, BlockPos pos) {
|
||||||
|
this.world = world;
|
||||||
|
this.worldPos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
public void tick() {
|
public void tick() {
|
||||||
// TODO
|
if (!hasRecipe()) return;
|
||||||
|
this.progress++;
|
||||||
|
if (progress == time) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRecipe() {
|
||||||
|
return this.activeRecipe != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
// TODO Auto-generated method stub
|
// TODO
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,6 +76,13 @@ public class InfusionRitual implements Inventory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlayerUse(PlayerEntity player) {
|
public boolean canPlayerUse(PlayerEntity player) {
|
||||||
return false;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fromTag(CompoundTag tag) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag toTag(CompoundTag tag) {
|
||||||
|
return tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue