/
PulseBase.java
162 lines (130 loc) · 5.87 KB
/
PulseBase.java
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package knightminer.tcomplement.common;
import java.util.Locale;
import knightminer.tcomplement.TinkersComplement;
import knightminer.tcomplement.library.Util;
import knightminer.tcomplement.melter.ModuleMelter;
import knightminer.tcomplement.plugin.ceramics.CeramicsPlugin;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import slimeknights.mantle.block.BlockStairsBase;
import slimeknights.mantle.block.EnumBlock;
import slimeknights.mantle.block.EnumBlockSlab;
import slimeknights.mantle.item.ItemBlockMeta;
import slimeknights.mantle.item.ItemBlockSlab;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.TinkerRegistry;
import slimeknights.tconstruct.library.tools.Pattern;
import slimeknights.tconstruct.library.tools.ToolPart;
import slimeknights.tconstruct.smeltery.TinkerSmeltery;
import slimeknights.tconstruct.tools.TinkerTools;
public class PulseBase {
/* Loaded */
protected boolean isToolsLoaded() {
return TConstruct.pulseManager.isPulseLoaded(TinkerTools.PulseId);
}
protected boolean isSmelteryLoaded() {
return TConstruct.pulseManager.isPulseLoaded(TinkerSmeltery.PulseId);
}
protected boolean isMelterLoaded() {
return TinkersComplement.pulseManager.isPulseLoaded(ModuleMelter.pulseID);
}
protected boolean isCeramicsPluginLoaded() {
return TinkersComplement.pulseManager.isPulseLoaded(CeramicsPlugin.pulseID);
}
/* Normal registration */
protected static <T extends Block> T registerBlock(IForgeRegistry<Block> registry, T block, String name) {
if(!name.equals(name.toLowerCase(Locale.US))) {
throw new IllegalArgumentException(
String.format("Unlocalized names need to be all lowercase! Block: %s", name));
}
String prefixedName = Util.prefix(name);
block.setUnlocalizedName(prefixedName);
register(registry, block, name);
return block;
}
protected static <E extends Enum<E> & EnumBlock.IEnumMeta & IStringSerializable> BlockStairsBase registerBlockStairsFrom(
IForgeRegistry<Block> registry, EnumBlock<E> block, E value, String name) {
return registerBlock(registry, new BlockStairsBase(block.getDefaultState().withProperty(block.prop, value)),
name);
}
protected static <T extends Block> T registerItemBlock(IForgeRegistry<Item> registry, T block) {
ItemBlock itemBlock = new ItemBlockMeta(block);
itemBlock.setUnlocalizedName(block.getUnlocalizedName());
register(registry, itemBlock, block.getRegistryName());
return block;
}
protected static <T extends EnumBlock<?>> T registerEnumItemBlock(IForgeRegistry<Item> registry, T block) {
ItemBlock itemBlock = new ItemBlockMeta(block);
itemBlock.setUnlocalizedName(block.getUnlocalizedName());
register(registry, itemBlock, block.getRegistryName());
ItemBlockMeta.setMappingProperty(block, block.prop);
return block;
}
@SuppressWarnings("unchecked")
protected static <T extends Block> T registerItemBlock(IForgeRegistry<Item> registry, ItemBlock itemBlock) {
itemBlock.setUnlocalizedName(itemBlock.getBlock().getUnlocalizedName());
register(registry, itemBlock, itemBlock.getBlock().getRegistryName());
return (T) itemBlock.getBlock();
}
protected static <T extends ItemBlock> T registerItemBlock(IForgeRegistry<Item> registry, T itemBlock, IProperty<?> property) {
itemBlock.setUnlocalizedName(itemBlock.getBlock().getUnlocalizedName());
register(registry, itemBlock, itemBlock.getBlock().getRegistryName());
ItemBlockMeta.setMappingProperty(itemBlock.getBlock(), property);
return itemBlock;
}
protected static ItemBlockMeta registerItemBlock(IForgeRegistry<Item> registry, Block block, IProperty<?> property) {
return registerItemBlock(registry, new ItemBlockMeta(block), property);
}
protected static <T extends EnumBlockSlab<?>> T registerEnumItemBlockSlab(IForgeRegistry<Item> registry, T block) {
@SuppressWarnings({"unchecked", "rawtypes"})
ItemBlock itemBlock = new ItemBlockSlab(block);
itemBlock.setUnlocalizedName(block.getUnlocalizedName());
register(registry, itemBlock, block.getRegistryName());
ItemBlockMeta.setMappingProperty(block, block.prop);
return block;
}
/**
* Sets the correct unlocalized name and registers the item.
*/
protected static <T extends Item> T registerItem(IForgeRegistry<Item> registry, T item, String name) {
if(!name.equals(name.toLowerCase(Locale.US))) {
throw new IllegalArgumentException(
String.format("Unlocalized names need to be all lowercase! Item: %s", name));
}
item.setUnlocalizedName(Util.prefix(name));
item.setRegistryName(Util.getResource(name));
registry.register(item);
return item;
}
protected static <T extends IForgeRegistryEntry<T>> T register(IForgeRegistry<T> registry, T thing, String name) {
thing.setRegistryName(Util.getResource(name));
registry.register(thing);
return thing;
}
protected static <T extends IForgeRegistryEntry<T>> T register(IForgeRegistry<T> registry, T thing,
ResourceLocation name) {
thing.setRegistryName(name);
registry.register(thing);
return thing;
}
protected static void registerTE(Class<? extends TileEntity> teClazz, String name) {
if(!name.equals(name.toLowerCase(Locale.US))) {
throw new IllegalArgumentException(
String.format("Unlocalized names need to be all lowercase! TE: %s", name));
}
GameRegistry.registerTileEntity(teClazz, Util.resource(name));
}
/* Tinkers Registration */
protected static void registerStencil(ToolPart part) {
TinkerRegistry.registerStencilTableCrafting(Pattern.setTagForPart(new ItemStack(TinkerTools.pattern), part));
}
}