Skip to content

Commit 002e40e

Browse files
authored
Allow for custom MachineBlocks (#126)
1 parent 9ab78b1 commit 002e40e

File tree

5 files changed

+197
-19
lines changed

5 files changed

+197
-19
lines changed

src/main/java/net/swedz/tesseract/neoforge/compat/mi/hack/HackedMachineRegistrationHelper.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import net.swedz.tesseract.neoforge.compat.mi.hook.MIHook;
3838
import net.swedz.tesseract.neoforge.compat.mi.hook.MIHookRegistry;
3939
import net.swedz.tesseract.neoforge.compat.mi.hook.MIHookTracker;
40+
import net.swedz.tesseract.neoforge.compat.mi.machine.MachineBlockCreator;
4041
import net.swedz.tesseract.neoforge.compat.mi.mixin.accessor.MIMachineRecipeTypesAccessor;
4142
import net.swedz.tesseract.neoforge.registry.common.CommonLootTableBuilders;
4243
import net.swedz.tesseract.neoforge.registry.common.CommonModelBuilders;
@@ -54,7 +55,12 @@
5455
import static aztech.modern_industrialization.machines.init.SingleBlockCraftingMachines.*;
5556

5657
/**
57-
* The methods in this helper class are copied from various places in MI's source code and modified to respect the registries and namespaces of whatever mod is registering the machine, rei categories, or recipe types.
58+
* <p>The methods in this helper class are copied from various places in MI's source code and modified to respect the
59+
* registries and namespaces of whatever mod is registering the machine, rei categories, or recipe types.</p>
60+
*
61+
* <p><b>It is recommended to not use these methods yourself.</b> They are intended for internal use within Tesseract
62+
* only. If you need to call one of these methods instead of a method in a hook context, there is something missing in
63+
* the hook context and that should be considered a bug / mistake.</p>
5864
*/
5965
public final class HackedMachineRegistrationHelper
6066
{
@@ -64,6 +70,7 @@ public final class HackedMachineRegistrationHelper
6470
@SafeVarargs
6571
public static Supplier<BlockEntityType<?>> registerMachine(MIHook hook,
6672
String englishName, String name,
73+
MachineBlockCreator blockCreator,
6774
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
6875
Consumer<BlockBehaviour.Properties> overrideProperties,
6976
boolean defaultMineableTags,
@@ -78,7 +85,7 @@ public static Supplier<BlockEntityType<?>> registerMachine(MIHook hook,
7885

7986
BlockWithItemHolder<?, ?> blockHolder = new BlockWithItemHolder<>(
8087
id, englishName,
81-
registry.blockRegistry(), (p) -> new MachineBlock(ctor, p),
88+
registry.blockRegistry(), (p) -> blockCreator == null ? new MachineBlock(ctor, p) : blockCreator.create(ctor, p),
8289
registry.itemRegistry(), BlockItem::new
8390
);
8491
blockHolder.item().sorted(registry.sortOrderMachines());
@@ -145,12 +152,13 @@ public static Supplier<BlockEntityType<?>> registerMachine(MIHook hook,
145152
@SafeVarargs
146153
public static Supplier<BlockEntityType<?>> registerMachine(MIHook hook,
147154
String englishName, String name,
155+
MachineBlockCreator blockCreator,
148156
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
149157
Consumer<BlockBehaviour.Properties> overrideProperties,
150158
Function<BEP, MachineBlockEntity> factory,
151159
Consumer<BlockEntityType<?>>... extraRegistrators)
152160
{
153-
return registerMachine(hook, englishName, name, modifyBlock, overrideProperties, true, factory, extraRegistrators);
161+
return registerMachine(hook, englishName, name, blockCreator, modifyBlock, overrideProperties, true, factory, extraRegistrators);
154162
}
155163

156164
@SafeVarargs
@@ -159,7 +167,7 @@ public static Supplier<BlockEntityType<?>> registerMachine(MIHook hook,
159167
Function<BEP, MachineBlockEntity> factory,
160168
Consumer<BlockEntityType<?>>... extraRegistrators)
161169
{
162-
return registerMachine(hook, englishName, name, null, null, factory, extraRegistrators);
170+
return registerMachine(hook, englishName, name, null, null, null, factory, extraRegistrators);
163171
}
164172

165173
/**

src/main/java/net/swedz/tesseract/neoforge/compat/mi/hook/context/listener/HatchMIHookContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private void registerHatch(String id, String englishName, String overlayFolder,
5353
boolean input,
5454
Consumer<BlockEntityType<?>>... extraRegistrators)
5555
{
56-
HackedMachineRegistrationHelper.registerMachine(hook, englishName, id, modifyBlock, overrideProperties, defaultMineableTags, (bep) -> factory.create(bep, input, hook.id(id)), extraRegistrators);
56+
HackedMachineRegistrationHelper.registerMachine(hook, englishName, id, null, modifyBlock, overrideProperties, defaultMineableTags, (bep) -> factory.create(bep, input, hook.id(id)), extraRegistrators);
5757
HackedMachineRegistrationHelper.addMachineModel(hook, id, casing, overlayFolder, true, false, true, false);
5858
}
5959

src/main/java/net/swedz/tesseract/neoforge/compat/mi/hook/context/listener/MultiblockMachinesMIHookContext.java

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.swedz.tesseract.neoforge.compat.mi.hack.HackedMachineRegistrationHelper;
1515
import net.swedz.tesseract.neoforge.compat.mi.hook.MIHook;
1616
import net.swedz.tesseract.neoforge.compat.mi.hook.context.MIHookContext;
17+
import net.swedz.tesseract.neoforge.compat.mi.machine.MachineBlockCreator;
1718
import net.swedz.tesseract.neoforge.registry.holder.BlockWithItemHolder;
1819

1920
import java.util.function.Consumer;
@@ -29,17 +30,30 @@ public MultiblockMachinesMIHookContext(MIHook hook)
2930

3031
@SafeVarargs
3132
public final void register(String englishName, String name,
33+
MachineBlockCreator blockCreator,
3234
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
3335
Consumer<BlockBehaviour.Properties> overrideProperties,
3436
boolean defaultMineableTags,
3537
Function<BEP, MachineBlockEntity> factory,
3638
Consumer<BlockEntityType<?>>... extraRegistrators)
3739
{
38-
HackedMachineRegistrationHelper.registerMachine(hook, englishName, name, modifyBlock, overrideProperties, defaultMineableTags, factory, extraRegistrators);
40+
HackedMachineRegistrationHelper.registerMachine(hook, englishName, name, blockCreator, modifyBlock, overrideProperties, defaultMineableTags, factory, extraRegistrators);
3941
}
4042

4143
@SafeVarargs
4244
public final void register(String englishName, String name,
45+
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
46+
Consumer<BlockBehaviour.Properties> overrideProperties,
47+
boolean defaultMineableTags,
48+
Function<BEP, MachineBlockEntity> factory,
49+
Consumer<BlockEntityType<?>>... extraRegistrators)
50+
{
51+
this.register(englishName, name, null, modifyBlock, overrideProperties, defaultMineableTags, factory, extraRegistrators);
52+
}
53+
54+
@SafeVarargs
55+
public final void register(String englishName, String name,
56+
MachineBlockCreator blockCreator,
4357
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
4458
Consumer<BlockBehaviour.Properties> overrideProperties,
4559
Function<BEP, MachineBlockEntity> factory,
@@ -48,6 +62,16 @@ public final void register(String englishName, String name,
4862
this.register(englishName, name, modifyBlock, overrideProperties, true, factory, extraRegistrators);
4963
}
5064

65+
@SafeVarargs
66+
public final void register(String englishName, String name,
67+
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
68+
Consumer<BlockBehaviour.Properties> overrideProperties,
69+
Function<BEP, MachineBlockEntity> factory,
70+
Consumer<BlockEntityType<?>>... extraRegistrators)
71+
{
72+
this.register(englishName, name, null, modifyBlock, overrideProperties, factory, extraRegistrators);
73+
}
74+
5175
@SafeVarargs
5276
public final void register(String englishName, String name,
5377
Function<BEP, MachineBlockEntity> factory,
@@ -59,13 +83,14 @@ public final void register(String englishName, String name,
5983
@SafeVarargs
6084
public final void register(String englishName, String name, String overlayFolder,
6185
MachineCasing defaultCasing, boolean frontOverlay, boolean topOverlay, boolean sideOverlay, boolean hasActive,
86+
MachineBlockCreator blockCreator,
6287
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
6388
Consumer<BlockBehaviour.Properties> overrideProperties,
6489
boolean defaultMineableTags,
6590
Function<BEP, MachineBlockEntity> factory,
6691
Consumer<BlockEntityType<?>>... extraRegistrators)
6792
{
68-
this.register(englishName, name, modifyBlock, overrideProperties, defaultMineableTags, factory, extraRegistrators);
93+
this.register(englishName, name, blockCreator, modifyBlock, overrideProperties, defaultMineableTags, factory, extraRegistrators);
6994

7095
HackedMachineRegistrationHelper.addMachineModel(hook, name, defaultCasing, overlayFolder, frontOverlay, topOverlay, sideOverlay, hasActive);
7196
}
@@ -75,10 +100,34 @@ public final void register(String englishName, String name, String overlayFolder
75100
MachineCasing defaultCasing, boolean frontOverlay, boolean topOverlay, boolean sideOverlay, boolean hasActive,
76101
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
77102
Consumer<BlockBehaviour.Properties> overrideProperties,
103+
boolean defaultMineableTags,
78104
Function<BEP, MachineBlockEntity> factory,
79105
Consumer<BlockEntityType<?>>... extraRegistrators)
80106
{
81-
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, hasActive, modifyBlock, overrideProperties, true, factory, extraRegistrators);
107+
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, hasActive, null, modifyBlock, overrideProperties, defaultMineableTags, factory, extraRegistrators);
108+
}
109+
110+
@SafeVarargs
111+
public final void register(String englishName, String name, String overlayFolder,
112+
MachineCasing defaultCasing, boolean frontOverlay, boolean topOverlay, boolean sideOverlay, boolean hasActive,
113+
MachineBlockCreator blockCreator,
114+
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
115+
Consumer<BlockBehaviour.Properties> overrideProperties,
116+
Function<BEP, MachineBlockEntity> factory,
117+
Consumer<BlockEntityType<?>>... extraRegistrators)
118+
{
119+
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, hasActive, blockCreator, modifyBlock, overrideProperties, true, factory, extraRegistrators);
120+
}
121+
122+
@SafeVarargs
123+
public final void register(String englishName, String name, String overlayFolder,
124+
MachineCasing defaultCasing, boolean frontOverlay, boolean topOverlay, boolean sideOverlay, boolean hasActive,
125+
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
126+
Consumer<BlockBehaviour.Properties> overrideProperties,
127+
Function<BEP, MachineBlockEntity> factory,
128+
Consumer<BlockEntityType<?>>... extraRegistrators)
129+
{
130+
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, hasActive, null, modifyBlock, overrideProperties, factory, extraRegistrators);
82131
}
83132

84133
@SafeVarargs
@@ -90,6 +139,19 @@ public final void register(String englishName, String name, String overlayFolder
90139
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, hasActive, null, null, factory, extraRegistrators);
91140
}
92141

142+
@SafeVarargs
143+
public final void register(String englishName, String name, String overlayFolder,
144+
MachineCasing defaultCasing, boolean frontOverlay, boolean topOverlay, boolean sideOverlay,
145+
MachineBlockCreator blockCreator,
146+
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
147+
Consumer<BlockBehaviour.Properties> overrideProperties,
148+
boolean defaultMineableTags,
149+
Function<BEP, MachineBlockEntity> factory,
150+
Consumer<BlockEntityType<?>>... extraRegistrators)
151+
{
152+
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, true, blockCreator, modifyBlock, overrideProperties, defaultMineableTags, factory, extraRegistrators);
153+
}
154+
93155
@SafeVarargs
94156
public final void register(String englishName, String name, String overlayFolder,
95157
MachineCasing defaultCasing, boolean frontOverlay, boolean topOverlay, boolean sideOverlay,
@@ -99,7 +161,19 @@ public final void register(String englishName, String name, String overlayFolder
99161
Function<BEP, MachineBlockEntity> factory,
100162
Consumer<BlockEntityType<?>>... extraRegistrators)
101163
{
102-
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, true, modifyBlock, overrideProperties, defaultMineableTags, factory, extraRegistrators);
164+
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, null, modifyBlock, overrideProperties, defaultMineableTags, factory, extraRegistrators);
165+
}
166+
167+
@SafeVarargs
168+
public final void register(String englishName, String name, String overlayFolder,
169+
MachineCasing defaultCasing, boolean frontOverlay, boolean topOverlay, boolean sideOverlay,
170+
MachineBlockCreator blockCreator,
171+
Consumer<BlockWithItemHolder<?, ?>> modifyBlock,
172+
Consumer<BlockBehaviour.Properties> overrideProperties,
173+
Function<BEP, MachineBlockEntity> factory,
174+
Consumer<BlockEntityType<?>>... extraRegistrators)
175+
{
176+
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, blockCreator, modifyBlock, overrideProperties, true, factory, extraRegistrators);
103177
}
104178

105179
@SafeVarargs
@@ -110,7 +184,7 @@ public final void register(String englishName, String name, String overlayFolder
110184
Function<BEP, MachineBlockEntity> factory,
111185
Consumer<BlockEntityType<?>>... extraRegistrators)
112186
{
113-
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, modifyBlock, overrideProperties, true, factory, extraRegistrators);
187+
this.register(englishName, name, overlayFolder, defaultCasing, frontOverlay, topOverlay, sideOverlay, null, modifyBlock, overrideProperties, factory, extraRegistrators);
114188
}
115189

116190
@SafeVarargs

0 commit comments

Comments
 (0)