Skip to content

Commit f7d6ea6

Browse files
committed
allow overriding CraftingBlock output
1 parent 2571811 commit f7d6ea6

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>io.github.mooy1</groupId>
88
<artifactId>InfinityLib</artifactId>
9-
<version>1.1.1</version>
9+
<version>1.1.2</version>
1010

1111
<properties>
1212
<maven.compiler.source>1.8</maven.compiler.source>

src/main/java/io/github/mooy1/infinitylib/machines/AbstractMachineBlock.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
1717
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
1818
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
19-
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
2019
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
2120
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
2221
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@@ -25,10 +24,6 @@
2524
@ParametersAreNonnullByDefault
2625
public abstract class AbstractMachineBlock extends TickingMenuBlock implements EnergyNetComponent {
2726

28-
public static final ItemStack PROCESSING_ITEM = new CustomItemStack(Material.LIME_STAINED_GLASS_PANE, "&aProcessing...");
29-
public static final ItemStack NO_ENERGY_ITEM = new CustomItemStack(Material.RED_STAINED_GLASS_PANE, "&cNot enough energy!");
30-
public static final ItemStack IDLE_ITEM = new CustomItemStack(Material.BLACK_STAINED_GLASS_PANE, "&8Idle");
31-
3227
protected MachineLayout layout = MachineLayout.MACHINE_DEFAULT;
3328
protected int energyPerTick = -1;
3429
protected int energyCapacity = -1;

src/main/java/io/github/mooy1/infinitylib/machines/CraftingBlock.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,11 @@ private boolean craft(Block b, BlockMenu menu, Player p) {
7272
CraftingBlockRecipe recipe = getOutput(b, input);
7373
if (recipe != null) {
7474
if (recipe.check(p)) {
75-
if (menu.fits(recipe.output, layout.outputSlots())) {
76-
ItemStack item = recipe.output.clone();
77-
onSuccessfulCraft(b, menu, p, recipe.output);
78-
menu.pushItem(item, layout.outputSlots());
75+
ItemStack output = recipe.output.clone();
76+
if (output(b, menu, p, output)) {
77+
onSuccessfulCraft(b, menu, p, output);
7978
recipe.consume(input);
8079
tick(b, menu);
81-
} else {
82-
onNoRoom(p);
8380
}
8481
}
8582
} else {
@@ -141,6 +138,16 @@ protected ItemStack getStatus(Block b, BlockMenu menu) {
141138
}
142139
}
143140

141+
protected boolean output(Block b, BlockMenu menu, Player p, ItemStack output) {
142+
if (menu.fits(output, layout.outputSlots())) {
143+
menu.pushItem(output, layout.outputSlots());
144+
return true;
145+
} else {
146+
onNoRoom(p);
147+
return false;
148+
}
149+
}
150+
144151
protected boolean canCraft(Block b, Player p) {
145152
return true;
146153
}

src/main/java/io/github/mooy1/infinitylib/machines/MenuBlock.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
@ParametersAreNonnullByDefault
3030
public abstract class MenuBlock extends SlimefunItem {
3131

32+
public static final ItemStack PROCESSING_ITEM = new CustomItemStack(Material.LIME_STAINED_GLASS_PANE, "&aProcessing...");
33+
public static final ItemStack NO_ENERGY_ITEM = new CustomItemStack(Material.RED_STAINED_GLASS_PANE, "&cNot enough energy!");
34+
public static final ItemStack IDLE_ITEM = new CustomItemStack(Material.BLACK_STAINED_GLASS_PANE, "&8Idle");
3235
public static final ItemStack NO_ROOM_ITEM = new CustomItemStack(Material.ORANGE_STAINED_GLASS_PANE, "&6Not enough room!");
3336
public static final ItemStack OUTPUT_BORDER = new CustomItemStack(ChestMenuUtils.getOutputSlotTexture(), "&6Output");
3437
public static final ItemStack INPUT_BORDER = new CustomItemStack(ChestMenuUtils.getInputSlotTexture(), "&9Input");

0 commit comments

Comments
 (0)