|
| 1 | +# Phase 9B: Mechanical Cleanup — ResourceLocation Migration |
| 2 | + |
| 3 | +**Phase:** 9B of 10 |
| 4 | +**Effort:** LOW |
| 5 | +**Estimated files:** 30 |
| 6 | +**Estimated changes:** ~80 ResourceLocation constructor usages |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +Phase 9B is a purely mechanical find-and-replace phase. In NeoForge 1.21.1, the `ResourceLocation` constructor is deprecated/removed. All `new ResourceLocation(...)` calls must be replaced with static factory methods: |
| 13 | + |
| 14 | +- `new ResourceLocation(namespace, path)` → `ResourceLocation.fromNamespaceAndPath(namespace, path)` |
| 15 | +- `new ResourceLocation(string)` → `ResourceLocation.parse(string)` |
| 16 | + |
| 17 | +After replacement, run data generators and a full build to verify nothing was missed. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +- **Phase 9A complete** — All vanilla/NeoForge API reworks (AbstractMinecart.Type, PartEntity, ItemStackHandler imports) must be done first. |
| 24 | +- All prior phases (1 through 9A) must pass `./gradlew build`. |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## Replacement Rules |
| 29 | + |
| 30 | +### Rule 1: Two-argument constructor (namespace, path) |
| 31 | + |
| 32 | +``` |
| 33 | +BEFORE: new ResourceLocation(ShippingMod.MOD_ID, "some/path") |
| 34 | +AFTER: ResourceLocation.fromNamespaceAndPath(ShippingMod.MOD_ID, "some/path") |
| 35 | +``` |
| 36 | + |
| 37 | +Regex: |
| 38 | +``` |
| 39 | +new ResourceLocation\(([^,]+),\s*([^)]+)\) |
| 40 | +→ |
| 41 | +ResourceLocation.fromNamespaceAndPath($1, $2) |
| 42 | +``` |
| 43 | + |
| 44 | +**~75 usages** across 28 files. |
| 45 | + |
| 46 | +### Rule 2: Single-argument constructor (full string) |
| 47 | + |
| 48 | +``` |
| 49 | +BEFORE: new ResourceLocation("minecraft:textures/block/lava_still.png") |
| 50 | +BEFORE: new ResourceLocation(someVariable) |
| 51 | +AFTER: ResourceLocation.parse("minecraft:textures/block/lava_still.png") |
| 52 | +AFTER: ResourceLocation.parse(someVariable) |
| 53 | +``` |
| 54 | + |
| 55 | +Regex: |
| 56 | +``` |
| 57 | +new ResourceLocation\(([^,)]+)\) |
| 58 | +→ |
| 59 | +ResourceLocation.parse($1) |
| 60 | +``` |
| 61 | + |
| 62 | +**5 usages** across 5 files. |
| 63 | + |
| 64 | +### Ordering |
| 65 | + |
| 66 | +Apply Rule 1 (two-arg) FIRST, then Rule 2 (single-arg). This avoids Rule 2 accidentally matching the first argument of a two-arg call. Alternatively, apply Rule 1 globally, verify, then apply Rule 2. |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Automation Strategy |
| 71 | + |
| 72 | +**Yes, this can be automated with regex find-replace**, with one caveat: |
| 73 | + |
| 74 | +1. **Step 1:** Run two-arg replacement across all `.java` files: |
| 75 | + ```bash |
| 76 | + find src -name '*.java' -exec sed -i '' \ |
| 77 | + 's/new ResourceLocation(\([^,]*\), /ResourceLocation.fromNamespaceAndPath(\1, /g' {} + |
| 78 | + ``` |
| 79 | + |
| 80 | +2. **Step 2:** Run single-arg replacement across all `.java` files: |
| 81 | + ```bash |
| 82 | + find src -name '*.java' -exec sed -i '' \ |
| 83 | + 's/new ResourceLocation(\([^,)]*\))/ResourceLocation.parse(\1)/g' {} + |
| 84 | + ``` |
| 85 | + |
| 86 | +3. **Step 3:** Manual review of any edge cases (e.g., multi-line constructor calls, nested parentheses). Grep to verify zero remaining `new ResourceLocation(` calls: |
| 87 | + ```bash |
| 88 | + grep -rn 'new ResourceLocation(' src/main/java/ |
| 89 | + ``` |
| 90 | + Expected: only commented-out lines (3 total in FluidRenderUtil.java, SpringItem.java, ModTags.java). |
| 91 | + |
| 92 | +**Caveat:** The `ModEntityTypes.java` usages are inside `.build(new ResourceLocation(...).toString())` chains. The two-arg regex handles this correctly since the inner `new ResourceLocation(ns, path)` is replaced regardless of surrounding context. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Complete File List |
| 97 | + |
| 98 | +### Two-argument usages (`fromNamespaceAndPath`) |
| 99 | + |
| 100 | +| # | File | Line(s) | Count | Context | |
| 101 | +|---|------|---------|-------|---------| |
| 102 | +| 1 | `ShippingMod.java` | 54 | 1 | Texture helper method | |
| 103 | +| 2 | `event/ForgeClientEventHandler.java` | 51 | 1 | Beacon beam texture | |
| 104 | +| 3 | `data/client/ModItemModelProvider.java` | 50, 55, 74 | 3 | Item model predicates | |
| 105 | +| 4 | `data/client/ModBlockStateProvider.java` | 32 | 1 | Block texture helper | |
| 106 | +| 5 | `item/container/TugRouteScreen.java` | 26 | 1 | GUI texture | |
| 107 | +| 6 | `item/container/StringInputScreen.java` | 23 | 1 | GUI texture | |
| 108 | +| 7 | `entity/container/AbstractHeadVehicleScreen.java` | 15 | 1 | Registration GUI texture | |
| 109 | +| 8 | `entity/container/EnergyHeadVehicleScreen.java` | 20 | 1 | Energy locomotive GUI | |
| 110 | +| 9 | `entity/container/SteamHeadVehicleScreen.java` | 16 | 1 | Steam locomotive GUI | |
| 111 | +| 10 | `entity/render/barge/AbstractVesselRenderer.java` | 29 | 1 | Chain texture | |
| 112 | +| 11 | `entity/render/train/TrainCarRenderer.java` | 33, 40 | 2 | Chain texture + base texture | |
| 113 | +| 12 | `entity/render/train/MultipartCarRenderer.java` | 55 | 1 | Chain texture | |
| 114 | +| 13 | `entity/models/train/EnergyLocomotiveModel.java` | 21 | 1 | ModelLayerLocation | |
| 115 | +| 14 | `entity/models/train/SteamLocomotiveModel.java` | 20 | 1 | ModelLayerLocation | |
| 116 | +| 15 | `entity/models/train/BaseCarModel.java` | 20 | 1 | ModelLayerLocation | |
| 117 | +| 16 | `entity/models/train/ChainModel.java` | 20 | 1 | ModelLayerLocation | |
| 118 | +| 17 | `entity/models/train/ChainExtendedModel.java` | 19 | 1 | ModelLayerLocation | |
| 119 | +| 18 | `entity/models/train/ChunkLoaderCarModel.java` | 19 | 1 | ModelLayerLocation | |
| 120 | +| 19 | `entity/models/train/SeaterCarModel.java` | 17 | 1 | ModelLayerLocation | |
| 121 | +| 20 | `entity/models/train/TrimCarModel.java` | 20 | 1 | ModelLayerLocation | |
| 122 | +| 21 | `entity/models/insert/CubeInsertCarModel.java` | 17 | 1 | ModelLayerLocation | |
| 123 | +| 22 | `entity/models/insert/CubeInsertBargeModel.java` | 17 | 1 | ModelLayerLocation | |
| 124 | +| 23 | `entity/models/insert/SeaterInsertBargeModel.java` | 19 | 1 | ModelLayerLocation | |
| 125 | +| 24 | `entity/models/insert/FishingInsertBargeModel.java` | 19, 20, 21 | 3 | ModelLayerLocation (3 states) | |
| 126 | +| 25 | `entity/models/insert/FluidTankInsertCarModel.java` | 21 | 1 | ModelLayerLocation | |
| 127 | +| 26 | `entity/models/insert/FluidTankInsertBargeModel.java` | 19 | 1 | ModelLayerLocation | |
| 128 | +| 27 | `entity/models/insert/RingsInsertBargeModel.java` | 19 | 1 | ModelLayerLocation | |
| 129 | +| 28 | `entity/models/vessel/SteamTugModel.java` | 20 | 1 | ModelLayerLocation | |
| 130 | +| 29 | `entity/models/vessel/EmptyModel.java` | 21 | 1 | ModelLayerLocation | |
| 131 | +| 30 | `entity/models/vessel/EnergyTugModel.java` | 18 | 1 | ModelLayerLocation | |
| 132 | +| 31 | `entity/models/vessel/base/BaseBargeModel.java` | 18, 19, 20 | 3 | ModelLayerLocation (3 variants) | |
| 133 | +| 32 | `entity/models/vessel/base/TrimBargeModel.java` | 21, 22, 23 | 3 | ModelLayerLocation (3 variants) | |
| 134 | +| 33 | `setup/ModTags.java` | 25, 29 | 2 | Tag creation (note: line 25 "forge"→"c" is Phase 2/M-4) | |
| 135 | +| 34 | `setup/ModSounds.java` | 11, 14, 17 | 3 | SoundEvent creation | |
| 136 | +| 35 | `setup/ModItemModelProperties.java` | 14, 18, 22 | 3 | Item property overrides | |
| 137 | +| 36 | `setup/ModItems.java` | 40, 41, 42 | 3 | Route/energy icons | |
| 138 | +| 37 | `setup/ModEntityTypes.java` | 25, 32, 39, 46, 53, 60, 67, 74, 81, 89, 97, 105, 113, 121, 130, 139 | 16 | Entity type .build() | |
| 139 | +| 38 | `network/TugRoutePacketHandler.java` | 22 | 1 | Channel location | |
| 140 | +| 39 | `network/client/VehicleTrackerPacketHandler.java` | 22 | 1 | Channel location | |
| 141 | +| 40 | `network/VehiclePacketHandler.java` | 19 | 1 | Channel location | |
| 142 | + |
| 143 | +**Subtotal: ~75 usages across 40 source locations in 30 files** |
| 144 | + |
| 145 | +### Single-argument usages (`parse`) |
| 146 | + |
| 147 | +| # | File | Line | Context | |
| 148 | +|---|------|------|---------| |
| 149 | +| 1 | `global/TrainChunkManagerManager.java` | 44 | Dimension key from NBT string | |
| 150 | +| 2 | `entity/custom/train/wagon/FluidTankCarEntity.java` | 114 | Fluid type from entity data | |
| 151 | +| 3 | `entity/custom/vessel/barge/FluidTankBargeEntity.java` | 109 | Fluid type from entity data | |
| 152 | +| 4 | `entity/custom/vessel/barge/FishingBargeEntity.java` | 58 | Loot table from config | |
| 153 | +| 5 | `entity/container/FishingBargeScreen.java` | 12 | Vanilla container texture | |
| 154 | + |
| 155 | +**Subtotal: 5 usages across 5 files** |
| 156 | + |
| 157 | +### Commented-out lines (no action needed) |
| 158 | + |
| 159 | +| File | Line | Status | |
| 160 | +|------|------|--------| |
| 161 | +| `util/FluidRenderUtil.java` | 183 | Commented out | |
| 162 | +| `item/SpringItem.java` | 53 | Commented out | |
| 163 | +| `setup/ModTags.java` | 13, 17 | Commented out | |
| 164 | + |
| 165 | +--- |
| 166 | + |
| 167 | +## Note on Network Handler Files |
| 168 | + |
| 169 | +The three network handler files (`VehiclePacketHandler.java`, `TugRoutePacketHandler.java`, `VehicleTrackerPacketHandler.java`) are **deleted in Phase 3**. If Phase 3 has already been completed, these files will not exist. If Phase 9B runs before Phase 3 (unlikely given phase ordering), they should still be updated. |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +## Execution Steps |
| 174 | + |
| 175 | +### Step 1: Verify preconditions |
| 176 | +```bash |
| 177 | +./gradlew build # Must pass (Phase 9A complete) |
| 178 | +``` |
| 179 | + |
| 180 | +### Step 2: Apply two-arg replacement |
| 181 | +```bash |
| 182 | +# In IDE: Find and Replace with regex across src/main/java/ |
| 183 | +# Find: new ResourceLocation\(([^,]+),\s* |
| 184 | +# Replace: ResourceLocation.fromNamespaceAndPath($1, |
| 185 | +``` |
| 186 | + |
| 187 | +### Step 3: Apply single-arg replacement |
| 188 | +```bash |
| 189 | +# Find: new ResourceLocation\(([^,)]+)\) |
| 190 | +# Replace: ResourceLocation.parse($1) |
| 191 | +``` |
| 192 | + |
| 193 | +### Step 4: Verify no remaining usages |
| 194 | +```bash |
| 195 | +grep -rn 'new ResourceLocation(' src/main/java/ | grep -v '//' |
| 196 | +# Expected output: empty (all active usages replaced) |
| 197 | +``` |
| 198 | + |
| 199 | +### Step 5: Run data generators |
| 200 | +```bash |
| 201 | +./gradlew runData |
| 202 | +``` |
| 203 | + |
| 204 | +### Step 6: Full build |
| 205 | +```bash |
| 206 | +./gradlew build |
| 207 | +``` |
| 208 | + |
| 209 | +Both commands must succeed. If `runData` fails, check the data generation provider files (ModBlockStateProvider, ModItemModelProvider) for any ResourceLocation usages that were missed. |
| 210 | + |
| 211 | +--- |
| 212 | + |
| 213 | +## Files Touched |
| 214 | + |
| 215 | +All paths relative to `src/main/java/dev/murad/shipping/`: |
| 216 | + |
| 217 | +``` |
| 218 | +ShippingMod.java |
| 219 | +event/ForgeClientEventHandler.java |
| 220 | +global/TrainChunkManagerManager.java |
| 221 | +data/client/ModItemModelProvider.java |
| 222 | +data/client/ModBlockStateProvider.java |
| 223 | +item/container/TugRouteScreen.java |
| 224 | +item/container/StringInputScreen.java |
| 225 | +entity/container/AbstractHeadVehicleScreen.java |
| 226 | +entity/container/EnergyHeadVehicleScreen.java |
| 227 | +entity/container/SteamHeadVehicleScreen.java |
| 228 | +entity/container/FishingBargeScreen.java |
| 229 | +entity/render/barge/AbstractVesselRenderer.java |
| 230 | +entity/render/train/TrainCarRenderer.java |
| 231 | +entity/render/train/MultipartCarRenderer.java |
| 232 | +entity/models/train/EnergyLocomotiveModel.java |
| 233 | +entity/models/train/SteamLocomotiveModel.java |
| 234 | +entity/models/train/BaseCarModel.java |
| 235 | +entity/models/train/ChainModel.java |
| 236 | +entity/models/train/ChainExtendedModel.java |
| 237 | +entity/models/train/ChunkLoaderCarModel.java |
| 238 | +entity/models/train/SeaterCarModel.java |
| 239 | +entity/models/train/TrimCarModel.java |
| 240 | +entity/models/insert/CubeInsertCarModel.java |
| 241 | +entity/models/insert/CubeInsertBargeModel.java |
| 242 | +entity/models/insert/SeaterInsertBargeModel.java |
| 243 | +entity/models/insert/FishingInsertBargeModel.java |
| 244 | +entity/models/insert/FluidTankInsertCarModel.java |
| 245 | +entity/models/insert/FluidTankInsertBargeModel.java |
| 246 | +entity/models/insert/RingsInsertBargeModel.java |
| 247 | +entity/models/vessel/SteamTugModel.java |
| 248 | +entity/models/vessel/EmptyModel.java |
| 249 | +entity/models/vessel/EnergyTugModel.java |
| 250 | +entity/models/vessel/base/BaseBargeModel.java |
| 251 | +entity/models/vessel/base/TrimBargeModel.java |
| 252 | +entity/custom/train/wagon/FluidTankCarEntity.java |
| 253 | +entity/custom/vessel/barge/FluidTankBargeEntity.java |
| 254 | +entity/custom/vessel/barge/FishingBargeEntity.java |
| 255 | +setup/ModTags.java |
| 256 | +setup/ModSounds.java |
| 257 | +setup/ModItemModelProperties.java |
| 258 | +setup/ModItems.java |
| 259 | +setup/ModEntityTypes.java |
| 260 | +network/TugRoutePacketHandler.java |
| 261 | +network/client/VehicleTrackerPacketHandler.java |
| 262 | +network/VehiclePacketHandler.java |
| 263 | +``` |
| 264 | + |
| 265 | +**Total: 44 files** (30 unique files with two-arg, 5 with single-arg, some overlap; 3 network files may be deleted by Phase 3) |
| 266 | + |
| 267 | +--- |
| 268 | + |
| 269 | +## Risk Assessment |
| 270 | + |
| 271 | +- **Risk: LOW** — This is a purely mechanical replacement with no behavioral changes. |
| 272 | +- **Edge case:** Multi-line `new ResourceLocation(` calls. Grep shows none in this codebase — all calls are single-line. |
| 273 | +- **Edge case:** `ModEntityTypes.java` uses `new ResourceLocation(...).toString()` inside `.build()`. The regex handles this correctly since it replaces the constructor call regardless of what follows the closing parenthesis. |
| 274 | +- **Edge case:** Commented-out code contains `new ResourceLocation(`. Leave as-is; these are dead code and will not cause compilation errors. |
0 commit comments