1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-30 17:17:55 +00:00

Use inner/nested classes to shield ModelResourceLocation from server.

Just cleaner then the old apoach. Thanks @SquidDev for the suggestion.
This commit is contained in:
Toad-Dev
2021-12-17 16:01:21 -08:00
parent d9777a8d2f
commit 9f337c2d1c
3 changed files with 37 additions and 64 deletions

View File

@@ -22,9 +22,11 @@ import javax.annotation.Nonnull;
public class TurtleCraftingTable extends AbstractTurtleUpgrade
{
@Environment( EnvType.CLIENT )
private ModelResourceLocation leftModel;
@Environment( EnvType.CLIENT )
private ModelResourceLocation rightModel;
private static class Models
{
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" );
}
public TurtleCraftingTable( ResourceLocation id, ItemStack stack )
{
@@ -42,17 +44,6 @@ 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" );
}
return TransformedModel.of( side == TurtleSide.LEFT ? Models.leftModel : Models.rightModel );
}
}

View File

@@ -61,16 +61,30 @@ public class TurtleModem extends AbstractTurtleUpgrade
}
}
@Environment( EnvType.CLIENT )
private class Models
{
private final ModelResourceLocation leftOffModel = advanced ?
new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_left", "inventory" ) :
new ModelResourceLocation( "computercraft:turtle_modem_normal_off_left", "inventory" );
private final ModelResourceLocation rightOffModel = advanced ?
new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_right", "inventory" ) :
new ModelResourceLocation( "computercraft:turtle_modem_normal_off_right", "inventory" );
private final ModelResourceLocation leftOnModel = advanced ?
new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_left", "inventory" ) :
new ModelResourceLocation( "computercraft:turtle_modem_normal_on_left", "inventory" );
private final ModelResourceLocation rightOnModel = advanced ?
new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_right", "inventory" ) :
new ModelResourceLocation( "computercraft:turtle_modem_normal_on_right", "inventory" );
}
private final boolean advanced;
@Environment( EnvType.CLIENT )
private ModelResourceLocation leftOffModel;
@Environment( EnvType.CLIENT )
private ModelResourceLocation rightOffModel;
@Environment( EnvType.CLIENT )
private ModelResourceLocation leftOnModel;
@Environment( EnvType.CLIENT )
private ModelResourceLocation rightOnModel;
private Models models;
public TurtleModem( ResourceLocation id, ItemStack stack, boolean advanced )
{
@@ -96,7 +110,7 @@ public class TurtleModem extends AbstractTurtleUpgrade
@Environment( EnvType.CLIENT )
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{
loadModelLocations();
if( models == null ) models = new Models();
boolean active = false;
if( turtle != null )
@@ -106,32 +120,8 @@ public class TurtleModem extends AbstractTurtleUpgrade
}
return side == TurtleSide.LEFT
? TransformedModel.of( active ? leftOnModel : leftOffModel )
: 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" );
}
}
? TransformedModel.of( active ? models.leftOnModel : models.leftOffModel )
: TransformedModel.of( active ? models.rightOnModel : models.rightOffModel );
}
@Override

View File

@@ -26,9 +26,11 @@ import javax.annotation.Nonnull;
public class TurtleSpeaker extends AbstractTurtleUpgrade
{
@Environment( EnvType.CLIENT )
private ModelResourceLocation leftModel;
@Environment( EnvType.CLIENT )
private ModelResourceLocation rightModel;
private static class Models
{
private static ModelResourceLocation leftModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_left", "inventory" );
private static ModelResourceLocation rightModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_right", "inventory" );
}
private static class Peripheral extends UpgradeSpeakerPeripheral
{
@@ -45,6 +47,7 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade
return turtle.getLevel();
}
@Nonnull
@Override
public Vec3 getPosition()
{
@@ -75,18 +78,7 @@ 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" );
}
return TransformedModel.of( side == TurtleSide.LEFT ? Models.leftModel : Models.rightModel );
}
@Override