Infusion ritual fix
This commit is contained in:
parent
28427f54a3
commit
1a412d08e3
6 changed files with 22 additions and 113 deletions
|
@ -45,13 +45,11 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEn
|
|||
matrices.scale(1.25F, 1.25F, 1.25F);
|
||||
}
|
||||
|
||||
float rotation = (blockEntity.getAge() + tickDelta) / 25.0F + 6.0F;
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(rotation));
|
||||
|
||||
|
||||
if (activeItem.getItem() == Items.END_CRYSTAL) {
|
||||
EndCrystalRenderer.render(blockEntity.getAge(), blockEntity.getMaxAge(), tickDelta, matrices, vertexConsumers, light);
|
||||
} else {
|
||||
float rotation = (blockEntity.getAge() + tickDelta) / 25.0F + 6.0F;
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(rotation));
|
||||
minecraft.getItemRenderer().renderItem(activeItem, ModelTransformation.Mode.GROUND, false, matrices, vertexConsumers, light, overlay, model);
|
||||
}
|
||||
matrices.pop();
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package ru.betterend.interfaces;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public interface CompoundSerializer<T> {
|
||||
public abstract CompoundTag beToTag(CompoundTag tag);
|
||||
public abstract T beFromTag(CompoundTag tag);
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package ru.betterend.mixin.common;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import ru.betterend.interfaces.CompoundSerializer;
|
||||
|
||||
@Mixin(Ingredient.class)
|
||||
public abstract class IngredientMixin implements CompoundSerializer<Ingredient> {
|
||||
|
||||
@Shadow
|
||||
private ItemStack[] matchingStacks;
|
||||
|
||||
@Shadow
|
||||
protected abstract void cacheMatchingStacks();
|
||||
|
||||
@Override
|
||||
public CompoundTag beToTag(CompoundTag tag) {
|
||||
this.cacheMatchingStacks();
|
||||
int i = 0;
|
||||
tag.putInt("length", matchingStacks.length);
|
||||
for (ItemStack stack : matchingStacks) {
|
||||
String key = Integer.toString(i);
|
||||
tag.put(key, stack.toTag(new CompoundTag()));
|
||||
i++;
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ingredient beFromTag(CompoundTag tag) {
|
||||
int length = tag.getInt("length");
|
||||
ItemStack[] stacks = new ItemStack[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
String key = Integer.toString(i);
|
||||
stacks[i] = ItemStack.fromTag(tag.getCompound(key));
|
||||
}
|
||||
return Ingredient.ofStacks(Arrays.stream(stacks));
|
||||
}
|
||||
}
|
|
@ -7,7 +7,6 @@ import com.google.gson.JsonObject;
|
|||
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
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;
|
||||
|
@ -17,8 +16,8 @@ import net.minecraft.util.Identifier;
|
|||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.interfaces.CompoundSerializer;
|
||||
import ru.betterend.recipe.EndRecipeManager;
|
||||
import ru.betterend.rituals.InfusionRitual;
|
||||
|
||||
|
@ -90,14 +89,6 @@ public class InfusionRecipe implements Recipe<InfusionRitual> {
|
|||
return TYPE;
|
||||
}
|
||||
|
||||
public static 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();
|
||||
|
||||
|
@ -197,7 +188,7 @@ public class InfusionRecipe implements Recipe<InfusionRitual> {
|
|||
recipe.input = Ingredient.fromPacket(buffer);
|
||||
recipe.output = buffer.readItemStack();
|
||||
recipe.time = buffer.readVarInt();
|
||||
for (int i = 0; i < 9; i++) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
recipe.catalysts[i] = Ingredient.fromPacket(buffer);
|
||||
}
|
||||
return recipe;
|
||||
|
@ -208,44 +199,9 @@ public class InfusionRecipe implements Recipe<InfusionRitual> {
|
|||
recipe.input.write(buffer);
|
||||
buffer.writeItemStack(recipe.output);
|
||||
buffer.writeVarInt(recipe.time);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
recipe.catalysts[i].write(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public InfusionRecipe fromTag(CompoundTag tag) {
|
||||
Identifier id = new Identifier(tag.getString("id"));
|
||||
InfusionRecipe recipe = new InfusionRecipe(id);
|
||||
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);
|
||||
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.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.beToTag(new CompoundTag()));
|
||||
}
|
||||
tag.put("catalysts", catalysts);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private CompoundSerializer<Ingredient> toSerializer(Ingredient ingredient) {
|
||||
return CompoundSerializer.class.cast(ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import net.minecraft.server.world.ServerWorld;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.blocks.entities.InfusionPedestalEntity;
|
||||
import ru.betterend.blocks.entities.PedestalBlockEntity;
|
||||
import ru.betterend.recipe.builders.InfusionRecipe;
|
||||
|
@ -27,6 +28,8 @@ public class InfusionRitual implements Inventory {
|
|||
private World world;
|
||||
private BlockPos worldPos;
|
||||
private InfusionRecipe activeRecipe;
|
||||
private boolean isDirty = false;
|
||||
private boolean hasRecipe = false;
|
||||
private int progress = 0;
|
||||
private int time = 0;
|
||||
|
||||
|
@ -60,25 +63,29 @@ public class InfusionRitual implements Inventory {
|
|||
|
||||
public boolean checkRecipe() {
|
||||
if (!isValid()) return false;
|
||||
InfusionRecipe recipe = this.world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null);
|
||||
if (hasRecipe()) {
|
||||
InfusionRecipe recipe = this.world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null);
|
||||
if (recipe == null) {
|
||||
this.activeRecipe = null;
|
||||
this.hasRecipe = false;
|
||||
this.progress = 0;
|
||||
this.time = 0;
|
||||
this.markDirty();
|
||||
return false;
|
||||
} else if (recipe != activeRecipe) {
|
||||
} else if (recipe.getInfusionTime() != time) {
|
||||
this.activeRecipe = recipe;
|
||||
this.time = this.activeRecipe.getInfusionTime();
|
||||
this.progress = 0;
|
||||
this.markDirty();
|
||||
} else if (activeRecipe == null) {
|
||||
this.activeRecipe = recipe;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
this.activeRecipe = this.world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null);
|
||||
if (activeRecipe != null) {
|
||||
if (recipe != null) {
|
||||
this.activeRecipe = recipe;
|
||||
this.time = this.activeRecipe.getInfusionTime();
|
||||
this.hasRecipe = true;
|
||||
this.progress = 0;
|
||||
this.markDirty();
|
||||
return true;
|
||||
|
@ -87,6 +94,7 @@ public class InfusionRitual implements Inventory {
|
|||
}
|
||||
|
||||
public void tick() {
|
||||
if (isDirty) this.configure();
|
||||
if (!isValid() || !hasRecipe()) return;
|
||||
if (!checkRecipe()) return;
|
||||
this.progress++;
|
||||
|
@ -98,6 +106,7 @@ public class InfusionRitual implements Inventory {
|
|||
catalyst.removeStack(world, world.getBlockState(catalyst.getPos()));
|
||||
}
|
||||
this.activeRecipe = null;
|
||||
this.hasRecipe = false;
|
||||
this.progress = 0;
|
||||
this.time = 0;
|
||||
this.markDirty();
|
||||
|
@ -133,13 +142,13 @@ public class InfusionRitual implements Inventory {
|
|||
}
|
||||
|
||||
public boolean hasRecipe() {
|
||||
return this.activeRecipe != null;
|
||||
return this.hasRecipe;
|
||||
}
|
||||
|
||||
public void setLocation(World world, BlockPos pos) {
|
||||
this.world = world;
|
||||
this.worldPos = pos;
|
||||
this.configure();
|
||||
this.isDirty = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -213,7 +222,7 @@ public class InfusionRitual implements Inventory {
|
|||
|
||||
public void fromTag(CompoundTag tag) {
|
||||
if (tag.contains("recipe")) {
|
||||
this.activeRecipe = InfusionRecipe.fromTag(tag.getCompound("recipe"));
|
||||
this.hasRecipe = tag.getBoolean("recipe");
|
||||
this.progress = tag.getInt("progress");
|
||||
this.time = tag.getInt("time");
|
||||
}
|
||||
|
@ -221,7 +230,7 @@ public class InfusionRitual implements Inventory {
|
|||
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
if (hasRecipe()) {
|
||||
tag.put("recipe", activeRecipe.toTag(new CompoundTag()));
|
||||
tag.putBoolean("recipe", this.hasRecipe);
|
||||
tag.putInt("progress", progress);
|
||||
tag.putInt("time", time);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
"BoneMealItemMixin",
|
||||
"SlimeEntityMixin",
|
||||
"BrewingAccessor",
|
||||
"IngredientMixin",
|
||||
"EntityMixin"
|
||||
],
|
||||
"injectors": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue