Skip to content

Commit

Permalink
Merge pull request #305 from Gu-ZT/AutoCrafter
Browse files Browse the repository at this point in the history
使合成器需要消耗电力
  • Loading branch information
XeKr authored Apr 17, 2024
2 parents d2b4569 + 88a8ee6 commit 6738175
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository;
import dev.dubhe.anvilcraft.api.depository.IItemDepository;
import dev.dubhe.anvilcraft.api.depository.ItemDepositoryHelper;
import dev.dubhe.anvilcraft.api.power.IPowerConsumer;
import dev.dubhe.anvilcraft.api.power.PowerGrid;
import dev.dubhe.anvilcraft.block.AutoCrafterBlock;
import dev.dubhe.anvilcraft.init.ModBlocks;
import dev.dubhe.anvilcraft.init.ModMenuTypes;
import dev.dubhe.anvilcraft.inventory.AutoCrafterMenu;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
Expand Down Expand Up @@ -44,7 +47,12 @@

@Getter
@SuppressWarnings("NullableProblems")
public class AutoCrafterBlockEntity extends BaseMachineBlockEntity implements IFilterBlockEntity {
public class AutoCrafterBlockEntity extends BaseMachineBlockEntity implements IFilterBlockEntity, IPowerConsumer {
@Getter
@Setter
private PowerGrid grid;
@Getter
private final int inputPower = 1;
private final Deque<AutoCrafterCache> cache = new ArrayDeque<>();
private final FilteredItemDepository depository = new FilteredItemDepository.Pollable(9) {
@Override
Expand Down Expand Up @@ -150,6 +158,7 @@ public void tick(@NotNull Level level, BlockPos pos) {
}

private boolean canCraft() {
if (grid == null || !grid.isWork()) return false;
if (cooldown > 0) return false;
if (!depository.isFilterEnabled()) return true;
for (int i = 0; i < depository.getSlots(); i++) {
Expand Down Expand Up @@ -296,6 +305,11 @@ public FilteredItemDepository getFilteredItemDepository() {
return this.depository;
}

@Override
public @NotNull BlockPos getPos() {
return this.getBlockPos();
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public static class AutoCrafterCache implements Predicate<Container> {
private final Container container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ public void renderSlot(@NotNull GuiGraphics guiGraphics, @NotNull Slot slot) {
IFilterScreen.super.renderSlot(guiGraphics, slot);
}

@Override
protected void renderTooltip(@NotNull GuiGraphics guiGraphics, int x, int y) {
super.renderTooltip(guiGraphics, x, y);
this.renderSlotTooltip(guiGraphics, x, y);
}

protected void renderSlotTooltip(@NotNull GuiGraphics guiGraphics, int x, int y) {
if (this.hoveredSlot == null) return;
if (!this.isFilterEnabled()) return;
if (!this.isSlotDisabled(this.hoveredSlot.getContainerSlot())) return;
guiGraphics.renderTooltip(this.font, Component.literal("screen.anvilcraft.slot.disable.tooltip"), x, y);
}

@Override
public IFilterMenu getFilterMenu() {
return this.menu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ public void renderSlot(@NotNull GuiGraphics guiGraphics, @NotNull Slot slot) {
IFilterScreen.super.renderSlot(guiGraphics, slot);
}

@Override
protected void renderTooltip(@NotNull GuiGraphics guiGraphics, int x, int y) {
super.renderTooltip(guiGraphics, x, y);
this.renderSlotTooltip(guiGraphics, x, y);
}

protected void renderSlotTooltip(@NotNull GuiGraphics guiGraphics, int x, int y) {
if (this.hoveredSlot == null) return;
if (!this.isFilterEnabled()) return;
if (!this.isSlotDisabled(this.hoveredSlot.getContainerSlot())) return;
guiGraphics.renderTooltip(this.font, Component.literal("screen.anvilcraft.slot.disable.tooltip"), x, y);
}

@Override
public IFilterMenu getFilterMenu() {
return menu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import dev.dubhe.anvilcraft.client.gui.component.EnableFilterButton;
import dev.dubhe.anvilcraft.inventory.IFilterMenu;
import dev.dubhe.anvilcraft.network.MachineEnableFilterPack;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public static void init(RegistrateLangProvider provider) {
provider.add("screen.anvilcraft.button.off", "off");
provider.add("screen.anvilcraft.button.on", "on");
provider.add("screen.anvilcraft.button.record", "Retention item filtering: %s");
provider.add("screen.anvilcraft.button.record.tooltip",
"When activated, the synthesizer must fill all slots (including the cover) in order to start crafting");
provider.add("screen.anvilcraft.slot.disable.tooltip", "Use item clicks to set filter");
provider.add("screen.anvilcraft.royal_grindstone.remove_curse_number", "Remove %i curse number");
provider.add("screen.anvilcraft.royal_grindstone.remove_repair_cost", "Remove %i repair cost");
provider.add("screen.anvilcraft.royal_grindstone.title", "Remove curse and repair cost");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@
"screen.anvilcraft.button.off": "ɟɟo",
"screen.anvilcraft.button.on": "uo",
"screen.anvilcraft.button.record": "%s :buıɹǝʇןıɟ ɯǝʇı uoıʇuǝʇǝᴚ",
"screen.anvilcraft.button.record.tooltip": "buıʇɟɐɹɔ ʇɹɐʇs oʇ ɹǝpɹo uı )ɹǝʌoɔ ǝɥʇ buıpnןɔuı( sʇoןs ןןɐ ןןıɟ ʇsnɯ ɹǝzısǝɥʇuʎs ǝɥʇ 'pǝʇɐʌıʇɔɐ uǝɥM",
"screen.anvilcraft.royal_grindstone.remove_curse_number": "ɹǝqɯnu ǝsɹnɔ ı% ǝʌoɯǝᴚ",
"screen.anvilcraft.royal_grindstone.remove_repair_cost": "ʇsoɔ ɹıɐdǝɹ ı% ǝʌoɯǝᴚ",
"screen.anvilcraft.royal_grindstone.title": "ʇsoɔ ɹıɐdǝɹ puɐ ǝsɹnɔ ǝʌoɯǝᴚ",
"screen.anvilcraft.royal_steel_upgrade_smithing_template": "ǝʇɐןdɯǝ⟘ buıɥʇıɯS ǝpɐɹbd∩ ןǝǝʇS ןɐʎoᴚ",
"screen.anvilcraft.slot.disable.tooltip": "ɹǝʇןıɟ ʇǝs oʇ sʞɔıןɔ ɯǝʇı ǝs∩",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.additions_slot_description": "ʇobuI ןǝǝʇS ןɐʎoᴚ ǝɥʇ ʇnԀ",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.applies_to": "ǝxɐʞɔıԀ puoɯɐıᗡ ǝxɐʞɔıԀ uoɹI ǝxɐʞɔıԀ uǝpןo⅁ ǝxɐʞɔıԀ ʇsʎɥʇǝɯⱯ",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.base_slot_description": "ǝxɐʞɔıd ǝɥʇ ʇnԀ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@
"screen.anvilcraft.button.off": "off",
"screen.anvilcraft.button.on": "on",
"screen.anvilcraft.button.record": "Retention item filtering: %s",
"screen.anvilcraft.button.record.tooltip": "When activated, the synthesizer must fill all slots (including the cover) in order to start crafting",
"screen.anvilcraft.royal_grindstone.remove_curse_number": "Remove %i curse number",
"screen.anvilcraft.royal_grindstone.remove_repair_cost": "Remove %i repair cost",
"screen.anvilcraft.royal_grindstone.title": "Remove curse and repair cost",
"screen.anvilcraft.royal_steel_upgrade_smithing_template": "Royal Steel Upgrade Smithing Template",
"screen.anvilcraft.slot.disable.tooltip": "Use item clicks to set filter",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.additions_slot_description": "Put the Royal Steel Ingot",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.applies_to": "Amethyst Pickaxe Golden Pickaxe Iron Pickaxe Diamond Pickaxe",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.base_slot_description": "Put the pickaxe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@
"screen.anvilcraft.button.off": "ɟɟo",
"screen.anvilcraft.button.on": "uo",
"screen.anvilcraft.button.record": "%s :buıɹǝʇןıɟ ɯǝʇı uoıʇuǝʇǝᴚ",
"screen.anvilcraft.button.record.tooltip": "buıʇɟɐɹɔ ʇɹɐʇs oʇ ɹǝpɹo uı )ɹǝʌoɔ ǝɥʇ buıpnןɔuı( sʇoןs ןןɐ ןןıɟ ʇsnɯ ɹǝzısǝɥʇuʎs ǝɥʇ 'pǝʇɐʌıʇɔɐ uǝɥM",
"screen.anvilcraft.royal_grindstone.remove_curse_number": "ɹǝqɯnu ǝsɹnɔ ı% ǝʌoɯǝᴚ",
"screen.anvilcraft.royal_grindstone.remove_repair_cost": "ʇsoɔ ɹıɐdǝɹ ı% ǝʌoɯǝᴚ",
"screen.anvilcraft.royal_grindstone.title": "ʇsoɔ ɹıɐdǝɹ puɐ ǝsɹnɔ ǝʌoɯǝᴚ",
"screen.anvilcraft.royal_steel_upgrade_smithing_template": "ǝʇɐןdɯǝ⟘ buıɥʇıɯS ǝpɐɹbd∩ ןǝǝʇS ןɐʎoᴚ",
"screen.anvilcraft.slot.disable.tooltip": "ɹǝʇןıɟ ʇǝs oʇ sʞɔıןɔ ɯǝʇı ǝs∩",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.additions_slot_description": "ʇobuI ןǝǝʇS ןɐʎoᴚ ǝɥʇ ʇnԀ",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.applies_to": "ǝxɐʞɔıԀ puoɯɐıᗡ ǝxɐʞɔıԀ uoɹI ǝxɐʞɔıԀ uǝpןo⅁ ǝxɐʞɔıԀ ʇsʎɥʇǝɯⱯ",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.base_slot_description": "ǝxɐʞɔıd ǝɥʇ ʇnԀ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@
"screen.anvilcraft.button.off": "off",
"screen.anvilcraft.button.on": "on",
"screen.anvilcraft.button.record": "Retention item filtering: %s",
"screen.anvilcraft.button.record.tooltip": "When activated, the synthesizer must fill all slots (including the cover) in order to start crafting",
"screen.anvilcraft.royal_grindstone.remove_curse_number": "Remove %i curse number",
"screen.anvilcraft.royal_grindstone.remove_repair_cost": "Remove %i repair cost",
"screen.anvilcraft.royal_grindstone.title": "Remove curse and repair cost",
"screen.anvilcraft.royal_steel_upgrade_smithing_template": "Royal Steel Upgrade Smithing Template",
"screen.anvilcraft.slot.disable.tooltip": "Use item clicks to set filter",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.additions_slot_description": "Put the Royal Steel Ingot",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.applies_to": "Amethyst Pickaxe Golden Pickaxe Iron Pickaxe Diamond Pickaxe",
"screen.anvilcraft.smithing_template.royal_steel_upgrade_smithing_template.base_slot_description": "Put the pickaxe",
Expand Down

0 comments on commit 6738175

Please sign in to comment.