Merge and fix
This commit is contained in:
parent
b91c85529d
commit
ce9f4add97
548 changed files with 17517 additions and 16862 deletions
|
@ -1,102 +1,102 @@
|
|||
package ru.betterend.client.gui;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.recipebook.BlastFurnaceRecipeBookScreen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class EndStoneSmelterRecipeBookScreen extends BlastFurnaceRecipeBookScreen {
|
||||
private Iterator<Item> fuelIterator;
|
||||
private Set<Item> fuels;
|
||||
private Slot fuelSlot;
|
||||
private Item currentItem;
|
||||
private float frameTime;
|
||||
|
||||
@Override
|
||||
protected Set<Item> getAllowedFuels() {
|
||||
return EndStoneSmelterBlockEntity.availableFuels().keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void slotClicked(Slot slot) {
|
||||
super.slotClicked(slot);
|
||||
if (slot != null && slot.id < this.craftingScreenHandler.getCraftingSlotCount()) {
|
||||
this.fuelSlot = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showGhostRecipe(Recipe<?> recipe, List<Slot> slots) {
|
||||
this.ghostSlots.reset();
|
||||
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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
this.fuelSlot = slots.get(2);
|
||||
if (this.fuels == null) {
|
||||
this.fuels = this.getAllowedFuels();
|
||||
}
|
||||
|
||||
this.fuelIterator = this.fuels.iterator();
|
||||
this.currentItem = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGhostSlots(MatrixStack matrices, int x, int y, boolean bl, float f) {
|
||||
this.ghostSlots.draw(matrices, client, x, y, bl, f);
|
||||
if (fuelSlot != null) {
|
||||
if (!Screen.hasControlDown()) {
|
||||
this.frameTime += f;
|
||||
}
|
||||
|
||||
int slotX = this.fuelSlot.x + x;
|
||||
int slotY = this.fuelSlot.y + y;
|
||||
DrawableHelper.fill(matrices, slotX, slotY, slotX + 16, slotY + 16, 822018048);
|
||||
this.client.getItemRenderer().renderInGuiWithOverrides(client.player, this.getItem().getDefaultStack(), slotX, slotY);
|
||||
RenderSystem.depthFunc(516);
|
||||
DrawableHelper.fill(matrices, slotX, slotY, slotX + 16, slotY + 16, 822083583);
|
||||
RenderSystem.depthFunc(515);
|
||||
}
|
||||
}
|
||||
|
||||
private Item getItem() {
|
||||
if (this.currentItem == null || this.frameTime > 30.0F) {
|
||||
this.frameTime = 0.0F;
|
||||
if (this.fuelIterator == null || !this.fuelIterator.hasNext()) {
|
||||
if (this.fuels == null) {
|
||||
this.fuels = this.getAllowedFuels();
|
||||
}
|
||||
this.fuelIterator = this.fuels.iterator();
|
||||
}
|
||||
this.currentItem = this.fuelIterator.next();
|
||||
}
|
||||
return this.currentItem;
|
||||
}
|
||||
}
|
||||
package ru.betterend.client.gui;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.recipebook.BlastFurnaceRecipeBookScreen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class EndStoneSmelterRecipeBookScreen extends BlastFurnaceRecipeBookScreen {
|
||||
private Iterator<Item> fuelIterator;
|
||||
private Set<Item> fuels;
|
||||
private Slot fuelSlot;
|
||||
private Item currentItem;
|
||||
private float frameTime;
|
||||
|
||||
@Override
|
||||
protected Set<Item> getAllowedFuels() {
|
||||
return EndStoneSmelterBlockEntity.availableFuels().keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void slotClicked(Slot slot) {
|
||||
super.slotClicked(slot);
|
||||
if (slot != null && slot.id < this.craftingScreenHandler.getCraftingSlotCount()) {
|
||||
this.fuelSlot = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showGhostRecipe(Recipe<?> recipe, List<Slot> slots) {
|
||||
this.ghostSlots.reset();
|
||||
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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
this.fuelSlot = slots.get(2);
|
||||
if (this.fuels == null) {
|
||||
this.fuels = this.getAllowedFuels();
|
||||
}
|
||||
|
||||
this.fuelIterator = this.fuels.iterator();
|
||||
this.currentItem = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGhostSlots(MatrixStack matrices, int x, int y, boolean bl, float f) {
|
||||
this.ghostSlots.draw(matrices, client, x, y, bl, f);
|
||||
if (fuelSlot != null) {
|
||||
if (!Screen.hasControlDown()) {
|
||||
this.frameTime += f;
|
||||
}
|
||||
|
||||
int slotX = this.fuelSlot.x + x;
|
||||
int slotY = this.fuelSlot.y + y;
|
||||
DrawableHelper.fill(matrices, slotX, slotY, slotX + 16, slotY + 16, 822018048);
|
||||
this.client.getItemRenderer().renderInGuiWithOverrides(client.player, this.getItem().getDefaultStack(), slotX, slotY);
|
||||
RenderSystem.depthFunc(516);
|
||||
DrawableHelper.fill(matrices, slotX, slotY, slotX + 16, slotY + 16, 822083583);
|
||||
RenderSystem.depthFunc(515);
|
||||
}
|
||||
}
|
||||
|
||||
private Item getItem() {
|
||||
if (this.currentItem == null || this.frameTime > 30.0F) {
|
||||
this.frameTime = 0.0F;
|
||||
if (this.fuelIterator == null || !this.fuelIterator.hasNext()) {
|
||||
if (this.fuels == null) {
|
||||
this.fuels = this.getAllowedFuels();
|
||||
}
|
||||
this.fuelIterator = this.fuels.iterator();
|
||||
}
|
||||
this.currentItem = this.fuelIterator.next();
|
||||
}
|
||||
return this.currentItem;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,130 +1,130 @@
|
|||
package ru.betterend.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
|
||||
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.screen.slot.SlotActionType;
|
||||
import net.minecraft.text.StringVisitable;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import ru.betterend.BetterEnd;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class EndStoneSmelterScreen extends HandledScreen<EndStoneSmelterScreenHandler> implements RecipeBookProvider {
|
||||
|
||||
private final static Identifier RECIPE_BUTTON_TEXTURE = new Identifier("textures/gui/recipe_button.png");
|
||||
private final static Identifier BACKGROUND_TEXTURE = BetterEnd.makeID("textures/gui/smelter_gui.png");
|
||||
|
||||
public final EndStoneSmelterRecipeBookScreen recipeBook;
|
||||
private boolean narrow;
|
||||
|
||||
public EndStoneSmelterScreen(EndStoneSmelterScreenHandler handler, PlayerInventory inventory, Text title) {
|
||||
super(handler, inventory, title);
|
||||
this.recipeBook = new EndStoneSmelterRecipeBookScreen();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
super.init();
|
||||
this.narrow = this.width < 379;
|
||||
this.recipeBook.initialize(width, height, client, narrow, handler);
|
||||
this.x = this.recipeBook.findLeftEdge(narrow, width, backgroundWidth);
|
||||
this.addButton(new TexturedButtonWidget(x + 20, height / 2 - 49, 20, 18, 0, 0, 19, RECIPE_BUTTON_TEXTURE, (buttonWidget) -> {
|
||||
this.recipeBook.reset(narrow);
|
||||
this.recipeBook.toggleOpen();
|
||||
this.x = this.recipeBook.findLeftEdge(narrow, width, backgroundWidth);
|
||||
((TexturedButtonWidget) buttonWidget).setPos(this.x + 20, height / 2 - 49);
|
||||
}));
|
||||
this.titleX = (this.backgroundWidth - this.textRenderer.getWidth((StringVisitable)this.title)) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
this.recipeBook.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
if (this.recipeBook.isOpen() && this.narrow) {
|
||||
this.drawBackground(matrices, delta, mouseX, mouseY);
|
||||
this.recipeBook.render(matrices, mouseX, mouseY, delta);
|
||||
} else {
|
||||
this.recipeBook.render(matrices, mouseX, mouseY, delta);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
this.recipeBook.drawGhostSlots(matrices, x, y, true, delta);
|
||||
}
|
||||
|
||||
this.drawMouseoverTooltip(matrices, mouseX, mouseY);
|
||||
this.recipeBook.drawTooltip(matrices, x, y, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (this.recipeBook.mouseClicked(mouseX, mouseY, button)) {
|
||||
return true;
|
||||
} else {
|
||||
return this.narrow && this.recipeBook.isOpen() ? true : super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMouseClick(Slot slot, int invSlot, int clickData, SlotActionType actionType) {
|
||||
super.onMouseClick(slot, invSlot, clickData, actionType);
|
||||
this.recipeBook.slotClicked(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
return this.recipeBook.keyPressed(keyCode, scanCode, modifiers) ? false : super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isClickOutsideBounds(double mouseX, double mouseY, int left, int top, int button) {
|
||||
boolean isMouseOut = mouseX < left || mouseY < top || mouseX >= (left + backgroundWidth) || mouseY >= (top + backgroundHeight);
|
||||
return this.recipeBook.isClickOutsideBounds(mouseX, mouseY, x, y, backgroundWidth, backgroundHeight, button) && isMouseOut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char chr, int keyCode) {
|
||||
return this.recipeBook.charTyped(chr, keyCode) ? true : super.charTyped(chr, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshRecipeBook() {
|
||||
this.recipeBook.refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeBookWidget getRecipeBookWidget() {
|
||||
return this.recipeBook;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.client.getTextureManager().bindTexture(BACKGROUND_TEXTURE);
|
||||
this.drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight);
|
||||
int p;
|
||||
if (handler.isBurning()) {
|
||||
p = handler.getFuelProgress();
|
||||
this.drawTexture(matrices, x + 56, y + 36 + 12 - p, 176, 12 - p, 14, p + 1);
|
||||
}
|
||||
p = handler.getSmeltProgress();
|
||||
this.drawTexture(matrices, x + 92, y + 34, 176, 14, p + 1, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
this.recipeBook.close();
|
||||
super.removed();
|
||||
}
|
||||
}
|
||||
package ru.betterend.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
|
||||
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.screen.slot.SlotActionType;
|
||||
import net.minecraft.text.StringVisitable;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import ru.betterend.BetterEnd;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class EndStoneSmelterScreen extends HandledScreen<EndStoneSmelterScreenHandler> implements RecipeBookProvider {
|
||||
|
||||
private final static Identifier RECIPE_BUTTON_TEXTURE = new Identifier("textures/gui/recipe_button.png");
|
||||
private final static Identifier BACKGROUND_TEXTURE = BetterEnd.makeID("textures/gui/smelter_gui.png");
|
||||
|
||||
public final EndStoneSmelterRecipeBookScreen recipeBook;
|
||||
private boolean narrow;
|
||||
|
||||
public EndStoneSmelterScreen(EndStoneSmelterScreenHandler handler, PlayerInventory inventory, Text title) {
|
||||
super(handler, inventory, title);
|
||||
this.recipeBook = new EndStoneSmelterRecipeBookScreen();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
super.init();
|
||||
this.narrow = this.width < 379;
|
||||
this.recipeBook.initialize(width, height, client, narrow, handler);
|
||||
this.x = this.recipeBook.findLeftEdge(narrow, width, backgroundWidth);
|
||||
this.addButton(new TexturedButtonWidget(x + 20, height / 2 - 49, 20, 18, 0, 0, 19, RECIPE_BUTTON_TEXTURE, (buttonWidget) -> {
|
||||
this.recipeBook.reset(narrow);
|
||||
this.recipeBook.toggleOpen();
|
||||
this.x = this.recipeBook.findLeftEdge(narrow, width, backgroundWidth);
|
||||
((TexturedButtonWidget) buttonWidget).setPos(this.x + 20, height / 2 - 49);
|
||||
}));
|
||||
this.titleX = (this.backgroundWidth - this.textRenderer.getWidth((StringVisitable)this.title)) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
this.recipeBook.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
if (this.recipeBook.isOpen() && this.narrow) {
|
||||
this.drawBackground(matrices, delta, mouseX, mouseY);
|
||||
this.recipeBook.render(matrices, mouseX, mouseY, delta);
|
||||
} else {
|
||||
this.recipeBook.render(matrices, mouseX, mouseY, delta);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
this.recipeBook.drawGhostSlots(matrices, x, y, true, delta);
|
||||
}
|
||||
|
||||
this.drawMouseoverTooltip(matrices, mouseX, mouseY);
|
||||
this.recipeBook.drawTooltip(matrices, x, y, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (this.recipeBook.mouseClicked(mouseX, mouseY, button)) {
|
||||
return true;
|
||||
} else {
|
||||
return this.narrow && this.recipeBook.isOpen() ? true : super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMouseClick(Slot slot, int invSlot, int clickData, SlotActionType actionType) {
|
||||
super.onMouseClick(slot, invSlot, clickData, actionType);
|
||||
this.recipeBook.slotClicked(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
return this.recipeBook.keyPressed(keyCode, scanCode, modifiers) ? false : super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isClickOutsideBounds(double mouseX, double mouseY, int left, int top, int button) {
|
||||
boolean isMouseOut = mouseX < left || mouseY < top || mouseX >= (left + backgroundWidth) || mouseY >= (top + backgroundHeight);
|
||||
return this.recipeBook.isClickOutsideBounds(mouseX, mouseY, x, y, backgroundWidth, backgroundHeight, button) && isMouseOut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char chr, int keyCode) {
|
||||
return this.recipeBook.charTyped(chr, keyCode) ? true : super.charTyped(chr, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshRecipeBook() {
|
||||
this.recipeBook.refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeBookWidget getRecipeBookWidget() {
|
||||
return this.recipeBook;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.client.getTextureManager().bindTexture(BACKGROUND_TEXTURE);
|
||||
this.drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight);
|
||||
int p;
|
||||
if (handler.isBurning()) {
|
||||
p = handler.getFuelProgress();
|
||||
this.drawTexture(matrices, x + 56, y + 36 + 12 - p, 176, 12 - p, 14, p + 1);
|
||||
}
|
||||
p = handler.getSmeltProgress();
|
||||
this.drawTexture(matrices, x + 92, y + 34, 176, 14, p + 1, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
this.recipeBook.close();
|
||||
super.removed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,186 +1,186 @@
|
|||
package ru.betterend.client.gui;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.SimpleInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeFinder;
|
||||
import net.minecraft.recipe.RecipeInputProvider;
|
||||
import net.minecraft.recipe.book.RecipeBookCategory;
|
||||
import net.minecraft.screen.AbstractRecipeScreenHandler;
|
||||
import net.minecraft.screen.ArrayPropertyDelegate;
|
||||
import net.minecraft.screen.PropertyDelegate;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.EndStoneSmelter;
|
||||
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
|
||||
import ru.betterend.client.gui.slot.SmelterFuelSlot;
|
||||
import ru.betterend.client.gui.slot.SmelterOutputSlot;
|
||||
import ru.betterend.recipe.builders.AlloyingRecipe;
|
||||
|
||||
public class EndStoneSmelterScreenHandler extends AbstractRecipeScreenHandler<Inventory> {
|
||||
|
||||
public final static ScreenHandlerType<EndStoneSmelterScreenHandler> HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(
|
||||
BetterEnd.makeID(EndStoneSmelter.ID), EndStoneSmelterScreenHandler::new);
|
||||
|
||||
private final Inventory inventory;
|
||||
private final PropertyDelegate propertyDelegate;
|
||||
protected final World world;
|
||||
|
||||
public EndStoneSmelterScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||
this(syncId, playerInventory, new SimpleInventory(4), new ArrayPropertyDelegate(4));
|
||||
}
|
||||
|
||||
public EndStoneSmelterScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory, PropertyDelegate propertyDelegate) {
|
||||
super(HANDLER_TYPE, syncId);
|
||||
this.inventory = inventory;
|
||||
this.propertyDelegate = propertyDelegate;
|
||||
this.world = playerInventory.player.world;
|
||||
|
||||
this.addProperties(propertyDelegate);
|
||||
this.addSlot(new Slot(inventory, 0, 45, 17));
|
||||
this.addSlot(new Slot(inventory, 1, 67, 17));
|
||||
this.addSlot(new SmelterFuelSlot(this, inventory, 2, 56, 53));
|
||||
this.addSlot(new SmelterOutputSlot(playerInventory.player, inventory, 3, 129, 35));
|
||||
|
||||
for(int i = 0; i < 3; ++i) {
|
||||
for(int j = 0; j < 9; ++j) {
|
||||
this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < 9; ++i) {
|
||||
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateRecipeFinder(RecipeFinder finder) {
|
||||
if (inventory instanceof RecipeInputProvider) {
|
||||
((RecipeInputProvider) inventory).provideRecipeInputs(finder);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCraftingSlots() {
|
||||
this.inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Recipe<? super Inventory> recipe) {
|
||||
return recipe.matches(this.inventory, this.world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCraftingResultSlotIndex() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCraftingWidth() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCraftingHeight() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCraftingSlotCount() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeBookCategory getCategory() {
|
||||
return RecipeBookCategory.BLAST_FURNACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
return this.inventory.canPlayerUse(player);
|
||||
}
|
||||
|
||||
protected boolean isSmeltable(ItemStack itemStack) {
|
||||
return this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, new SimpleInventory(new ItemStack[]{itemStack}), this.world).isPresent();
|
||||
}
|
||||
|
||||
public boolean isFuel(ItemStack itemStack) {
|
||||
return EndStoneSmelterBlockEntity.canUseAsFuel(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferSlot(PlayerEntity player, int index) {
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
Slot slot = this.slots.get(index);
|
||||
if (slot != null && slot.hasStack()) {
|
||||
ItemStack itemStack2 = slot.getStack();
|
||||
itemStack = itemStack2.copy();
|
||||
if (index == 3) {
|
||||
if (insertItem(itemStack2, 4, 40, true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
slot.onStackChanged(itemStack2, itemStack);
|
||||
} else if (index != 2 && index != 1 && index != 0) {
|
||||
if (isSmeltable(itemStack2)) {
|
||||
if (!insertItem(itemStack2, 0, 2, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (isFuel(itemStack2)) {
|
||||
if (!this.insertItem(itemStack2, 2, 3, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (index >= 4 && index < 31) {
|
||||
if (!insertItem(itemStack2, 31, 40, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (index >= 31 && index < 40 && !insertItem(itemStack2, 4, 31, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!insertItem(itemStack2, 4, 40, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemStack2.isEmpty()) {
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.markDirty();
|
||||
}
|
||||
|
||||
if (itemStack2.getCount() == itemStack.getCount()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
slot.onTakeItem(player, itemStack2);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public int getSmeltProgress() {
|
||||
int time = this.propertyDelegate.get(2);
|
||||
int timeTotal = this.propertyDelegate.get(3);
|
||||
return timeTotal != 0 && time != 0 ? time * 24 / timeTotal : 0;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public int getFuelProgress() {
|
||||
int fuelTime = this.propertyDelegate.get(1);
|
||||
if (fuelTime == 0) {
|
||||
fuelTime = 200;
|
||||
}
|
||||
return this.propertyDelegate.get(0) * 13 / fuelTime;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public boolean isBurning() {
|
||||
return this.propertyDelegate.get(0) > 0;
|
||||
}
|
||||
}
|
||||
package ru.betterend.client.gui;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.SimpleInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeFinder;
|
||||
import net.minecraft.recipe.RecipeInputProvider;
|
||||
import net.minecraft.recipe.book.RecipeBookCategory;
|
||||
import net.minecraft.screen.AbstractRecipeScreenHandler;
|
||||
import net.minecraft.screen.ArrayPropertyDelegate;
|
||||
import net.minecraft.screen.PropertyDelegate;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.EndStoneSmelter;
|
||||
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
|
||||
import ru.betterend.client.gui.slot.SmelterFuelSlot;
|
||||
import ru.betterend.client.gui.slot.SmelterOutputSlot;
|
||||
import ru.betterend.recipe.builders.AlloyingRecipe;
|
||||
|
||||
public class EndStoneSmelterScreenHandler extends AbstractRecipeScreenHandler<Inventory> {
|
||||
|
||||
public final static ScreenHandlerType<EndStoneSmelterScreenHandler> HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(
|
||||
BetterEnd.makeID(EndStoneSmelter.ID), EndStoneSmelterScreenHandler::new);
|
||||
|
||||
private final Inventory inventory;
|
||||
private final PropertyDelegate propertyDelegate;
|
||||
protected final World world;
|
||||
|
||||
public EndStoneSmelterScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||
this(syncId, playerInventory, new SimpleInventory(4), new ArrayPropertyDelegate(4));
|
||||
}
|
||||
|
||||
public EndStoneSmelterScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory, PropertyDelegate propertyDelegate) {
|
||||
super(HANDLER_TYPE, syncId);
|
||||
this.inventory = inventory;
|
||||
this.propertyDelegate = propertyDelegate;
|
||||
this.world = playerInventory.player.world;
|
||||
|
||||
this.addProperties(propertyDelegate);
|
||||
this.addSlot(new Slot(inventory, 0, 45, 17));
|
||||
this.addSlot(new Slot(inventory, 1, 67, 17));
|
||||
this.addSlot(new SmelterFuelSlot(this, inventory, 2, 56, 53));
|
||||
this.addSlot(new SmelterOutputSlot(playerInventory.player, inventory, 3, 129, 35));
|
||||
|
||||
for(int i = 0; i < 3; ++i) {
|
||||
for(int j = 0; j < 9; ++j) {
|
||||
this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < 9; ++i) {
|
||||
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateRecipeFinder(RecipeFinder finder) {
|
||||
if (inventory instanceof RecipeInputProvider) {
|
||||
((RecipeInputProvider) inventory).provideRecipeInputs(finder);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCraftingSlots() {
|
||||
this.inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Recipe<? super Inventory> recipe) {
|
||||
return recipe.matches(this.inventory, this.world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCraftingResultSlotIndex() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCraftingWidth() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCraftingHeight() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCraftingSlotCount() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeBookCategory getCategory() {
|
||||
return RecipeBookCategory.BLAST_FURNACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
return this.inventory.canPlayerUse(player);
|
||||
}
|
||||
|
||||
protected boolean isSmeltable(ItemStack itemStack) {
|
||||
return this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, new SimpleInventory(new ItemStack[]{itemStack}), this.world).isPresent();
|
||||
}
|
||||
|
||||
public boolean isFuel(ItemStack itemStack) {
|
||||
return EndStoneSmelterBlockEntity.canUseAsFuel(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferSlot(PlayerEntity player, int index) {
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
Slot slot = this.slots.get(index);
|
||||
if (slot != null && slot.hasStack()) {
|
||||
ItemStack itemStack2 = slot.getStack();
|
||||
itemStack = itemStack2.copy();
|
||||
if (index == 3) {
|
||||
if (insertItem(itemStack2, 4, 40, true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
slot.onStackChanged(itemStack2, itemStack);
|
||||
} else if (index != 2 && index != 1 && index != 0) {
|
||||
if (isSmeltable(itemStack2)) {
|
||||
if (!insertItem(itemStack2, 0, 2, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (isFuel(itemStack2)) {
|
||||
if (!this.insertItem(itemStack2, 2, 3, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (index >= 4 && index < 31) {
|
||||
if (!insertItem(itemStack2, 31, 40, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (index >= 31 && index < 40 && !insertItem(itemStack2, 4, 31, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!insertItem(itemStack2, 4, 40, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemStack2.isEmpty()) {
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.markDirty();
|
||||
}
|
||||
|
||||
if (itemStack2.getCount() == itemStack.getCount()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
slot.onTakeItem(player, itemStack2);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public int getSmeltProgress() {
|
||||
int time = this.propertyDelegate.get(2);
|
||||
int timeTotal = this.propertyDelegate.get(3);
|
||||
return timeTotal != 0 && time != 0 ? time * 24 / timeTotal : 0;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public int getFuelProgress() {
|
||||
int fuelTime = this.propertyDelegate.get(1);
|
||||
if (fuelTime == 0) {
|
||||
fuelTime = 200;
|
||||
}
|
||||
return this.propertyDelegate.get(0) * 13 / fuelTime;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public boolean isBurning() {
|
||||
return this.propertyDelegate.get(0) > 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
package ru.betterend.client.gui.slot;
|
||||
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.FurnaceFuelSlot;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import ru.betterend.client.gui.EndStoneSmelterScreenHandler;
|
||||
|
||||
public class SmelterFuelSlot extends Slot {
|
||||
|
||||
private final EndStoneSmelterScreenHandler handler;
|
||||
|
||||
public SmelterFuelSlot(EndStoneSmelterScreenHandler handler, Inventory inventory, int index, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return this.handler.isFuel(stack) || FurnaceFuelSlot.isBucket(stack);
|
||||
}
|
||||
|
||||
public int getMaxItemCount(ItemStack stack) {
|
||||
return FurnaceFuelSlot.isBucket(stack) ? 1 : super.getMaxItemCount(stack);
|
||||
}
|
||||
}
|
||||
package ru.betterend.client.gui.slot;
|
||||
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.FurnaceFuelSlot;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import ru.betterend.client.gui.EndStoneSmelterScreenHandler;
|
||||
|
||||
public class SmelterFuelSlot extends Slot {
|
||||
|
||||
private final EndStoneSmelterScreenHandler handler;
|
||||
|
||||
public SmelterFuelSlot(EndStoneSmelterScreenHandler handler, Inventory inventory, int index, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return this.handler.isFuel(stack) || FurnaceFuelSlot.isBucket(stack);
|
||||
}
|
||||
|
||||
public int getMaxItemCount(ItemStack stack) {
|
||||
return FurnaceFuelSlot.isBucket(stack) ? 1 : super.getMaxItemCount(stack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
package ru.betterend.client.gui.slot;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
|
||||
|
||||
public class SmelterOutputSlot extends Slot {
|
||||
|
||||
private PlayerEntity player;
|
||||
private int amount;
|
||||
|
||||
public SmelterOutputSlot(PlayerEntity player, Inventory inventory, int index, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ItemStack takeStack(int amount) {
|
||||
if (this.hasStack()) {
|
||||
this.amount += Math.min(amount, this.getStack().getCount());
|
||||
}
|
||||
|
||||
return super.takeStack(amount);
|
||||
}
|
||||
|
||||
public ItemStack onTakeItem(PlayerEntity player, ItemStack stack) {
|
||||
this.onCrafted(stack);
|
||||
super.onTakeItem(player, stack);
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected void onCrafted(ItemStack stack, int amount) {
|
||||
this.amount += amount;
|
||||
this.onCrafted(stack);
|
||||
}
|
||||
|
||||
protected void onCrafted(ItemStack stack) {
|
||||
stack.onCraft(this.player.world, this.player, this.amount);
|
||||
if (!this.player.world.isClient && this.inventory instanceof EndStoneSmelterBlockEntity) {
|
||||
((EndStoneSmelterBlockEntity) this.inventory).dropExperience(player);
|
||||
}
|
||||
this.amount = 0;
|
||||
}
|
||||
}
|
||||
package ru.betterend.client.gui.slot;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
|
||||
|
||||
public class SmelterOutputSlot extends Slot {
|
||||
|
||||
private PlayerEntity player;
|
||||
private int amount;
|
||||
|
||||
public SmelterOutputSlot(PlayerEntity player, Inventory inventory, int index, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ItemStack takeStack(int amount) {
|
||||
if (this.hasStack()) {
|
||||
this.amount += Math.min(amount, this.getStack().getCount());
|
||||
}
|
||||
|
||||
return super.takeStack(amount);
|
||||
}
|
||||
|
||||
public ItemStack onTakeItem(PlayerEntity player, ItemStack stack) {
|
||||
this.onCrafted(stack);
|
||||
super.onTakeItem(player, stack);
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected void onCrafted(ItemStack stack, int amount) {
|
||||
this.amount += amount;
|
||||
this.onCrafted(stack);
|
||||
}
|
||||
|
||||
protected void onCrafted(ItemStack stack) {
|
||||
stack.onCraft(this.player.world, this.player, this.amount);
|
||||
if (!this.player.world.isClient && this.inventory instanceof EndStoneSmelterBlockEntity) {
|
||||
((EndStoneSmelterBlockEntity) this.inventory).dropExperience(player);
|
||||
}
|
||||
this.amount = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue