Skip to content

Commit 0c8f263

Browse files
committed
Implement dynamic model loading
1 parent 876c63e commit 0c8f263

27 files changed

+1911
-101
lines changed

src/main/java/org/dimdev/vanillafix/LoadingConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class LoadingConfig {
1414
public boolean profiler;
1515
public boolean textureFixes;
1616
public boolean blockstates;
17-
17+
public boolean dynamicResources;
1818

1919
public void init(File file) {
2020
if (!file.exists()) {
@@ -23,6 +23,8 @@ public void init(File file) {
2323
modSupport = true;
2424
profiler = true;
2525
textureFixes = true;
26+
blockstates = true;
27+
dynamicResources = true;
2628
return;
2729
}
2830
if (config == null) {
@@ -38,5 +40,6 @@ public void reload() {
3840
profiler = config.get("fixes", "profiler", true).getBoolean();
3941
textureFixes = config.get("fixes", "textureFixes", true).getBoolean();
4042
blockstates = config.get("fixes", "blockstates", true).getBoolean();
43+
dynamicResources = config.get("fixes", "dynamicresources", true).getBoolean();
4144
}
4245
}

src/main/java/org/dimdev/vanillafix/ModConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public static class Fixes {
5050
@LangKey("vanillafix.fixes.blockstates")
5151
@RequiresMcRestart
5252
public boolean blockstates = true;
53+
54+
@Name("dynamicresources")
55+
@LangKey("vanillafix.fixes.dynamicresources")
56+
@RequiresMcRestart
57+
public boolean dynamicresources = true;
5358
}
5459

5560
public static class Crashes {

src/main/java/org/dimdev/vanillafix/VanillaFix.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraft.item.ItemBlock;
99
import net.minecraft.util.ReportedException;
1010
import net.minecraft.util.ResourceLocation;
11+
import net.minecraftforge.common.ForgeModContainer;
1112
import net.minecraftforge.common.MinecraftForge;
1213
import net.minecraftforge.common.config.Config;
1314
import net.minecraftforge.common.config.ConfigManager;
@@ -73,6 +74,9 @@ public void onPreInit(FMLPreInitializationEvent event) {
7374
// Register event listeners
7475
MinecraftForge.EVENT_BUS.register(ModConfig.class);
7576

77+
// Don't render terrain on main thread for higher FPS, but possibly seeing missing chunks
78+
ForgeModContainer.alwaysSetupTerrainOffThread = true;
79+
7680
IForgeRegistry<Block> blockRegistry = GameRegistry.findRegistry(Block.class);
7781
IForgeRegistry<Item> itemRegistry = GameRegistry.findRegistry(Item.class);
7882

src/main/java/org/dimdev/vanillafix/VanillaFixLoadingPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public VanillaFixLoadingPlugin() {
4646
if (config.profiler) Mixins.addConfiguration("mixins.vanillafix.profiler.json");
4747
if (config.textureFixes) Mixins.addConfiguration("mixins.vanillafix.textures.json");
4848
if (config.modSupport) Mixins.addConfiguration("mixins.vanillafix.modsupport.json");
49-
if (config.blockstates) Mixins.addConfiguration("mixins.vanillafix.blockstates.json");
49+
if (config.blockstates) Mixins.addConfiguration("mixins.vanillafix.blockstates.json");
50+
if (config.dynamicResources) Mixins.addConfiguration("mixins.vanillafix.dynamicresources.json");
5051
// @formatter:on
5152
}
5253

src/main/java/org/dimdev/vanillafix/blockstates/NumericalBlockState.java

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ public class NumericalBlockState extends BlockStateBase {
4242
private static final Map<IProperty<?>, Integer> propertyWidths = new HashMap<>();
4343

4444
protected final BlockStateContainer container;
45+
protected final Block block;
4546
protected final int data; // TODO: short
4647

4748
protected NumericalBlockState(BlockStateContainer container, int data) {
4849
this.container = container;
50+
block = container.getBlock();
4951
this.data = data;
5052
}
5153

@@ -104,7 +106,7 @@ public <T extends Comparable<T>> T getValue(IProperty<T> property) {
104106
int offset = ((IPatchedBlockStateContainer) container).getPropertyOffsets().getOrDefault(property, -1);
105107

106108
if (offset == -1) {
107-
throw new IllegalArgumentException("Cannot get property " + property + " as it does not exist in " + container.getBlock().getBlockState());
109+
throw new IllegalArgumentException("Cannot get property " + property + " as it does not exist in " + container);
108110
}
109111

110112
int width = propertyWidths.get(property);
@@ -119,7 +121,7 @@ public <T extends Comparable<T>, V extends T> IBlockState withProperty(IProperty
119121
int offset = ((IPatchedBlockStateContainer) container).getPropertyOffsets().getOrDefault(property, -1);
120122

121123
if (offset == -1) {
122-
throw new IllegalArgumentException("Cannot set property " + property + " as it does not exist in " + container.getBlock().getBlockState());
124+
throw new IllegalArgumentException("Cannot set property " + property + " as it does not exist in " + container);
123125
}
124126

125127
@SuppressWarnings("SuspiciousMethodCalls") int number = valueToNumber.get(new ImmutablePair<>(property, value));
@@ -152,235 +154,235 @@ public int hashCode() {
152154

153155
@Override
154156
public Block getBlock() {
155-
return container.getBlock();
157+
return block;
156158
}
157159

158160
// <editor-fold defaultstate="collapsed" desc="Methods proxied to block class">
159161
@Override
160162
public Material getMaterial() {
161-
return container.getBlock().getMaterial(this);
163+
return block.getMaterial(this);
162164
}
163165

164166
@Override
165167
public boolean isFullBlock() {
166-
return container.getBlock().isFullBlock(this);
168+
return block.isFullBlock(this);
167169
}
168170

169171
@Override
170172
public boolean canEntitySpawn(Entity entity) {
171-
return container.getBlock().canEntitySpawn(this, entity);
173+
return block.canEntitySpawn(this, entity);
172174
}
173175

174176
@Override
175177
public int getLightOpacity() {
176-
return container.getBlock().getLightOpacity(this);
178+
return block.getLightOpacity(this);
177179
}
178180

179181
@Override
180182
public int getLightValue() {
181-
return container.getBlock().getLightValue(this);
183+
return block.getLightValue(this);
182184
}
183185

184186
@Override
185187
@SideOnly(Side.CLIENT)
186188
public boolean isTranslucent() {
187-
return container.getBlock().isTranslucent(this);
189+
return block.isTranslucent(this);
188190
}
189191

190192
@Override
191193
public boolean useNeighborBrightness() {
192-
return container.getBlock().getUseNeighborBrightness(this);
194+
return block.getUseNeighborBrightness(this);
193195
}
194196

195197
@Override
196198
public MapColor getMapColor(IBlockAccess p_185909_1_, BlockPos p_185909_2_) {
197-
return container.getBlock().getMapColor(this, p_185909_1_, p_185909_2_);
199+
return block.getMapColor(this, p_185909_1_, p_185909_2_);
198200
}
199201

200202
@Override
201203
public IBlockState withRotation(Rotation rot) {
202-
return container.getBlock().withRotation(this, rot);
204+
return block.withRotation(this, rot);
203205
}
204206

205207
@Override
206208
public IBlockState withMirror(Mirror mirror) {
207-
return container.getBlock().withMirror(this, mirror);
209+
return block.withMirror(this, mirror);
208210
}
209211

210212
@Override
211213
public boolean isFullCube() {
212-
return container.getBlock().isFullCube(this);
214+
return block.isFullCube(this);
213215
}
214216

215217
@Override
216218
@SideOnly(Side.CLIENT)
217219
public boolean hasCustomBreakingProgress() {
218-
return container.getBlock().hasCustomBreakingProgress(this);
220+
return block.hasCustomBreakingProgress(this);
219221
}
220222

221223
@Override
222224
public EnumBlockRenderType getRenderType() {
223-
return container.getBlock().getRenderType(this);
225+
return block.getRenderType(this);
224226
}
225227

226228
@Override
227229
@SideOnly(Side.CLIENT)
228230
public int getPackedLightmapCoords(IBlockAccess source, BlockPos pos) {
229-
return container.getBlock().getPackedLightmapCoords(this, source, pos);
231+
return block.getPackedLightmapCoords(this, source, pos);
230232
}
231233

232234
@Override
233235
@SideOnly(Side.CLIENT)
234236
public float getAmbientOcclusionLightValue() {
235-
return container.getBlock().getAmbientOcclusionLightValue(this);
237+
return block.getAmbientOcclusionLightValue(this);
236238
}
237239

238240
@Override
239241
public boolean isBlockNormalCube() {
240-
return container.getBlock().isBlockNormalCube(this);
242+
return block.isBlockNormalCube(this);
241243
}
242244

243245
@Override
244246
public boolean isNormalCube() {
245-
return container.getBlock().isNormalCube(this);
247+
return block.isNormalCube(this);
246248
}
247249

248250
@Override
249251
public boolean canProvidePower() {
250-
return container.getBlock().canProvidePower(this);
252+
return block.canProvidePower(this);
251253
}
252254

253255
@Override
254256
public int getWeakPower(IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
255-
return container.getBlock().getWeakPower(this, blockAccess, pos, side);
257+
return block.getWeakPower(this, blockAccess, pos, side);
256258
}
257259

258260
@Override
259261
public boolean hasComparatorInputOverride() {
260-
return container.getBlock().hasComparatorInputOverride(this);
262+
return block.hasComparatorInputOverride(this);
261263
}
262264

263265
@Override
264266
public int getComparatorInputOverride(World world, BlockPos pos) {
265-
return container.getBlock().getComparatorInputOverride(this, world, pos);
267+
return block.getComparatorInputOverride(this, world, pos);
266268
}
267269

268270
@Override
269271
public float getBlockHardness(World world, BlockPos pos) {
270-
return container.getBlock().getBlockHardness(this, world, pos);
272+
return block.getBlockHardness(this, world, pos);
271273
}
272274

273275
@Override
274276
public float getPlayerRelativeBlockHardness(EntityPlayer player, World world, BlockPos pos) {
275-
return container.getBlock().getPlayerRelativeBlockHardness(this, player, world, pos);
277+
return block.getPlayerRelativeBlockHardness(this, player, world, pos);
276278
}
277279

278280
@Override
279281
public int getStrongPower(IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
280-
return container.getBlock().getStrongPower(this, blockAccess, pos, side);
282+
return block.getStrongPower(this, blockAccess, pos, side);
281283
}
282284

283285
@Override
284286
public EnumPushReaction getMobilityFlag() {
285-
return container.getBlock().getMobilityFlag(this);
287+
return block.getMobilityFlag(this);
286288
}
287289

288290
@Override
289291
public IBlockState getActualState(IBlockAccess blockAccess, BlockPos pos) {
290-
return container.getBlock().getActualState(this, blockAccess, pos);
292+
return block.getActualState(this, blockAccess, pos);
291293
}
292294

293295
@Override
294296
@SideOnly(Side.CLIENT)
295297
public AxisAlignedBB getSelectedBoundingBox(World world, BlockPos pos) {
296-
return container.getBlock().getSelectedBoundingBox(this, world, pos);
298+
return block.getSelectedBoundingBox(this, world, pos);
297299
}
298300

299301
@Override
300302
@SideOnly(Side.CLIENT)
301303
public boolean shouldSideBeRendered(IBlockAccess blockAccess, BlockPos pos, EnumFacing facing) {
302-
return container.getBlock().shouldSideBeRendered(this, blockAccess, pos, facing);
304+
return block.shouldSideBeRendered(this, blockAccess, pos, facing);
303305
}
304306

305307
@Override
306308
public boolean isOpaqueCube() {
307-
return container.getBlock().isOpaqueCube(this);
309+
return block.isOpaqueCube(this);
308310
}
309311

310312
@Override
311313
@Nullable
312314
public AxisAlignedBB getCollisionBoundingBox(IBlockAccess world, BlockPos pos) {
313-
return container.getBlock().getCollisionBoundingBox(this, world, pos);
315+
return block.getCollisionBoundingBox(this, world, pos);
314316
}
315317

316318
@Override
317319
public void addCollisionBoxToList(World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean p_185908_6_) {
318-
container.getBlock().addCollisionBoxToList(this, world, pos, entityBox, collidingBoxes, entity, p_185908_6_);
320+
block.addCollisionBoxToList(this, world, pos, entityBox, collidingBoxes, entity, p_185908_6_);
319321
}
320322

321323
@Override
322324
public AxisAlignedBB getBoundingBox(IBlockAccess blockAccess, BlockPos pos) {
323-
return container.getBlock().getBoundingBox(this, blockAccess, pos);
325+
return block.getBoundingBox(this, blockAccess, pos);
324326
}
325327

326328
@Override
327329
public RayTraceResult collisionRayTrace(World world, BlockPos pos, Vec3d start, Vec3d end) {
328-
return container.getBlock().collisionRayTrace(this, world, pos, start, end);
330+
return block.collisionRayTrace(this, world, pos, start, end);
329331
}
330332

331333
@Override
332334
public boolean isTopSolid() {
333-
return container.getBlock().isTopSolid(this);
335+
return block.isTopSolid(this);
334336
}
335337

336338
@Override
337339
public Vec3d getOffset(IBlockAccess access, BlockPos pos) {
338-
return container.getBlock().getOffset(this, access, pos);
340+
return block.getOffset(this, access, pos);
339341
}
340342

341343
@Override
342344
public boolean onBlockEventReceived(World world, BlockPos pos, int id, int param) {
343-
return container.getBlock().eventReceived(this, world, pos, id, param);
345+
return block.eventReceived(this, world, pos, id, param);
344346
}
345347

346348
@Override
347349
public void neighborChanged(World world, BlockPos pos, Block block, BlockPos fromPos) {
348-
container.getBlock().neighborChanged(this, world, pos, block, fromPos);
350+
this.block.neighborChanged(this, world, pos, block, fromPos);
349351
}
350352

351353
@Override
352354
public boolean causesSuffocation() {
353-
return container.getBlock().causesSuffocation(this);
355+
return block.causesSuffocation(this);
354356
}
355357

356358
@Override
357359
public BlockFaceShape getBlockFaceShape(IBlockAccess world, BlockPos pos, EnumFacing facing) {
358-
return container.getBlock().getBlockFaceShape(world, this, pos, facing);
360+
return block.getBlockFaceShape(world, this, pos, facing);
359361
}
360362

361363
@Override
362364
public int getLightOpacity(IBlockAccess world, BlockPos pos) {
363-
return container.getBlock().getLightOpacity(this, world, pos);
365+
return block.getLightOpacity(this, world, pos);
364366
}
365367

366368
@Override
367369
public int getLightValue(IBlockAccess world, BlockPos pos) {
368-
return container.getBlock().getLightValue(this, world, pos);
370+
return block.getLightValue(this, world, pos);
369371
}
370372

371373
@Override
372374
public boolean isSideSolid(IBlockAccess world, BlockPos pos, EnumFacing side) {
373-
return container.getBlock().isSideSolid(this, world, pos, side);
375+
return block.isSideSolid(this, world, pos, side);
374376
}
375377

376378
@Override
377379
public boolean doesSideBlockChestOpening(IBlockAccess world, BlockPos pos, EnumFacing side) {
378-
return container.getBlock().doesSideBlockChestOpening(this, world, pos, side);
380+
return block.doesSideBlockChestOpening(this, world, pos, side);
379381
}
380382

381383
@Override
382384
public boolean doesSideBlockRendering(IBlockAccess world, BlockPos pos, EnumFacing side) {
383-
return container.getBlock().doesSideBlockRendering(this, world, pos, side);
385+
return block.doesSideBlockRendering(this, world, pos, side);
384386
}
385387
// </editor-fold>
386388
}

0 commit comments

Comments
 (0)