diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java index 44d8d2cd2..becf59d5a 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java @@ -21,8 +21,10 @@ import javax.annotation.Nonnull; public class TurtleCraftingTable extends AbstractTurtleUpgrade { - private static final ModelResourceLocation leftModel = new ModelResourceLocation( "computercraft:turtle_crafting_table_left", "inventory" ); - private static final ModelResourceLocation rightModel = new ModelResourceLocation( "computercraft:turtle_crafting_table_right", "inventory" ); + @Environment( EnvType.CLIENT ) + private ModelResourceLocation leftModel; + @Environment( EnvType.CLIENT ) + private ModelResourceLocation rightModel; public TurtleCraftingTable( ResourceLocation id, ItemStack stack ) { @@ -40,6 +42,17 @@ public class TurtleCraftingTable extends AbstractTurtleUpgrade @Environment( EnvType.CLIENT ) public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) { + loadModelLocations(); return TransformedModel.of( side == TurtleSide.LEFT ? leftModel : rightModel ); } + + @Environment( EnvType.CLIENT ) + private void loadModelLocations() + { + if( leftModel == null ) + { + leftModel = new ModelResourceLocation( "computercraft:turtle_crafting_table_left", "inventory" ); + rightModel = new ModelResourceLocation( "computercraft:turtle_crafting_table_right", "inventory" ); + } + } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java index ad12ef00e..85a074132 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java @@ -63,30 +63,19 @@ public class TurtleModem extends AbstractTurtleUpgrade private final boolean advanced; - private final ModelResourceLocation leftOffModel; - private final ModelResourceLocation rightOffModel; - private final ModelResourceLocation leftOnModel; - private final ModelResourceLocation rightOnModel; + @Environment( EnvType.CLIENT ) + private ModelResourceLocation leftOffModel; + @Environment( EnvType.CLIENT ) + private ModelResourceLocation rightOffModel; + @Environment( EnvType.CLIENT ) + private ModelResourceLocation leftOnModel; + @Environment( EnvType.CLIENT ) + private ModelResourceLocation rightOnModel; public TurtleModem( ResourceLocation id, ItemStack stack, boolean advanced ) { super( id, TurtleUpgradeType.PERIPHERAL, advanced ? WirelessModemPeripheral.ADVANCED_ADJECTIVE : WirelessModemPeripheral.NORMAL_ADJECTIVE, stack ); this.advanced = advanced; - - if( advanced ) - { - leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_left", "inventory" ); - rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_right", "inventory" ); - leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_left", "inventory" ); - rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_right", "inventory" ); - } - else - { - leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_left", "inventory" ); - rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_right", "inventory" ); - leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_left", "inventory" ); - rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_right", "inventory" ); - } } @Override @@ -107,6 +96,8 @@ public class TurtleModem extends AbstractTurtleUpgrade @Environment( EnvType.CLIENT ) public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) { + loadModelLocations(); + boolean active = false; if( turtle != null ) { @@ -119,6 +110,30 @@ public class TurtleModem extends AbstractTurtleUpgrade : TransformedModel.of( active ? rightOnModel : rightOffModel ); } + // This exists separate from the constructor because we can't use the class ModelResourceLocation on the dedicated + // server. + @Environment( EnvType.CLIENT ) + private void loadModelLocations() + { + if( leftOffModel == null ) + { + if( advanced ) + { + leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_left", "inventory" ); + rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_right", "inventory" ); + leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_left", "inventory" ); + rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_right", "inventory" ); + } + else + { + leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_left", "inventory" ); + rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_right", "inventory" ); + leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_left", "inventory" ); + rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_right", "inventory" ); + } + } + } + @Override public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSpeaker.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSpeaker.java index aea0ddf67..6d532e1ec 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSpeaker.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSpeaker.java @@ -25,8 +25,10 @@ import javax.annotation.Nonnull; public class TurtleSpeaker extends AbstractTurtleUpgrade { - private static final ModelResourceLocation leftModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_left", "inventory" ); - private static final ModelResourceLocation rightModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_right", "inventory" ); + @Environment( EnvType.CLIENT ) + private ModelResourceLocation leftModel; + @Environment( EnvType.CLIENT ) + private ModelResourceLocation rightModel; private static class Peripheral extends UpgradeSpeakerPeripheral { @@ -73,9 +75,20 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade @Environment( EnvType.CLIENT ) public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) { + loadModelLocations(); return TransformedModel.of( side == TurtleSide.LEFT ? leftModel : rightModel ); } + @Environment( EnvType.CLIENT ) + private void loadModelLocations() + { + if( leftModel == null ) + { + leftModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_left", "inventory" ); + rightModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_right", "inventory" ); + } + } + @Override public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide turtleSide ) {