This commit is contained in:
Aleksey 2020-09-29 17:57:46 +03:00
parent 7d311ca3d7
commit 43993d13bc
5 changed files with 86 additions and 18 deletions

View file

@ -255,7 +255,8 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
if (recipe == null) { if (recipe == null) {
recipe = this.world.getRecipeManager().getFirstMatch(RecipeType.BLASTING, this, world).orElse(null); recipe = this.world.getRecipeManager().getFirstMatch(RecipeType.BLASTING, this, world).orElse(null);
} }
if (!burning && canAcceptRecipeOutput(recipe)) { boolean accepted = this.canAcceptRecipeOutput(recipe);
if (!burning && accepted) {
this.burnTime = this.getFuelTime(fuel); this.burnTime = this.getFuelTime(fuel);
this.fuelTime = this.burnTime; this.fuelTime = this.burnTime;
burning = this.isBurning(); burning = this.isBurning();
@ -272,7 +273,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
} }
} }
if (burning && canAcceptRecipeOutput(recipe)) { if (burning && accepted) {
this.smeltTime++; this.smeltTime++;
if (smeltTime == smeltTimeTotal) { if (smeltTime == smeltTimeTotal) {
this.smeltTime = 0; this.smeltTime = 0;
@ -415,12 +416,12 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
@Override @Override
public void fromTag(BlockState state, CompoundTag tag) { public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag); super.fromTag(state, tag);
this.inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY); this.inventory = DefaultedList.ofSize(size(), ItemStack.EMPTY);
Inventories.fromTag(tag, this.inventory); Inventories.fromTag(tag, inventory);
this.burnTime = tag.getShort("BurnTime"); this.burnTime = tag.getShort("BurnTime");
this.fuelTime = tag.getShort("FuelTime");
this.smeltTime = tag.getShort("SmeltTime"); this.smeltTime = tag.getShort("SmeltTime");
this.smeltTimeTotal = tag.getShort("SmeltTimeTotal"); this.smeltTimeTotal = tag.getShort("SmeltTimeTotal");
this.fuelTime = this.getFuelTime(this.inventory.get(2));
CompoundTag compoundTag = tag.getCompound("RecipesUsed"); CompoundTag compoundTag = tag.getCompound("RecipesUsed");
Iterator<String> recipes = compoundTag.getKeys().iterator(); Iterator<String> recipes = compoundTag.getKeys().iterator();
while(recipes.hasNext()) { while(recipes.hasNext()) {
@ -432,10 +433,11 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
@Override @Override
public CompoundTag toTag(CompoundTag tag) { public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag); super.toTag(tag);
tag.putShort("BurnTime", (short)this.burnTime); tag.putShort("BurnTime", (short) burnTime);
tag.putShort("SmeltTime", (short)this.smeltTime); tag.putShort("FuelTime", (short) fuelTime);
tag.putShort("SmeltTimeTotal", (short)this.smeltTimeTotal); tag.putShort("SmeltTime", (short) smeltTime);
Inventories.toTag(tag, this.inventory); tag.putShort("SmeltTimeTotal", (short) smeltTimeTotal);
Inventories.toTag(tag, inventory);
CompoundTag usedRecipes = new CompoundTag(); CompoundTag usedRecipes = new CompoundTag();
this.recipesUsed.forEach((identifier, integer) -> { this.recipesUsed.forEach((identifier, integer) -> {
usedRecipes.putInt(identifier.toString(), integer); usedRecipes.putInt(identifier.toString(), integer);

View file

@ -1,21 +1,64 @@
package ru.betterend.client.gui; package ru.betterend.client.gui;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.List;
import java.util.Set; import java.util.Set;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.recipebook.AbstractFurnaceRecipeBookScreen;
import net.minecraft.client.gui.screen.recipebook.BlastFurnaceRecipeBookScreen; import net.minecraft.client.gui.screen.recipebook.BlastFurnaceRecipeBookScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.text.Text; import net.minecraft.item.ItemStack;
import net.minecraft.text.TranslatableText; import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.Recipe;
import net.minecraft.screen.slot.Slot;
import net.minecraft.util.collection.DefaultedList;
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity; import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
public class EndStoneSmelterRecipeBookScreen extends BlastFurnaceRecipeBookScreen { public class EndStoneSmelterRecipeBookScreen extends BlastFurnaceRecipeBookScreen {
private static final Text TITLE = new TranslatableText("gui.recipebook.toggleRecipes.blastable"); @Override
protected Text getToggleCraftableButtonText() {
return TITLE;
}
protected Set<Item> getAllowedFuels() { protected Set<Item> getAllowedFuels() {
return EndStoneSmelterBlockEntity.availableFuels().keySet(); return EndStoneSmelterBlockEntity.availableFuels().keySet();
} }
@SuppressWarnings("unchecked")
@Override
public void showGhostRecipe(Recipe<?> recipe, List<Slot> slots) {
ItemStack result = recipe.getOutput();
this.ghostSlots.setRecipe(recipe);
this.ghostSlots.addSlot(Ingredient.ofStacks(result), (slots.get(3)).x, (slots.get(3)).y);
DefaultedList<Ingredient> inputs = recipe.getPreviewInputs();
try {
Field outputSlot = super.getClass().getDeclaredField("outputSlot");
outputSlot.setAccessible(true);
outputSlot.set(Slot.class, slots.get(3));
Field fuels = super.getClass().getDeclaredField("fuels");
fuels.setAccessible(true);
if (fuels.get(Set.class) == null) {
fuels.set(Set.class, this.getAllowedFuels());
}
Field fuelIterator = super.getClass().getDeclaredField("fuelIterator");
fuelIterator.setAccessible(true);
fuelIterator.set(Iterator.class, ((Set<Item>) fuels.get(Set.class)).iterator());
} catch (Exception ex) {
ex.printStackTrace();
}
Iterator<Ingredient> iterator = inputs.iterator();
for(int i = 0; i < 2; i++) {
if (!iterator.hasNext()) {
return;
}
Ingredient ingredient = iterator.next();
if (!ingredient.isEmpty()) {
Slot slot = slots.get(i);
this.ghostSlots.addSlot(ingredient, slot.x, slot.y);
}
}
}
} }

View file

@ -0,0 +1,22 @@
package ru.betterend.mixin.client;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.client.recipebook.ClientRecipeBook;
import net.minecraft.client.recipebook.RecipeBookGroup;
import net.minecraft.recipe.Recipe;
import ru.betterend.recipe.AlloyingRecipe;
@Mixin(ClientRecipeBook.class)
public abstract class ClientRecipeBookMixin {
@Inject(method = "getGroupForRecipe", at = @At("HEAD"), cancellable = true)
private static void getGroupForRecipe(Recipe<?> recipe, CallbackInfoReturnable<RecipeBookGroup> cinfo) {
if (recipe instanceof AlloyingRecipe) {
cinfo.setReturnValue(RecipeBookGroup.BLAST_FURNACE_MISC);
cinfo.cancel();
}
}
}

View file

@ -6,6 +6,7 @@
"client": [ "client": [
"WorldRendererMixin", "WorldRendererMixin",
"BackgroundRendererMixin", "BackgroundRendererMixin",
"ClientRecipeBookMixin",
"ClientPlayNetworkHandlerMixin" "ClientPlayNetworkHandlerMixin"
], ],
"injectors": { "injectors": {