Skip to content
This repository was archived by the owner on Aug 31, 2026. It is now read-only.

Commit 744d84c

Browse files
committed
@
feat: vendor Advanced Force Field System as AR shield core - Lift AFFS source (75 java + resources) into affs/, wired into build - Fold guest into AR single @mod: lifecycle, EventBusSubscriber, entity id - Route AFFS GUIs through AR container via AffsGuiRouter - Merge AFFS access transformer into advancedrocketry_at.cfg - License AFFS under GPL-3 with linking exception (affs/LICENSE, COPYING) - Add AffsVendorSmokeTest proving all core blocks register and place @
1 parent 9714373 commit 744d84c

172 files changed

Lines changed: 12648 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

affs/COPYING

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

affs/LICENSE

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Advanced Force Field System
2+
Copyright (C) 2025-2026 StannisMod
3+
4+
This is the "Advanced Force Field System" (AFFS), the maintainer's own project,
5+
vendored into Advanced Rocketry as its shield subsystem. The files under this
6+
directory retain their own copyright and licence, stated here; as part of the
7+
Advanced Rocketry distribution they are additionally covered by the project as a
8+
whole (see the top-level LICENSE and COPYING).
9+
10+
This program is free software: you can redistribute it and/or modify it under
11+
the terms of the GNU General Public License, version 3, as published by the Free
12+
Software Foundation, WITH the Linking Exception stated below. The complete text
13+
of the GNU General Public License, version 3, is in the file COPYING.
14+
15+
This program is distributed in the hope that it will be useful, but WITHOUT ANY
16+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
17+
PARTICULAR PURPOSE. See the GNU General Public License for more details.
18+
19+
SPDX-License-Identifier: GPL-3.0-only WITH Linking-Exception
20+
21+
22+
LINKING EXCEPTION
23+
=================
24+
25+
As a special exception, the copyright holders of Advanced Force Field System
26+
give you permission to link or combine independent modules with this program to
27+
produce a combined work, and to convey the resulting combined work under terms
28+
of your choice, provided that:
29+
30+
(a) the independent module is not itself derived from or based on Advanced
31+
Force Field System other than by linking against or calling its code as a
32+
library / Forge mod dependency; and
33+
34+
(b) you comply with the GNU General Public License, version 3, for Advanced
35+
Force Field System itself and for any modifications you make to it.
36+
37+
Depending on, linking against, or calling this program does not, by itself, make
38+
your work a work based on Advanced Force Field System for the purposes of this
39+
License.
40+
41+
If you modify Advanced Force Field System itself, this exception does not extend
42+
to those modifications, which remain governed by the GNU General Public License,
43+
version 3.
44+
45+
You may, at your option, remove this exception from a given copy of the program;
46+
doing so makes the plain GNU General Public License, version 3, apply to that
47+
copy.
Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,326 @@
1+
package com.github.stannismod.affs;
2+
3+
import com.github.stannismod.affs.block.*;
4+
import com.github.stannismod.affs.config.ModConfig;
5+
import com.github.stannismod.affs.entity.EntityLaserBolt;
6+
import com.github.stannismod.affs.item.ItemCodeDevice;
7+
import com.github.stannismod.affs.item.ItemLaserGun;
8+
import com.github.stannismod.affs.network.*;
9+
import com.github.stannismod.affs.te.*;
10+
import net.minecraft.block.Block;
11+
import net.minecraft.block.material.Material;
12+
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
13+
import net.minecraft.creativetab.CreativeTabs;
14+
import net.minecraft.init.Items;
15+
import net.minecraft.item.Item;
16+
import net.minecraft.item.ItemBlock;
17+
import net.minecraft.item.ItemStack;
18+
import net.minecraft.util.ResourceLocation;
19+
import net.minecraftforge.client.event.ModelRegistryEvent;
20+
import net.minecraftforge.client.model.ModelLoader;
21+
import net.minecraftforge.event.RegistryEvent;
22+
import net.minecraftforge.fml.common.Mod;
23+
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
24+
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
25+
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
26+
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
27+
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
28+
import net.minecraftforge.fml.common.network.NetworkRegistry;
29+
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
30+
import net.minecraftforge.fml.common.registry.EntityRegistry;
31+
import net.minecraftforge.fml.common.registry.GameRegistry;
32+
import net.minecraftforge.fml.relauncher.Side;
33+
import net.minecraftforge.fml.relauncher.SideOnly;
34+
import org.apache.logging.log4j.Logger;
35+
import zmaster587.advancedRocketry.AdvancedRocketry;
36+
import zmaster587.advancedRocketry.api.Constants;
37+
38+
import javax.annotation.Nullable;
39+
import java.util.ArrayList;
40+
import java.util.Collections;
41+
import java.util.List;
42+
43+
// Vendored into Advanced Rocketry as its shield subsystem: no longer its own
44+
// @Mod. The mod is folded into AR's single container — AR drives the lifecycle
45+
// (preInit/init/postInit) from its own @Mod handlers, and the static registry
46+
// handlers below register under AR's modid. The registry DOMAIN stays "affs".
47+
@Mod.EventBusSubscriber(modid = Constants.modId)
48+
public class AdvancedForceFieldSystem {
49+
50+
public static final String MODID = "affs";
51+
public static final String MODNAME = "AdvancedForceFieldSystem";
52+
public static final String VERSION = "0.0.1";
53+
54+
public static Logger LOG;
55+
public static final int GUI_FIELD_GENERATOR = 1;
56+
public static final int GUI_ADMIN_ENERGY_SOURCE = 2;
57+
public static final int GUI_CODE_DEVICE = 3;
58+
public static final int GUI_SHIELD_GENERATOR = 4;
59+
public static final int GUI_SHIELD_NETWORK = 5;
60+
public static final int GUI_SHIELD_CONSOLE = 6;
61+
public static final int GUI_NETWORK_MAP = 8;
62+
public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
63+
private static int packetId = 0;
64+
65+
public static Item itemFieldGenerator;
66+
public static Item itemShieldGenerator;
67+
public static Item itemShieldCable;
68+
public static Item itemAdminEnergySource;
69+
public static Item itemContourFrame;
70+
public static Item itemContourInjector;
71+
public static Item itemLaserGun;
72+
public static ItemCodeDevice ITEM_CODE_DEVICE;
73+
74+
public static BlockFieldGenerator BLOCK_FIELD_GENERATOR;
75+
public static BlockShieldGenerator BLOCK_SHIELD_GENERATOR;
76+
public static BlockShieldCable BLOCK_SHIELD_CABLE;
77+
public static BlockShieldConsole BLOCK_SHIELD_CONSOLE;
78+
public static BlockAdminEnergySource BLOCK_ADMIN_ENERGY_SOURCE;
79+
public static BlockContourFrame BLOCK_CONTOUR_FRAME;
80+
public static BlockContourInjector BLOCK_CONTOUR_INJECTOR;
81+
public static BlockProjectedField BLOCK_PROJECTED_FIELD;
82+
public static CreativeTabs tabAffs = new CreativeTabs("tabAffs") {
83+
@Override
84+
public ItemStack getTabIconItem() {
85+
Item icon = itemFieldGenerator != null ? itemFieldGenerator
86+
: itemShieldGenerator != null ? itemShieldGenerator
87+
: itemContourFrame;
88+
return icon == null ? ItemStack.EMPTY : new ItemStack(icon);
89+
}
90+
};
91+
92+
// Self-initialised (ready at class-load, before any registry event) — the
93+
// guest is no longer a @Mod, so FML does not inject @Mod.Instance for it.
94+
public static final AdvancedForceFieldSystem INSTANCE = new AdvancedForceFieldSystem();
95+
96+
public void preInit(FMLPreInitializationEvent event) {
97+
LOG = event.getModLog();
98+
ModConfig.load(event.getSuggestedConfigurationFile());
99+
initContent();
100+
// GUI handler is registered by AR (AffsGuiRouter) — the guest is no longer its own mod
101+
// container, so it cannot own an IGuiHandler. GUIs are opened via openAffsGui below.
102+
NETWORK.registerMessage(PacketSetFieldRadius.Handler.class, PacketSetFieldRadius.class, packetId++, Side.SERVER);
103+
NETWORK.registerMessage(PacketSyncCodeValue.Handler.class, PacketSyncCodeValue.class, packetId++, Side.SERVER);
104+
NETWORK.registerMessage(PacketSyncActiveGenerators.Handler.class, PacketSyncActiveGenerators.class, packetId++, Side.CLIENT);
105+
NETWORK.registerMessage(PacketFieldTouchEffect.Handler.class, PacketFieldTouchEffect.class, packetId++, Side.CLIENT);
106+
NETWORK.registerMessage(PacketOpenGui.Handler.class, PacketOpenGui.class, packetId++, Side.SERVER);
107+
NETWORK.registerMessage(PacketSetShieldResistanceBias.Handler.class, PacketSetShieldResistanceBias.class, packetId++, Side.SERVER);
108+
}
109+
110+
public void init(FMLInitializationEvent event) {
111+
GameRegistry.registerTileEntity(TileEntityFieldGenerator.class, new ResourceLocation(MODID, "field_generator"));
112+
GameRegistry.registerTileEntity(TileEntityShieldGenerator.class, new ResourceLocation(MODID, "shield_generator"));
113+
GameRegistry.registerTileEntity(TileEntityShieldCable.class, new ResourceLocation(MODID, "shield_cable"));
114+
GameRegistry.registerTileEntity(TileEntityShieldConsole.class, new ResourceLocation(MODID, "shield_console"));
115+
GameRegistry.registerTileEntity(TileEntityAdminEnergySource.class, new ResourceLocation(MODID, "admin_energy_source"));
116+
GameRegistry.registerTileEntity(TileEntityContourInjector.class, new ResourceLocation(MODID, "contour_injector"));
117+
// Owner is AR's mod instance (the guest is folded into AR's container); the
118+
// per-mod entity id must be free in AR's namespace (AR uses 0..9) → 10.
119+
EntityRegistry.registerModEntity(new ResourceLocation(MODID, "laser_bolt"), EntityLaserBolt.class, "laser_bolt", 10, AdvancedRocketry.instance, 64, 10, true);
120+
if (event.getSide().isClient()) {
121+
com.github.stannismod.affs.client.ClientEntityRenderRegistry.init();
122+
}
123+
}
124+
125+
public void postInit(FMLPostInitializationEvent event) {
126+
}
127+
128+
/**
129+
* Opens an AFFS GUI. Because AFFS is folded into AR's single mod container, the owner
130+
* passed to {@code openGui} must be AR's mod instance, and the local GUI id is offset into
131+
* {@link zmaster587.advancedRocketry.integration.affs.AffsGuiRouter}'s AFFS range.
132+
*/
133+
public static void openAffsGui(net.minecraft.entity.player.EntityPlayer player, int guiId,
134+
net.minecraft.world.World world, int x, int y, int z) {
135+
player.openGui(AdvancedRocketry.instance,
136+
zmaster587.advancedRocketry.integration.affs.AffsGuiRouter.AFFS_GUI_BASE + guiId,
137+
world, x, y, z);
138+
}
139+
140+
private static List<Block> blocks;
141+
142+
private static void initContent() {
143+
if (blocks != null) {
144+
return;
145+
}
146+
147+
BLOCK_FIELD_GENERATOR = new BlockFieldGenerator("field_generator", Material.IRON);
148+
BLOCK_SHIELD_GENERATOR = new BlockShieldGenerator("shield_generator", Material.IRON);
149+
BLOCK_SHIELD_CABLE = new BlockShieldCable("shield_cable", Material.IRON);
150+
BLOCK_SHIELD_CONSOLE = new BlockShieldConsole("shield_console", Material.IRON);
151+
BLOCK_ADMIN_ENERGY_SOURCE = new BlockAdminEnergySource("admin_energy_source", Material.IRON);
152+
BLOCK_CONTOUR_FRAME = new BlockContourFrame("contour_frame", Material.IRON);
153+
BLOCK_CONTOUR_INJECTOR = new BlockContourInjector("contour_injector", Material.IRON);
154+
BLOCK_PROJECTED_FIELD = new BlockProjectedField("projected_field", Material.BARRIER);
155+
ITEM_CODE_DEVICE = new ItemCodeDevice();
156+
itemLaserGun = new ItemLaserGun();
157+
158+
List<Block> content = new ArrayList<>();
159+
content.add(BLOCK_FIELD_GENERATOR);
160+
content.add(BLOCK_SHIELD_GENERATOR);
161+
content.add(BLOCK_SHIELD_CABLE);
162+
content.add(BLOCK_SHIELD_CONSOLE);
163+
content.add(BLOCK_ADMIN_ENERGY_SOURCE);
164+
content.add(BLOCK_CONTOUR_FRAME);
165+
content.add(BLOCK_CONTOUR_INJECTOR);
166+
content.add(BLOCK_PROJECTED_FIELD);
167+
blocks = Collections.unmodifiableList(content);
168+
}
169+
170+
private static List<Block> getBlocks() {
171+
initContent();
172+
return blocks;
173+
}
174+
175+
@SubscribeEvent
176+
public static void onRegisterItems(RegistryEvent.Register<Item> event) {
177+
initContent();
178+
event.getRegistry().register(ITEM_CODE_DEVICE);
179+
event.getRegistry().register(itemLaserGun);
180+
for (Block block : getBlocks()) {
181+
Item item = createItemBlock(block);
182+
if (item == null) {
183+
continue;
184+
}
185+
186+
event.getRegistry().register(item);
187+
cacheRegisteredItem(item);
188+
}
189+
}
190+
191+
@SubscribeEvent
192+
public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
193+
if (event.player instanceof net.minecraft.entity.player.EntityPlayerMP) {
194+
PacketSyncActiveGenerators.sendFullSnapshotToPlayer((net.minecraft.entity.player.EntityPlayerMP) event.player);
195+
}
196+
}
197+
198+
@SubscribeEvent
199+
public static void onPlayerChangedDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
200+
if (event.player instanceof net.minecraft.entity.player.EntityPlayerMP) {
201+
PacketSyncActiveGenerators.sendFullSnapshotToPlayer((net.minecraft.entity.player.EntityPlayerMP) event.player);
202+
}
203+
}
204+
205+
@Nullable
206+
private static Item createItemBlock(Block block) {
207+
if (!(block instanceof IHasItemBlock)) {
208+
return new ItemBlock(block).setRegistryName(block.getRegistryName());
209+
}
210+
return ((IHasItemBlock) block).createItemBlock();
211+
}
212+
213+
private static void cacheRegisteredItem(Item item) {
214+
ResourceLocation registryName = item.getRegistryName();
215+
if (registryName == null) {
216+
return;
217+
}
218+
219+
String path = resourcePath(registryName);
220+
switch (path) {
221+
case "field_generator":
222+
itemFieldGenerator = item;
223+
break;
224+
case "shield_generator":
225+
itemShieldGenerator = item;
226+
break;
227+
case "shield_cable":
228+
itemShieldCable = item;
229+
break;
230+
case "shield_console":
231+
break;
232+
case "admin_energy_source":
233+
itemAdminEnergySource = item;
234+
break;
235+
case "contour_frame":
236+
itemContourFrame = item;
237+
break;
238+
case "contour_injector":
239+
itemContourInjector = item;
240+
break;
241+
case "laser_gun":
242+
itemLaserGun = item;
243+
break;
244+
}
245+
}
246+
247+
@SubscribeEvent
248+
public static void onRegisterBlocks(RegistryEvent.Register<Block> event) {
249+
initContent();
250+
for (Block block : getBlocks()) {
251+
event.getRegistry().register(block);
252+
}
253+
}
254+
255+
@SideOnly(Side.CLIENT)
256+
@SubscribeEvent
257+
public static void onModelRegister(ModelRegistryEvent event) {
258+
initContent();
259+
registerModel(ITEM_CODE_DEVICE);
260+
registerModel(itemLaserGun);
261+
for (Block block : getBlocks()) {
262+
if (Item.getItemFromBlock(block) == Items.AIR) {
263+
continue;
264+
}
265+
if (isTieredBlock(block)) {
266+
registerTieredBlockModels(block);
267+
continue;
268+
}
269+
registerModel(block);
270+
}
271+
}
272+
273+
private static void registerModel(Item item) {
274+
ModelLoader.setCustomModelResourceLocation(
275+
item,
276+
0,
277+
new ModelResourceLocation(item.getRegistryName().toString(), "inventory")
278+
);
279+
}
280+
281+
private static void registerTieredBlockModels(Block block) {
282+
Item item = Item.getItemFromBlock(block);
283+
String basePath = resourcePath(block.getRegistryName());
284+
for (int tier = 0; tier < BlockFieldGenerator.TIER_COUNT; tier++) {
285+
registerModel(item, tier, new ResourceLocation(MODID, basePath + "_tier" + tier));
286+
}
287+
}
288+
289+
private static void registerModel(Item item, int meta, ResourceLocation modelLocation) {
290+
ModelLoader.setCustomModelResourceLocation(
291+
item,
292+
meta,
293+
new ModelResourceLocation(modelLocation, "inventory")
294+
);
295+
}
296+
297+
private static void registerModel(Block block) {
298+
ModelLoader.setCustomModelResourceLocation(
299+
Item.getItemFromBlock(block),
300+
0,
301+
new ModelResourceLocation(block.getRegistryName().toString(), "inventory")
302+
);
303+
}
304+
305+
private static boolean isTieredBlock(Block block) {
306+
return block == BLOCK_FIELD_GENERATOR
307+
|| block == BLOCK_SHIELD_GENERATOR
308+
|| block == BLOCK_SHIELD_CABLE;
309+
}
310+
311+
public static String resourcePath(@Nullable ResourceLocation location) {
312+
if (location == null) {
313+
return "unknown";
314+
}
315+
try {
316+
return (String) ResourceLocation.class.getMethod("getResourcePath").invoke(location);
317+
} catch (ReflectiveOperationException ignored) {
318+
try {
319+
return (String) ResourceLocation.class.getMethod("getPath").invoke(location);
320+
} catch (ReflectiveOperationException ignoredToo) {
321+
return location.toString();
322+
}
323+
}
324+
}
325+
326+
}

0 commit comments

Comments
 (0)