Infusion crafting
This commit is contained in:
parent
beab6ce10a
commit
16039bcb47
8 changed files with 48 additions and 19 deletions
|
@ -106,14 +106,12 @@ public class BlockPedestal extends BlockBaseNotFull implements BlockEntityProvid
|
|||
if (pedestal.isEmpty()) {
|
||||
ItemStack itemStack = player.getStackInHand(hand);
|
||||
if (itemStack.isEmpty()) return ActionResult.CONSUME;
|
||||
world.setBlockState(pos, state.with(HAS_ITEM, true));
|
||||
pedestal.setStack(0, itemStack.split(1));
|
||||
pedestal.setStack(world, state, itemStack.split(1));
|
||||
return ActionResult.SUCCESS;
|
||||
} else {
|
||||
ItemStack itemStack = pedestal.getStack(0);
|
||||
if (player.giveItemStack(itemStack)) {
|
||||
world.setBlockState(pos, state.with(HAS_ITEM, false));
|
||||
pedestal.removeStack(0);
|
||||
pedestal.removeStack(world, state);
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.FAIL;
|
||||
|
|
|
@ -41,18 +41,19 @@ public class InfusionPedestalEntity extends PedestalBlockEntity {
|
|||
|
||||
@Override
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
super.fromTag(state, tag);
|
||||
if (tag.contains("ritual")) {
|
||||
this.linkedRitual = new InfusionRitual(world, pos);
|
||||
this.linkedRitual.fromTag(tag.getCompound("ritual"));
|
||||
}
|
||||
super.fromTag(state, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
if (hasRitual()) {
|
||||
tag.put("ritual", linkedRitual.toTag(new CompoundTag()));
|
||||
}
|
||||
return super.toTag(tag);
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
|
||||
import net.minecraft.util.Tickable;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.blocks.basis.BlockPedestal;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class PedestalBlockEntity extends BlockEntity implements Inventory, Tickable {
|
||||
|
@ -57,11 +59,21 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
|||
public ItemStack removeStack(int slot) {
|
||||
return this.activeItem = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public void removeStack(World world, BlockState state) {
|
||||
world.setBlockState(pos, state.with(BlockPedestal.HAS_ITEM, false));
|
||||
this.removeStack(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int slot, ItemStack stack) {
|
||||
this.activeItem = stack;
|
||||
}
|
||||
|
||||
public void setStack(World world, BlockState state, ItemStack stack) {
|
||||
world.setBlockState(pos, state.with(BlockPedestal.HAS_ITEM, true));
|
||||
this.setStack(0, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(PlayerEntity player) {
|
||||
|
@ -89,8 +101,9 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
|||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
tag.put("active_item", activeItem.toTag(new CompoundTag()));
|
||||
return super.toTag(tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,6 @@ package ru.betterend.interfaces;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public interface CompoundSerializer<T> {
|
||||
public abstract CompoundTag toTag(CompoundTag tag);
|
||||
public abstract T fromTag(CompoundTag tag);
|
||||
public abstract CompoundTag beToTag(CompoundTag tag);
|
||||
public abstract T beFromTag(CompoundTag tag);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public abstract class IngredientMixin implements CompoundSerializer<Ingredient>
|
|||
protected abstract void cacheMatchingStacks();
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
public CompoundTag beToTag(CompoundTag tag) {
|
||||
this.cacheMatchingStacks();
|
||||
int i = 0;
|
||||
tag.putInt("length", matchingStacks.length);
|
||||
|
@ -34,7 +34,7 @@ public abstract class IngredientMixin implements CompoundSerializer<Ingredient>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Ingredient fromTag(CompoundTag tag) {
|
||||
public Ingredient beFromTag(CompoundTag tag) {
|
||||
int length = tag.getInt("length");
|
||||
ItemStack[] stacks = new ItemStack[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ru.betterend.recipe;
|
||||
|
||||
import net.minecraft.item.Items;
|
||||
import ru.betterend.recipe.builders.InfusionRecipe;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
@ -14,5 +15,18 @@ public class InfusionRecipes {
|
|||
.addCatalyst(4, EndItems.CRYSTAL_SHARDS)
|
||||
.addCatalyst(6, EndItems.CRYSTAL_SHARDS)
|
||||
.build();
|
||||
|
||||
InfusionRecipe.Builder.create("eternal_crystal")
|
||||
.setInput(EndItems.CRYSTAL_SHARDS)
|
||||
.setOutput(EndItems.ETERNAL_CRYSTAL)
|
||||
.addCatalyst(0, Items.END_CRYSTAL)
|
||||
.addCatalyst(2, Items.END_CRYSTAL)
|
||||
.addCatalyst(4, Items.END_CRYSTAL)
|
||||
.addCatalyst(6, Items.END_CRYSTAL)
|
||||
.addCatalyst(1, EndItems.ENDER_DUST)
|
||||
.addCatalyst(3, EndItems.ENDER_DUST)
|
||||
.addCatalyst(5, EndItems.ENDER_DUST)
|
||||
.addCatalyst(7, EndItems.ENDER_DUST)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -217,29 +217,28 @@ public class InfusionRecipe implements Recipe<InfusionRitual> {
|
|||
public InfusionRecipe fromTag(CompoundTag tag) {
|
||||
Identifier id = new Identifier(tag.getString("id"));
|
||||
InfusionRecipe recipe = new InfusionRecipe(id);
|
||||
CompoundSerializer<Ingredient> inputSerializer = this.toSerializer(recipe.input);
|
||||
recipe.input = inputSerializer.fromTag(tag.getCompound("input"));
|
||||
CompoundSerializer<Ingredient> ingredientSerializer = this.toSerializer(Ingredient.EMPTY);
|
||||
recipe.input = ingredientSerializer.beFromTag(tag.getCompound("input"));
|
||||
recipe.output = ItemStack.fromTag(tag.getCompound("output"));
|
||||
recipe.time = tag.getInt("time");
|
||||
CompoundTag catalysts = tag.getCompound("catalysts");
|
||||
for(int i = 0; i < recipe.catalysts.length; i++) {
|
||||
String key = Integer.toString(i);
|
||||
CompoundSerializer<Ingredient> cataSerializer = this.toSerializer(recipe.catalysts[i]);
|
||||
recipe.catalysts[i] = cataSerializer.fromTag(catalysts.getCompound(key));
|
||||
recipe.catalysts[i] = ingredientSerializer.beFromTag(catalysts.getCompound(key));
|
||||
}
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public CompoundTag toTag(InfusionRecipe recipe, CompoundTag tag) {
|
||||
CompoundSerializer<?> inputSerializer = this.toSerializer(recipe.input);
|
||||
tag.put("input", inputSerializer.toTag(new CompoundTag()));
|
||||
tag.put("input", inputSerializer.beToTag(new CompoundTag()));
|
||||
tag.put("output", recipe.output.toTag(new CompoundTag()));
|
||||
tag.putInt("time", recipe.time);
|
||||
CompoundTag catalysts = new CompoundTag();
|
||||
for(int i = 0; i < recipe.catalysts.length; i++) {
|
||||
String key = Integer.toString(i);
|
||||
CompoundSerializer<?> cataSerializer = this.toSerializer(recipe.catalysts[i]);
|
||||
catalysts.put(key, cataSerializer.toTag(new CompoundTag()));
|
||||
catalysts.put(key, cataSerializer.beToTag(new CompoundTag()));
|
||||
}
|
||||
tag.put("catalysts", catalysts);
|
||||
return tag;
|
||||
|
|
|
@ -2,6 +2,7 @@ package ru.betterend.rituals;
|
|||
|
||||
import java.awt.Point;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
|
@ -60,6 +61,7 @@ public class InfusionRitual implements Inventory {
|
|||
this.activeRecipe = this.world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null);
|
||||
if (activeRecipe != null) {
|
||||
this.time = this.activeRecipe.getInfusionTime();
|
||||
this.progress = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -69,9 +71,11 @@ public class InfusionRitual implements Inventory {
|
|||
if (!isValid() || !hasRecipe()) return;
|
||||
this.progress++;
|
||||
if (progress == time) {
|
||||
this.input.setStack(0, activeRecipe.craft(this));
|
||||
BlockState inputState = world.getBlockState(input.getPos());
|
||||
this.input.removeStack(world, inputState);
|
||||
this.input.setStack(world, inputState, activeRecipe.craft(this));
|
||||
for (PedestalBlockEntity catalyst : catalysts) {
|
||||
catalyst.clear();
|
||||
catalyst.removeStack(world, world.getBlockState(catalyst.getPos()));
|
||||
}
|
||||
this.activeRecipe = null;
|
||||
this.progress = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue