From ad036cef029b7d5bf1d537124d5300f7357d1cfa Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 6 Sep 2021 22:33:25 +0900 Subject: [PATCH 1/4] add event handler for FMLMissingMappingsEvent --- src/main/java/jp/ngt/rtm/RTMCore.java | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/main/java/jp/ngt/rtm/RTMCore.java b/src/main/java/jp/ngt/rtm/RTMCore.java index 0a6a2e99..f48a112b 100644 --- a/src/main/java/jp/ngt/rtm/RTMCore.java +++ b/src/main/java/jp/ngt/rtm/RTMCore.java @@ -16,6 +16,8 @@ import jp.ngt.rtm.gui.RTMGuiHandler; import jp.ngt.rtm.item.ItemBucketLiquid; import jp.ngt.rtm.world.RTMChunkManager; +import net.minecraft.block.Block; +import net.minecraft.item.Item; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; @@ -23,6 +25,9 @@ import org.apache.logging.log4j.Level; import paulscode.sound.SoundSystemConfig; +import java.util.HashMap; +import java.util.Map; + @Mod(modid = RTMCore.MODID, name = "RealTrainMod", version = RTMCore.VERSION) public final class RTMCore { public static final String MODID = "RTM"; @@ -215,6 +220,39 @@ public void handleServerStarting(FMLServerStartingEvent event) { WireManager.INSTANCE.clear(); } + public static void registerMapping(Item item, String name) { + itemMap.put(MODID + ':' + name, item); + } + + public static void registerMapping(Block block, String name) { + blockMap.put(MODID + ':' + name, block); + Item itemForBlock = Item.getItemFromBlock(block); + if (itemForBlock != null) { + registerMapping(itemForBlock, name); + } + } + + private static Map itemMap = new HashMap<>(); + private static Map blockMap = new HashMap<>(); + + @EventHandler + public void handleMissingMapping(FMLMissingMappingsEvent event) { + for (FMLMissingMappingsEvent.MissingMapping mapping : event.get()) { + switch (mapping.type) { + case BLOCK: + Block mappedBlock = blockMap.get(mapping.name); + if (mappedBlock != null) + mapping.remap(mappedBlock); + break; + case ITEM: + Item mappedItem = itemMap.get(mapping.name); + if (mappedItem != null) + mapping.remap(mappedItem); + break; + } + } + } + private static short guiId; private static short getNextGuiID() { From 1589d3a4a1e4a0e373dac506f9566e96e1c0016d Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 6 Sep 2021 22:51:49 +0900 Subject: [PATCH 2/4] remove rtm: prefix and register mappings --- src/main/java/jp/ngt/rtm/RTMBlock.java | 103 ++++++++++++++++--------- src/main/java/jp/ngt/rtm/RTMItem.java | 59 +++++++++----- 2 files changed, 107 insertions(+), 55 deletions(-) diff --git a/src/main/java/jp/ngt/rtm/RTMBlock.java b/src/main/java/jp/ngt/rtm/RTMBlock.java index 2ca077ae..5ea77e55 100644 --- a/src/main/java/jp/ngt/rtm/RTMBlock.java +++ b/src/main/java/jp/ngt/rtm/RTMBlock.java @@ -160,26 +160,44 @@ public static void init() { RTMRail.init(); - GameRegistry.registerBlock(marker, "rtm:marker"); - GameRegistry.registerBlock(markerSwitch, "rtm:markerSwitch"); -// GameRegistry.registerBlock(markerSlope, "rtm:markerSlope"); - - GameRegistry.registerBlock(fluorescent, "rtm:fluorescent"); - GameRegistry.registerBlock(ironPillar, "rtm:ironPillar"); - GameRegistry.registerBlock(insulator, "rtm:insulator"); - GameRegistry.registerBlock(signal, "rtm:signal"); - GameRegistry.registerBlock(crossingGate, "rtm:crossing"); - GameRegistry.registerBlock(variableBlock, "rtm:Variable"); - GameRegistry.registerBlock(linePole, "rtm:linePole"); - GameRegistry.registerBlock(connector, "rtm:connector"); - GameRegistry.registerBlock(powerUnit, "rtm:powerUnit"); + GameRegistry.registerBlock(marker, "marker"); + GameRegistry.registerBlock(markerSwitch, "markerSwitch"); +// GameRegistry.registerBlock(markerSlope, "markerSlope"); + RTMCore.registerMapping(marker, "rtm:marker"); + RTMCore.registerMapping(markerSwitch, "rtm:markerSwitch"); +// RTMCore.registerMapping(markerSlope, "rtm:markerSlope"); + + GameRegistry.registerBlock(fluorescent, "fluorescent"); + GameRegistry.registerBlock(ironPillar, "ironPillar"); + GameRegistry.registerBlock(insulator, "insulator"); + GameRegistry.registerBlock(signal, "signal"); + GameRegistry.registerBlock(crossingGate, "crossing"); + GameRegistry.registerBlock(variableBlock, "Variable"); + GameRegistry.registerBlock(linePole, "linePole"); + GameRegistry.registerBlock(connector, "connector"); + GameRegistry.registerBlock(powerUnit, "powerUnit"); + RTMCore.registerMapping(fluorescent, "rtm:fluorescent"); + RTMCore.registerMapping(ironPillar, "rtm:ironPillar"); + RTMCore.registerMapping(insulator, "rtm:insulator"); + RTMCore.registerMapping(signal, "rtm:signal"); + RTMCore.registerMapping(crossingGate, "rtm:crossing"); + RTMCore.registerMapping(variableBlock, "rtm:Variable"); + RTMCore.registerMapping(linePole, "rtm:linePole"); + RTMCore.registerMapping(connector, "rtm:connector"); + RTMCore.registerMapping(powerUnit, "rtm:powerUnit"); GameRegistry.registerBlock(signalConverter, ItemBlockCustom.class, "signal_converter"); - GameRegistry.registerBlock(railroadSign, "rtm:railroadSign"); - GameRegistry.registerBlock(turnstile, "rtm:turnstile"); - GameRegistry.registerBlock(point, "rtm:point"); - GameRegistry.registerBlock(rsWire, "rtm:rsWire"); - GameRegistry.registerBlock(signboard, "rtm:signboard"); - GameRegistry.registerBlock(trainWorkBench, ItemBlockCustom.class, "rtm:trainWorkBench"); + GameRegistry.registerBlock(railroadSign, "railroadSign"); + GameRegistry.registerBlock(turnstile, "turnstile"); + GameRegistry.registerBlock(point, "point"); + GameRegistry.registerBlock(rsWire, "rsWire"); + GameRegistry.registerBlock(signboard, "signboard"); + GameRegistry.registerBlock(trainWorkBench, ItemBlockCustom.class, "trainWorkBench"); + RTMCore.registerMapping(railroadSign, "rtm:railroadSign"); + RTMCore.registerMapping(turnstile, "rtm:turnstile"); + RTMCore.registerMapping(point, "rtm:point"); + RTMCore.registerMapping(rsWire, "rtm:rsWire"); + RTMCore.registerMapping(signboard, "rtm:signboard"); + RTMCore.registerMapping(trainWorkBench, "rtm:trainWorkBench"); GameRegistry.registerBlock(ticketVendor, "ticketVendor"); GameRegistry.registerBlock(mirror, "mirror"); GameRegistry.registerBlock(mirrorCube, "mirror_cube"); @@ -188,21 +206,36 @@ public static void init() { GameRegistry.registerBlock(light, "light_block"); GameRegistry.registerBlock(speaker, "speaker"); - GameRegistry.registerBlock(fireBrick, "rtm:fireBrick"); - GameRegistry.registerBlock(hotStoveBrick, "rtm:hotStoveBrick"); - GameRegistry.registerBlock(pipe, "rtm:pipe"); - GameRegistry.registerBlock(slot, "rtm:slot"); - GameRegistry.registerBlock(furnaceFire, "rtm:furnaceFire"); - GameRegistry.registerBlock(exhaustGas, "rtm:exhaustGas"); - GameRegistry.registerBlock(liquefiedPigIron, "rtm:pigIron_L"); - GameRegistry.registerBlock(liquefiedSteel, "rtm:steel_L"); - GameRegistry.registerBlock(slag, "rtm:slag"); - GameRegistry.registerBlock(converterCore, "rtm:converterCore"); - GameRegistry.registerBlock(converterBase, "rtm:converterBase"); - GameRegistry.registerBlock(steelSlab, "rtm:steelSlab"); - GameRegistry.registerBlock(brickSlab, "rtm:brickSlab"); - GameRegistry.registerBlock(brickDoubleSlab, "rtm:brickDoubleSlab"); - GameRegistry.registerBlock(steelMaterial, "rtm:steelMaterial"); + GameRegistry.registerBlock(fireBrick, "fireBrick"); + GameRegistry.registerBlock(hotStoveBrick, "hotStoveBrick"); + GameRegistry.registerBlock(pipe, "pipe"); + GameRegistry.registerBlock(slot, "slot"); + GameRegistry.registerBlock(furnaceFire, "furnaceFire"); + GameRegistry.registerBlock(exhaustGas, "exhaustGas"); + GameRegistry.registerBlock(liquefiedPigIron, "pigIron_L"); + GameRegistry.registerBlock(liquefiedSteel, "steel_L"); + GameRegistry.registerBlock(slag, "slag"); + GameRegistry.registerBlock(converterCore, "converterCore"); + GameRegistry.registerBlock(converterBase, "converterBase"); + GameRegistry.registerBlock(steelSlab, "steelSlab"); + GameRegistry.registerBlock(brickSlab, "brickSlab"); + GameRegistry.registerBlock(brickDoubleSlab, "brickDoubleSlab"); + GameRegistry.registerBlock(steelMaterial, "steelMaterial"); + RTMCore.registerMapping(fireBrick, "rtm:fireBrick"); + RTMCore.registerMapping(hotStoveBrick, "rtm:hotStoveBrick"); + RTMCore.registerMapping(pipe, "rtm:pipe"); + RTMCore.registerMapping(slot, "rtm:slot"); + RTMCore.registerMapping(furnaceFire, "rtm:furnaceFire"); + RTMCore.registerMapping(exhaustGas, "rtm:exhaustGas"); + RTMCore.registerMapping(liquefiedPigIron, "rtm:pigIron_L"); + RTMCore.registerMapping(liquefiedSteel, "rtm:steel_L"); + RTMCore.registerMapping(slag, "rtm:slag"); + RTMCore.registerMapping(converterCore, "rtm:converterCore"); + RTMCore.registerMapping(converterBase, "rtm:converterBase"); + RTMCore.registerMapping(steelSlab, "rtm:steelSlab"); + RTMCore.registerMapping(brickSlab, "rtm:brickSlab"); + RTMCore.registerMapping(brickDoubleSlab, "rtm:brickDoubleSlab"); + RTMCore.registerMapping(steelMaterial, "rtm:steelMaterial"); GameRegistry.registerBlock(scaffold, "scaffold"); GameRegistry.registerBlock(scaffoldStairs, "scaffold_stairs"); GameRegistry.registerBlock(framework, "framework"); @@ -246,4 +279,4 @@ public static void init() { GameRegistry.registerTileEntity(TileEntityEffect.class, "TEEffect"); } -} \ No newline at end of file +} diff --git a/src/main/java/jp/ngt/rtm/RTMItem.java b/src/main/java/jp/ngt/rtm/RTMItem.java index 26610d00..c9f075b6 100644 --- a/src/main/java/jp/ngt/rtm/RTMItem.java +++ b/src/main/java/jp/ngt/rtm/RTMItem.java @@ -113,17 +113,28 @@ public static void init() { camera = (new ItemCamera()).setUnlocalizedName("rtm:camera").setTextureName("rtm:camera").setCreativeTab(CreativeTabRTM.tabRTMTools); - GameRegistry.registerItem(bogie, "rtm:bogie"); - GameRegistry.registerItem(installedObject, "rtm:installedObject"); - GameRegistry.registerItem(material, "rtm:material"); - GameRegistry.registerItem(crowbar, "rtm:crowbar"); - GameRegistry.registerItem(itemtrain, "rtm:itemTrain"); - GameRegistry.registerItem(itemMotorman, "rtm:itemMotorman"); - GameRegistry.registerItem(itemCargo, "rtm:itemCargo"); - GameRegistry.registerItem(itemRailroadSign, "rtm:itemRailroadSign"); - GameRegistry.registerItem(ticket, "rtm:ticket"); - GameRegistry.registerItem(ticketBook, "rtm:ticketBook"); - GameRegistry.registerItem(icCard, "rtm:icCard"); + GameRegistry.registerItem(bogie, "bogie"); + GameRegistry.registerItem(installedObject, "installedObject"); + GameRegistry.registerItem(material, "material"); + GameRegistry.registerItem(crowbar, "crowbar"); + GameRegistry.registerItem(itemtrain, "itemTrain"); + GameRegistry.registerItem(itemMotorman, "itemMotorman"); + GameRegistry.registerItem(itemCargo, "itemCargo"); + GameRegistry.registerItem(itemRailroadSign, "itemRailroadSign"); + GameRegistry.registerItem(ticket, "ticket"); + GameRegistry.registerItem(ticketBook, "ticketBook"); + GameRegistry.registerItem(icCard, "icCard"); + RTMCore.registerMapping(bogie, "rtm:bogie"); + RTMCore.registerMapping(installedObject, "rtm:installedObject"); + RTMCore.registerMapping(material, "rtm:material"); + RTMCore.registerMapping(crowbar, "rtm:crowbar"); + RTMCore.registerMapping(itemtrain, "rtm:itemTrain"); + RTMCore.registerMapping(itemMotorman, "rtm:itemMotorman"); + RTMCore.registerMapping(itemCargo, "rtm:itemCargo"); + RTMCore.registerMapping(itemRailroadSign, "rtm:itemRailroadSign"); + RTMCore.registerMapping(ticket, "rtm:ticket"); + RTMCore.registerMapping(ticketBook, "rtm:ticketBook"); + RTMCore.registerMapping(icCard, "rtm:icCard"); GameRegistry.registerItem(itemLargeRail, "itemLargeRail"); GameRegistry.registerItem(itemSignal, "itemSignal"); GameRegistry.registerItem(itemLinePole, "itemLinePole"); @@ -149,16 +160,24 @@ public static void init() { GameRegistry.registerItem(bullet, "bullet"); GameRegistry.registerItem(nvd, "nvd"); - GameRegistry.registerItem(bucketLiquid, "rtm:bucketLiquid"); - GameRegistry.registerItem(iron_hacksaw, "rtm:ironHacksaw"); - GameRegistry.registerItem(steel_ingot, "rtm:ingotSteel"); - GameRegistry.registerItem(paddle, "rtm:paddle"); - GameRegistry.registerItem(coke, "rtm:coke"); - GameRegistry.registerItem(bellows, "rtm:bellows"); - GameRegistry.registerItem(itemPipe, "rtm:itemPipe"); + GameRegistry.registerItem(bucketLiquid, "bucketLiquid"); + GameRegistry.registerItem(iron_hacksaw, "ironHacksaw"); + GameRegistry.registerItem(steel_ingot, "ingotSteel"); + GameRegistry.registerItem(paddle, "paddle"); + GameRegistry.registerItem(coke, "coke"); + GameRegistry.registerItem(bellows, "bellows"); + GameRegistry.registerItem(itemPipe, "itemPipe"); + RTMCore.registerMapping(bucketLiquid, "rtm:bucketLiquid"); + RTMCore.registerMapping(iron_hacksaw, "rtm:ironHacksaw"); + RTMCore.registerMapping(steel_ingot, "rtm:ingotSteel"); + RTMCore.registerMapping(paddle, "rtm:paddle"); + RTMCore.registerMapping(coke, "rtm:coke"); + RTMCore.registerMapping(bellows, "rtm:bellows"); + RTMCore.registerMapping(itemPipe, "rtm:itemPipe"); GameRegistry.registerItem(paintTool, "paint_tool"); - GameRegistry.registerItem(camera, "rtm:camera"); + GameRegistry.registerItem(camera, "camera"); + RTMCore.registerMapping(camera, "rtm:camera"); OreDictionary.registerOre("ingotSteel", new ItemStack(steel_ingot, 1, 0)); OreDictionary.registerOre("fuelCoke", new ItemStack(coke, 1, 0)); @@ -220,4 +239,4 @@ public static int getPrice(int id) { return Arrays.stream(MoneyType.values()).filter(type -> type.id == id).findFirst().map(type -> type.price).orElse((short) 0); } } -} \ No newline at end of file +} From a2ad16f753a05bd08fb2af8f0af81b39b11927f0 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 6 Sep 2021 22:53:54 +0900 Subject: [PATCH 3/4] remove rtm: prefix and register mappings in RTMRail --- src/main/java/jp/ngt/rtm/RTMRail.java | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/jp/ngt/rtm/RTMRail.java b/src/main/java/jp/ngt/rtm/RTMRail.java index 55b56738..9660a24a 100644 --- a/src/main/java/jp/ngt/rtm/RTMRail.java +++ b/src/main/java/jp/ngt/rtm/RTMRail.java @@ -44,13 +44,20 @@ public static void init() { largeRailSlopeCore[i] = (new BlockLargeRailSlopeCore(i)).setBlockName("rtm:LRLCore." + i).setBlockTextureName(railTexture[i]); }); - GameRegistry.registerBlock(largeRailBase0, "rtm:LRBase"); - GameRegistry.registerBlock(largeRailCore0, "rtm:LRCore"); - GameRegistry.registerBlock(largeRailSwitchBase0, "rtm:LRSBase"); - GameRegistry.registerBlock(largeRailSwitchCore0, "rtm:LRSCore"); - GameRegistry.registerBlock(largeRailSlopeBase0, "rtm:LRLBase"); - GameRegistry.registerBlock(largeRailSlopeCore0, "rtm:LRLCore"); - GameRegistry.registerBlock(TURNTABLE_CORE, "rtm:turntable_core"); + GameRegistry.registerBlock(largeRailBase0, "LRBase"); + GameRegistry.registerBlock(largeRailCore0, "LRCore"); + GameRegistry.registerBlock(largeRailSwitchBase0, "LRSBase"); + GameRegistry.registerBlock(largeRailSwitchCore0, "LRSCore"); + GameRegistry.registerBlock(largeRailSlopeBase0, "LRLBase"); + GameRegistry.registerBlock(largeRailSlopeCore0, "LRLCore"); + GameRegistry.registerBlock(TURNTABLE_CORE, "turntable_core"); + RTMCore.registerMapping(largeRailBase0, "rtm:LRBase"); + RTMCore.registerMapping(largeRailCore0, "rtm:LRCore"); + RTMCore.registerMapping(largeRailSwitchBase0, "rtm:LRSBase"); + RTMCore.registerMapping(largeRailSwitchCore0, "rtm:LRSCore"); + RTMCore.registerMapping(largeRailSlopeBase0, "rtm:LRLBase"); + RTMCore.registerMapping(largeRailSlopeCore0, "rtm:LRLCore"); + RTMCore.registerMapping(TURNTABLE_CORE, "rtm:turntable_core"); //インスタンス使いまわして登録は不可 IntStream.range(0, railTexture.length).forEach(i -> { @@ -156,4 +163,4 @@ public static RailProperty getProperty(byte shape, int texType) { float h = (texType == 4) ? 0.18125F + 0.0625F : 0.0625F; return new RailProperty(s0, block, meta, h); } -} \ No newline at end of file +} From 3897d47cce179c5af7d35874c116ff270dfd7968 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 6 Sep 2021 22:59:35 +0900 Subject: [PATCH 4/4] register block/item and mapping at once --- src/main/java/jp/ngt/rtm/RTMBlock.java | 101 +++++++++---------------- src/main/java/jp/ngt/rtm/RTMCore.java | 22 ++++++ src/main/java/jp/ngt/rtm/RTMItem.java | 57 +++++--------- src/main/java/jp/ngt/rtm/RTMRail.java | 21 ++--- 4 files changed, 82 insertions(+), 119 deletions(-) diff --git a/src/main/java/jp/ngt/rtm/RTMBlock.java b/src/main/java/jp/ngt/rtm/RTMBlock.java index 5ea77e55..fb06c3f2 100644 --- a/src/main/java/jp/ngt/rtm/RTMBlock.java +++ b/src/main/java/jp/ngt/rtm/RTMBlock.java @@ -160,44 +160,26 @@ public static void init() { RTMRail.init(); - GameRegistry.registerBlock(marker, "marker"); - GameRegistry.registerBlock(markerSwitch, "markerSwitch"); -// GameRegistry.registerBlock(markerSlope, "markerSlope"); - RTMCore.registerMapping(marker, "rtm:marker"); - RTMCore.registerMapping(markerSwitch, "rtm:markerSwitch"); -// RTMCore.registerMapping(markerSlope, "rtm:markerSlope"); - - GameRegistry.registerBlock(fluorescent, "fluorescent"); - GameRegistry.registerBlock(ironPillar, "ironPillar"); - GameRegistry.registerBlock(insulator, "insulator"); - GameRegistry.registerBlock(signal, "signal"); - GameRegistry.registerBlock(crossingGate, "crossing"); - GameRegistry.registerBlock(variableBlock, "Variable"); - GameRegistry.registerBlock(linePole, "linePole"); - GameRegistry.registerBlock(connector, "connector"); - GameRegistry.registerBlock(powerUnit, "powerUnit"); - RTMCore.registerMapping(fluorescent, "rtm:fluorescent"); - RTMCore.registerMapping(ironPillar, "rtm:ironPillar"); - RTMCore.registerMapping(insulator, "rtm:insulator"); - RTMCore.registerMapping(signal, "rtm:signal"); - RTMCore.registerMapping(crossingGate, "rtm:crossing"); - RTMCore.registerMapping(variableBlock, "rtm:Variable"); - RTMCore.registerMapping(linePole, "rtm:linePole"); - RTMCore.registerMapping(connector, "rtm:connector"); - RTMCore.registerMapping(powerUnit, "rtm:powerUnit"); + RTMCore.registerRtmPrefixed(marker, "rtm:marker"); + RTMCore.registerRtmPrefixed(markerSwitch, "rtm:markerSwitch"); +// RTMCore.registerRtmPrefixed(markerSlope, "rtm:markerSlope"); + + RTMCore.registerRtmPrefixed(fluorescent, "rtm:fluorescent"); + RTMCore.registerRtmPrefixed(ironPillar, "rtm:ironPillar"); + RTMCore.registerRtmPrefixed(insulator, "rtm:insulator"); + RTMCore.registerRtmPrefixed(signal, "rtm:signal"); + RTMCore.registerRtmPrefixed(crossingGate, "rtm:crossing"); + RTMCore.registerRtmPrefixed(variableBlock, "rtm:Variable"); + RTMCore.registerRtmPrefixed(linePole, "rtm:linePole"); + RTMCore.registerRtmPrefixed(connector, "rtm:connector"); + RTMCore.registerRtmPrefixed(powerUnit, "rtm:powerUnit"); GameRegistry.registerBlock(signalConverter, ItemBlockCustom.class, "signal_converter"); - GameRegistry.registerBlock(railroadSign, "railroadSign"); - GameRegistry.registerBlock(turnstile, "turnstile"); - GameRegistry.registerBlock(point, "point"); - GameRegistry.registerBlock(rsWire, "rsWire"); - GameRegistry.registerBlock(signboard, "signboard"); - GameRegistry.registerBlock(trainWorkBench, ItemBlockCustom.class, "trainWorkBench"); - RTMCore.registerMapping(railroadSign, "rtm:railroadSign"); - RTMCore.registerMapping(turnstile, "rtm:turnstile"); - RTMCore.registerMapping(point, "rtm:point"); - RTMCore.registerMapping(rsWire, "rtm:rsWire"); - RTMCore.registerMapping(signboard, "rtm:signboard"); - RTMCore.registerMapping(trainWorkBench, "rtm:trainWorkBench"); + RTMCore.registerRtmPrefixed(railroadSign, "rtm:railroadSign"); + RTMCore.registerRtmPrefixed(turnstile, "rtm:turnstile"); + RTMCore.registerRtmPrefixed(point, "rtm:point"); + RTMCore.registerRtmPrefixed(rsWire, "rtm:rsWire"); + RTMCore.registerRtmPrefixed(signboard, "rtm:signboard"); + RTMCore.registerRtmPrefixed(trainWorkBench, ItemBlockCustom.class, "rtm:trainWorkBench"); GameRegistry.registerBlock(ticketVendor, "ticketVendor"); GameRegistry.registerBlock(mirror, "mirror"); GameRegistry.registerBlock(mirrorCube, "mirror_cube"); @@ -206,36 +188,21 @@ public static void init() { GameRegistry.registerBlock(light, "light_block"); GameRegistry.registerBlock(speaker, "speaker"); - GameRegistry.registerBlock(fireBrick, "fireBrick"); - GameRegistry.registerBlock(hotStoveBrick, "hotStoveBrick"); - GameRegistry.registerBlock(pipe, "pipe"); - GameRegistry.registerBlock(slot, "slot"); - GameRegistry.registerBlock(furnaceFire, "furnaceFire"); - GameRegistry.registerBlock(exhaustGas, "exhaustGas"); - GameRegistry.registerBlock(liquefiedPigIron, "pigIron_L"); - GameRegistry.registerBlock(liquefiedSteel, "steel_L"); - GameRegistry.registerBlock(slag, "slag"); - GameRegistry.registerBlock(converterCore, "converterCore"); - GameRegistry.registerBlock(converterBase, "converterBase"); - GameRegistry.registerBlock(steelSlab, "steelSlab"); - GameRegistry.registerBlock(brickSlab, "brickSlab"); - GameRegistry.registerBlock(brickDoubleSlab, "brickDoubleSlab"); - GameRegistry.registerBlock(steelMaterial, "steelMaterial"); - RTMCore.registerMapping(fireBrick, "rtm:fireBrick"); - RTMCore.registerMapping(hotStoveBrick, "rtm:hotStoveBrick"); - RTMCore.registerMapping(pipe, "rtm:pipe"); - RTMCore.registerMapping(slot, "rtm:slot"); - RTMCore.registerMapping(furnaceFire, "rtm:furnaceFire"); - RTMCore.registerMapping(exhaustGas, "rtm:exhaustGas"); - RTMCore.registerMapping(liquefiedPigIron, "rtm:pigIron_L"); - RTMCore.registerMapping(liquefiedSteel, "rtm:steel_L"); - RTMCore.registerMapping(slag, "rtm:slag"); - RTMCore.registerMapping(converterCore, "rtm:converterCore"); - RTMCore.registerMapping(converterBase, "rtm:converterBase"); - RTMCore.registerMapping(steelSlab, "rtm:steelSlab"); - RTMCore.registerMapping(brickSlab, "rtm:brickSlab"); - RTMCore.registerMapping(brickDoubleSlab, "rtm:brickDoubleSlab"); - RTMCore.registerMapping(steelMaterial, "rtm:steelMaterial"); + RTMCore.registerRtmPrefixed(fireBrick, "rtm:fireBrick"); + RTMCore.registerRtmPrefixed(hotStoveBrick, "rtm:hotStoveBrick"); + RTMCore.registerRtmPrefixed(pipe, "rtm:pipe"); + RTMCore.registerRtmPrefixed(slot, "rtm:slot"); + RTMCore.registerRtmPrefixed(furnaceFire, "rtm:furnaceFire"); + RTMCore.registerRtmPrefixed(exhaustGas, "rtm:exhaustGas"); + RTMCore.registerRtmPrefixed(liquefiedPigIron, "rtm:pigIron_L"); + RTMCore.registerRtmPrefixed(liquefiedSteel, "rtm:steel_L"); + RTMCore.registerRtmPrefixed(slag, "rtm:slag"); + RTMCore.registerRtmPrefixed(converterCore, "rtm:converterCore"); + RTMCore.registerRtmPrefixed(converterBase, "rtm:converterBase"); + RTMCore.registerRtmPrefixed(steelSlab, "rtm:steelSlab"); + RTMCore.registerRtmPrefixed(brickSlab, "rtm:brickSlab"); + RTMCore.registerRtmPrefixed(brickDoubleSlab, "rtm:brickDoubleSlab"); + RTMCore.registerRtmPrefixed(steelMaterial, "rtm:steelMaterial"); GameRegistry.registerBlock(scaffold, "scaffold"); GameRegistry.registerBlock(scaffoldStairs, "scaffold_stairs"); GameRegistry.registerBlock(framework, "framework"); diff --git a/src/main/java/jp/ngt/rtm/RTMCore.java b/src/main/java/jp/ngt/rtm/RTMCore.java index f48a112b..160ad3ac 100644 --- a/src/main/java/jp/ngt/rtm/RTMCore.java +++ b/src/main/java/jp/ngt/rtm/RTMCore.java @@ -7,6 +7,7 @@ import cpw.mods.fml.common.event.*; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import jp.kaiz.kaizpatch.fixrtm.modelpack.FIXFileLoader; import jp.ngt.ngtlib.util.PermissionManager; @@ -18,6 +19,7 @@ import jp.ngt.rtm.world.RTMChunkManager; import net.minecraft.block.Block; import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; @@ -220,6 +222,26 @@ public void handleServerStarting(FMLServerStartingEvent event) { WireManager.INSTANCE.clear(); } + public static void registerRtmPrefixed(Item item, String name) { + GameRegistry.registerItem(item, removePrefix(name)); + registerMapping(item, name); + } + + public static void registerRtmPrefixed(Block block, String name) { + GameRegistry.registerBlock(block, removePrefix(name)); + registerMapping(block, name); + } + + public static void registerRtmPrefixed(Block block, Class itemclass, String name) { + GameRegistry.registerBlock(block, itemclass, removePrefix(name)); + registerMapping(block, name); + } + + private static String removePrefix(String name) { + assert name.startsWith("rtm:"); + return name.substring("rtm:".length()); + } + public static void registerMapping(Item item, String name) { itemMap.put(MODID + ':' + name, item); } diff --git a/src/main/java/jp/ngt/rtm/RTMItem.java b/src/main/java/jp/ngt/rtm/RTMItem.java index c9f075b6..cdc25685 100644 --- a/src/main/java/jp/ngt/rtm/RTMItem.java +++ b/src/main/java/jp/ngt/rtm/RTMItem.java @@ -113,28 +113,17 @@ public static void init() { camera = (new ItemCamera()).setUnlocalizedName("rtm:camera").setTextureName("rtm:camera").setCreativeTab(CreativeTabRTM.tabRTMTools); - GameRegistry.registerItem(bogie, "bogie"); - GameRegistry.registerItem(installedObject, "installedObject"); - GameRegistry.registerItem(material, "material"); - GameRegistry.registerItem(crowbar, "crowbar"); - GameRegistry.registerItem(itemtrain, "itemTrain"); - GameRegistry.registerItem(itemMotorman, "itemMotorman"); - GameRegistry.registerItem(itemCargo, "itemCargo"); - GameRegistry.registerItem(itemRailroadSign, "itemRailroadSign"); - GameRegistry.registerItem(ticket, "ticket"); - GameRegistry.registerItem(ticketBook, "ticketBook"); - GameRegistry.registerItem(icCard, "icCard"); - RTMCore.registerMapping(bogie, "rtm:bogie"); - RTMCore.registerMapping(installedObject, "rtm:installedObject"); - RTMCore.registerMapping(material, "rtm:material"); - RTMCore.registerMapping(crowbar, "rtm:crowbar"); - RTMCore.registerMapping(itemtrain, "rtm:itemTrain"); - RTMCore.registerMapping(itemMotorman, "rtm:itemMotorman"); - RTMCore.registerMapping(itemCargo, "rtm:itemCargo"); - RTMCore.registerMapping(itemRailroadSign, "rtm:itemRailroadSign"); - RTMCore.registerMapping(ticket, "rtm:ticket"); - RTMCore.registerMapping(ticketBook, "rtm:ticketBook"); - RTMCore.registerMapping(icCard, "rtm:icCard"); + RTMCore.registerRtmPrefixed(bogie, "rtm:bogie"); + RTMCore.registerRtmPrefixed(installedObject, "rtm:installedObject"); + RTMCore.registerRtmPrefixed(material, "rtm:material"); + RTMCore.registerRtmPrefixed(crowbar, "rtm:crowbar"); + RTMCore.registerRtmPrefixed(itemtrain, "rtm:itemTrain"); + RTMCore.registerRtmPrefixed(itemMotorman, "rtm:itemMotorman"); + RTMCore.registerRtmPrefixed(itemCargo, "rtm:itemCargo"); + RTMCore.registerRtmPrefixed(itemRailroadSign, "rtm:itemRailroadSign"); + RTMCore.registerRtmPrefixed(ticket, "rtm:ticket"); + RTMCore.registerRtmPrefixed(ticketBook, "rtm:ticketBook"); + RTMCore.registerRtmPrefixed(icCard, "rtm:icCard"); GameRegistry.registerItem(itemLargeRail, "itemLargeRail"); GameRegistry.registerItem(itemSignal, "itemSignal"); GameRegistry.registerItem(itemLinePole, "itemLinePole"); @@ -160,24 +149,16 @@ public static void init() { GameRegistry.registerItem(bullet, "bullet"); GameRegistry.registerItem(nvd, "nvd"); - GameRegistry.registerItem(bucketLiquid, "bucketLiquid"); - GameRegistry.registerItem(iron_hacksaw, "ironHacksaw"); - GameRegistry.registerItem(steel_ingot, "ingotSteel"); - GameRegistry.registerItem(paddle, "paddle"); - GameRegistry.registerItem(coke, "coke"); - GameRegistry.registerItem(bellows, "bellows"); - GameRegistry.registerItem(itemPipe, "itemPipe"); - RTMCore.registerMapping(bucketLiquid, "rtm:bucketLiquid"); - RTMCore.registerMapping(iron_hacksaw, "rtm:ironHacksaw"); - RTMCore.registerMapping(steel_ingot, "rtm:ingotSteel"); - RTMCore.registerMapping(paddle, "rtm:paddle"); - RTMCore.registerMapping(coke, "rtm:coke"); - RTMCore.registerMapping(bellows, "rtm:bellows"); - RTMCore.registerMapping(itemPipe, "rtm:itemPipe"); + RTMCore.registerRtmPrefixed(bucketLiquid, "rtm:bucketLiquid"); + RTMCore.registerRtmPrefixed(iron_hacksaw, "rtm:ironHacksaw"); + RTMCore.registerRtmPrefixed(steel_ingot, "rtm:ingotSteel"); + RTMCore.registerRtmPrefixed(paddle, "rtm:paddle"); + RTMCore.registerRtmPrefixed(coke, "rtm:coke"); + RTMCore.registerRtmPrefixed(bellows, "rtm:bellows"); + RTMCore.registerRtmPrefixed(itemPipe, "rtm:itemPipe"); GameRegistry.registerItem(paintTool, "paint_tool"); - GameRegistry.registerItem(camera, "camera"); - RTMCore.registerMapping(camera, "rtm:camera"); + RTMCore.registerRtmPrefixed(camera, "rtm:camera"); OreDictionary.registerOre("ingotSteel", new ItemStack(steel_ingot, 1, 0)); OreDictionary.registerOre("fuelCoke", new ItemStack(coke, 1, 0)); diff --git a/src/main/java/jp/ngt/rtm/RTMRail.java b/src/main/java/jp/ngt/rtm/RTMRail.java index 9660a24a..544a15aa 100644 --- a/src/main/java/jp/ngt/rtm/RTMRail.java +++ b/src/main/java/jp/ngt/rtm/RTMRail.java @@ -44,20 +44,13 @@ public static void init() { largeRailSlopeCore[i] = (new BlockLargeRailSlopeCore(i)).setBlockName("rtm:LRLCore." + i).setBlockTextureName(railTexture[i]); }); - GameRegistry.registerBlock(largeRailBase0, "LRBase"); - GameRegistry.registerBlock(largeRailCore0, "LRCore"); - GameRegistry.registerBlock(largeRailSwitchBase0, "LRSBase"); - GameRegistry.registerBlock(largeRailSwitchCore0, "LRSCore"); - GameRegistry.registerBlock(largeRailSlopeBase0, "LRLBase"); - GameRegistry.registerBlock(largeRailSlopeCore0, "LRLCore"); - GameRegistry.registerBlock(TURNTABLE_CORE, "turntable_core"); - RTMCore.registerMapping(largeRailBase0, "rtm:LRBase"); - RTMCore.registerMapping(largeRailCore0, "rtm:LRCore"); - RTMCore.registerMapping(largeRailSwitchBase0, "rtm:LRSBase"); - RTMCore.registerMapping(largeRailSwitchCore0, "rtm:LRSCore"); - RTMCore.registerMapping(largeRailSlopeBase0, "rtm:LRLBase"); - RTMCore.registerMapping(largeRailSlopeCore0, "rtm:LRLCore"); - RTMCore.registerMapping(TURNTABLE_CORE, "rtm:turntable_core"); + RTMCore.registerRtmPrefixed(largeRailBase0, "rtm:LRBase"); + RTMCore.registerRtmPrefixed(largeRailCore0, "rtm:LRCore"); + RTMCore.registerRtmPrefixed(largeRailSwitchBase0, "rtm:LRSBase"); + RTMCore.registerRtmPrefixed(largeRailSwitchCore0, "rtm:LRSCore"); + RTMCore.registerRtmPrefixed(largeRailSlopeBase0, "rtm:LRLBase"); + RTMCore.registerRtmPrefixed(largeRailSlopeCore0, "rtm:LRLCore"); + RTMCore.registerRtmPrefixed(TURNTABLE_CORE, "rtm:turntable_core"); //インスタンス使いまわして登録は不可 IntStream.range(0, railTexture.length).forEach(i -> {