Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.pylonmc.rebar.block.base.RebarTickingBlock;
import io.github.pylonmc.rebar.block.base.RebarVirtualInventoryBlock;
import io.github.pylonmc.rebar.block.context.BlockCreateContext;
import io.github.pylonmc.rebar.datatypes.RebarSerializers;
import io.github.pylonmc.rebar.fluid.RebarFluid;
import io.github.pylonmc.rebar.i18n.RebarArgument;
import io.github.pylonmc.rebar.item.builder.ItemStackBuilder;
Expand All @@ -14,8 +15,8 @@
import io.github.pylonmc.rebar.util.gui.unit.UnitFormat;
import kotlin.Pair;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TranslatableComponent;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
Expand All @@ -28,16 +29,23 @@
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.inventory.VirtualInventory;
import xyz.xenondevs.invui.item.AbstractItem;
import xyz.xenondevs.invui.item.Item;
import xyz.xenondevs.invui.item.ItemProvider;

import java.util.Map;

import static io.github.pylonmc.pylon.util.PylonUtils.pylonKey;

public final class SmelteryCaster extends SmelteryComponent implements
RebarGuiBlock,
RebarVirtualInventoryBlock,
RebarTickingBlock,
RebarLogisticBlock {

private static final NamespacedKey AUTO_CAST_KEY = pylonKey("auto_cast");

private boolean autoCast = false;

private @Nullable RebarFluid bottomFluid = null;

@SuppressWarnings("unused")
Expand All @@ -46,16 +54,22 @@ public SmelteryCaster(@NotNull Block block, @NotNull BlockCreateContext context)
setTickInterval(SmelteryController.TICK_INTERVAL);
}

@SuppressWarnings("unused")
@SuppressWarnings({"unused", "DataFlowIssue"})
public SmelteryCaster(@NotNull Block block, @NotNull PersistentDataContainer pdc) {
super(block, pdc);
this.autoCast = pdc.get(AUTO_CAST_KEY, RebarSerializers.BOOLEAN);
}

@Override
public void postInitialise() {
createLogisticGroup("output", LogisticGroupType.OUTPUT, inventory);
}

@Override
public void write(@NotNull PersistentDataContainer pdc) {
pdc.set(AUTO_CAST_KEY, RebarSerializers.BOOLEAN, autoCast);
}

private final VirtualInventory inventory = new VirtualInventory(1);
private final CastItem castItem = new CastItem();

Expand All @@ -64,10 +78,20 @@ public void postInitialise() {
return Gui.builder()
.setStructure(
"# # # # # # # # #",
"# # # # a # # # #",
"# # # # c # # # #",
"# # # # x # # # #",
"# # # # # # # # #"
)
.addIngredient('a', Item.builder()
.setItemProvider(viewer -> ItemStackBuilder.of(autoCast ? Material.GREEN_STAINED_GLASS_PANE : Material.YELLOW_STAINED_GLASS_PANE)
.name(Component.translatable("pylon.gui.smeltery_caster.auto_cast",
RebarArgument.of("status", autoCast ? Component.translatable("pylon.gui.status.on") : Component.translatable("pylon.gui.status.off"))
))
)
.addClickHandler(click -> autoCast = !autoCast)
.updateOnClick()
)
.addIngredient('c', castItem)
.addIngredient('x', inventory)
.addIngredient('#', GuiItems.background())
Expand All @@ -82,64 +106,58 @@ private class CastItem extends AbstractItem {
CastingRecipe recipe = (bottomFluid == null) ? null : CastingRecipe.getCastRecipeFor(bottomFluid);
if (controller == null || bottomFluid == null || recipe == null) {
return ItemStackBuilder.of(Material.BARRIER)
.name(casterKey("cannot_cast"));
.name(Component.translatable("pylon.gui.smeltery_caster.cannot_cast"));
}
ItemStack result = recipe.result();
Component name = result.effectiveName();
double temperature = recipe.temperature();
if (controller.getTemperature() < temperature) {
return ItemStackBuilder.of(result.getType())
.name(casterKey("cannot_cast"))
.lore(casterKey(
"too_cold",
.name(Component.translatable("pylon.gui.smeltery_caster.cannot_cast"))
.lore(Component.translatable("pylon.gui.smeltery_caster.too_cold",
RebarArgument.of("item", name),
RebarArgument.of("temperature", temperature)
));
RebarArgument.of("temperature", temperature)));
}
double bottomAmount = controller.getFluidAmount(bottomFluid);
if (bottomAmount < recipe.input().amountMillibuckets()) {
return ItemStackBuilder.of(result.getType())
.name(casterKey("cannot_cast"))
.lore(casterKey(
"not_enough",
.name(Component.translatable("pylon.gui.smeltery_caster.cannot_cast"))
.lore(Component.translatable("pylon.gui.smeltery_caster.not_enough",
RebarArgument.of("fluid", bottomFluid.getName()),
RebarArgument.of("needed", UnitFormat.MILLIBUCKETS.format(recipe.input().amountMillibuckets())),
RebarArgument.of("amount", UnitFormat.MILLIBUCKETS.format(bottomAmount)
.decimalPlaces(1))
));
.decimalPlaces(1))));
}
return ItemStackBuilder.of(result.getType())
.name(casterKey("cast"))
.lore(casterKey(
"click_to_cast",
.name(Component.translatable("pylon.gui.smeltery_caster.cast"))
.lore(Component.translatable("pylon.gui.smeltery_caster.click_to_cast",
RebarArgument.of("amount", UnitFormat.MILLIBUCKETS.format(bottomAmount)),
RebarArgument.of("needed", UnitFormat.MILLIBUCKETS.format(recipe.input().amountMillibuckets())),
RebarArgument.of("fluid", bottomFluid.getName())
));
RebarArgument.of("fluid", bottomFluid.getName())));
}

@Override
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull Click click) {
SmelteryController controller = getController();
if (controller == null || bottomFluid == null) return;

CastingRecipe recipe = CastingRecipe.getCastRecipeFor(bottomFluid);
if (recipe == null || controller.getTemperature() < recipe.temperature() || controller.getFluidAmount(bottomFluid) < recipe.input().amountMillibuckets())
return;
cast();
}
}

ItemStack result = recipe.result();
if (!inventory.canHold(result)) {
return;
}
private void cast() {
SmelteryController controller = getController();
if (controller == null || bottomFluid == null) return;

inventory.addItem(null, result);
CastingRecipe recipe = CastingRecipe.getCastRecipeFor(bottomFluid);
if (recipe == null || controller.getTemperature() < recipe.temperature() || controller.getFluidAmount(bottomFluid) < recipe.input().amountMillibuckets())
return;

controller.removeFluid(bottomFluid, recipe.input().amountMillibuckets());
ItemStack result = recipe.result();
if (!inventory.canHold(result)) {
return;
}

private static TranslatableComponent casterKey(@NotNull String subkey, @NotNull RebarArgument @NotNull ... args) {
return Component.translatable("pylon.gui.smeltery_caster." + subkey, args);
}
inventory.addItem(null, result);

controller.removeFluid(bottomFluid, recipe.input().amountMillibuckets());
}

@Override
Expand All @@ -159,6 +177,9 @@ public void tick() {
} else {
this.bottomFluid = bottomFluid.getFirst();
}
if (autoCast) {
cast();
}
}
castItem.notifyWindows();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,7 @@ gui:
too_cold: "<red>Temperature too low to cast, needs at least %temperature%"
not_enough: "<red>Not enough %fluid% to cast (%amount%/%needed%)"
click_to_cast: "<insn>Click</insn> to cast (%amount%/%needed%)"
auto_cast: "Auto cast: %status%"
progress_bar:
text: "%filled_bars%<dark_gray>%empty_bars% <gray>%progress%"
vacuum_hopper:
Expand Down
20 changes: 10 additions & 10 deletions src/main/resources/recipes/pylon/smeltery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pylon:copper_smelting:
pylon:slurry_raw_copper: 1000
outputs:
pylon:copper: 144
pylon:slurry: 500
pylon:slurry: 856
temperature: 1085

pylon:gold_smelting:
Expand All @@ -44,9 +44,9 @@ pylon:gold_smelting:
pylon:mercury: 1000
outputs:
pylon:gold: 144
pylon:slurry: 400
pylon:slurry_raw_tin: 200
pylon:mercury: 900
pylon:slurry: 200
pylon:slurry_raw_tin: 500
pylon:mercury: 800
temperature: 1064

pylon:iron_smelting:
Expand All @@ -55,19 +55,19 @@ pylon:iron_smelting:
pylon:slurry_carbon: 500
outputs:
pylon:iron: 144
pylon:slurry: 500
pylon:slurry: 1356
temperature: 1540

pylon:iron_smelting_with_sulfur:
inputs:
pylon:slurry_raw_iron: 1000
pylon:slurry_carbon: 500
pylon:sulfur: 100
pylon:sulfur: 144
outputs:
pylon:iron: 144
pylon:slurry: 400
pylon:cobalt: 16
pylon:nickel: 16
pylon:cobalt: 72
pylon:nickel: 72
pylon:slurry: 1356
temperature: 1540

pylon:tin_smelting:
Expand All @@ -76,7 +76,7 @@ pylon:tin_smelting:
pylon:slurry_carbon: 500
outputs:
pylon:tin: 144
pylon:slurry: 500
pylon:slurry: 1356
temperature: 250

pylon:redstone_decomposition:
Expand Down