-
-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathTurntableBuilder.java
More file actions
83 lines (69 loc) · 3.12 KB
/
Copy pathTurntableBuilder.java
File metadata and controls
83 lines (69 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.blamejared.compat.betterwithmods.base.blockrecipes;
import betterwithmods.common.BWRegistry;
import betterwithmods.common.registry.block.managers.CraftingManagerBlock;
import betterwithmods.common.registry.block.recipe.TurntableRecipe;
import com.blamejared.ModTweaker;
import com.blamejared.mtlib.helpers.InputHelper;
import com.blamejared.mtlib.helpers.LogHelper;
import com.blamejared.mtlib.utils.BaseAction;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import stanhebben.zenscript.annotations.ZenMethod;
import java.util.function.Supplier;
public class TurntableBuilder extends BlockRecipeBuilder<TurntableRecipe> {
private int rotations = 8;
private IBlockState productState = Blocks.AIR.getDefaultState();
public TurntableBuilder(Supplier<CraftingManagerBlock<TurntableRecipe>> registry, String name) {
super(registry, name);
}
@ZenMethod
public TurntableBuilder setRotations(int rotations) {
this.rotations = rotations;
return this;
}
@SuppressWarnings("deprecation")
@ZenMethod
public TurntableBuilder setProductState(IItemStack productState) {
if (InputHelper.isABlock(productState)) {
Block block = CraftTweakerMC.getBlock(productState);
this.productState = block.getStateFromMeta(productState.getMetadata());
} else {
LogHelper.logError(String.format("%s Product State must create a valid BlockState", productState.getDisplayName()), new IllegalArgumentException(String.format("%s Product State must create a valid BlockState", productState.getDisplayName())));
}
return this;
}
@ZenMethod
public TurntableBuilder buildRecipe(IIngredient input, IItemStack[] outputs) {
_buildRecipe(input,outputs);
return this;
}
@Override
public void build() {
addRecipe(new TurntableRecipe(input, outputs, productState, rotations));
}
public void removeRecipe(IBlockState productState) {
ModTweaker.LATE_REMOVALS.add(new TurntableRemoveProduct(name, productState));
}
public class TurntableRemoveProduct extends BaseAction {
private final IBlockState productState;
private TurntableRemoveProduct(String name, IBlockState productState) {
super(name);
this.productState = productState;
}
@Override
public void apply() {
if (!BWRegistry.TURNTABLE.remove(productState)) {
LogHelper.logWarning(String.format("No recipes were removed for input %s", getRecipeInfo(productState)));
} else {
LogHelper.logInfo(String.format("Succesfully removed all recipes with %s as input", getRecipeInfo(productState)));
}
}
private String getRecipeInfo(IBlockState productState) {
return String.format("%s - %s", name, productState.getBlock().toString()+"@"+productState.getBlock().getMetaFromState(productState));
}
}
}