1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-24 18:37:38 +00:00

Auto-generate monitor models

I didn't think it was worth it, and then I found myself needing to
update a dozen of them. The code isn't especially pretty, but it works,
so that's fine.

Also fixes several issues with us using the wrong texture (closes #572).
I've put together a wiki page[1] which describes each texture in a
little more detail.

[1] https://github.com/SquidDev-CC/CC-Tweaked/wiki/Monitor-texture-reference
This commit is contained in:
SquidDev
2020-11-11 21:14:50 +00:00
parent 74ac5bb3d1
commit c8aeddedd4
71 changed files with 2109 additions and 940 deletions

View File

@@ -0,0 +1,109 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.data;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.Registry;
import dan200.computercraft.shared.peripheral.monitor.BlockMonitor;
import dan200.computercraft.shared.peripheral.monitor.MonitorEdgeState;
import net.minecraft.block.Block;
import net.minecraft.data.DataGenerator;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.generators.*;
import javax.annotation.Nonnull;
public class BlockModelProvider extends BlockStateProvider
{
private final ModelFile root;
public BlockModelProvider( DataGenerator generator, ExistingFileHelper existingFileHelper )
{
super( generator, ComputerCraft.MOD_ID, existingFileHelper );
root = models().getExistingFile( new ResourceLocation( ComputerCraft.MOD_ID, "block/monitor_base" ) );
}
@Nonnull
@Override
public String getName()
{
return "Block states and models";
}
@Override
protected void registerStatesAndModels()
{
registerMonitors( Registry.ModBlocks.MONITOR_NORMAL.get() );
registerMonitors( Registry.ModBlocks.MONITOR_ADVANCED.get() );
}
private void registerMonitors( Block block )
{
String name = block.getRegistryName().getPath();
registerMonitorModel( name, "", 16, 4, 0, 32 );
registerMonitorModel( name, "_d", 20, 7, 0, 36 );
registerMonitorModel( name, "_l", 19, 4, 1, 33 );
registerMonitorModel( name, "_ld", 31, 7, 1, 45 );
registerMonitorModel( name, "_lr", 18, 4, 2, 34 );
registerMonitorModel( name, "_lrd", 30, 7, 2, 46 );
registerMonitorModel( name, "_lru", 24, 5, 2, 40 );
registerMonitorModel( name, "_lrud", 27, 6, 2, 43 );
registerMonitorModel( name, "_lu", 25, 5, 1, 39 );
registerMonitorModel( name, "_lud", 28, 6, 1, 42 );
registerMonitorModel( name, "_r", 17, 4, 3, 35 );
registerMonitorModel( name, "_rd", 29, 7, 3, 47 );
registerMonitorModel( name, "_ru", 23, 5, 3, 41 );
registerMonitorModel( name, "_rud", 26, 6, 3, 44 );
registerMonitorModel( name, "_u", 22, 5, 0, 38 );
registerMonitorModel( name, "_ud", 21, 6, 0, 37 );
VariantBlockStateBuilder builder = getVariantBuilder( block );
for( MonitorEdgeState edge : BlockMonitor.STATE.getAllowedValues() )
{
String suffix = edge == MonitorEdgeState.NONE ? "" : "_" + edge.getName();
ResourceLocation modelName = new ResourceLocation( ComputerCraft.MOD_ID, "block/" + name + suffix );
ModelFile model = models().getBuilder( modelName.toString() );
for( Direction facing : BlockMonitor.FACING.getAllowedValues() )
{
for( Direction orientation : BlockMonitor.ORIENTATION.getAllowedValues() )
{
builder.partialState()
.with( BlockMonitor.STATE, edge )
.with( BlockMonitor.FACING, facing )
.with( BlockMonitor.ORIENTATION, orientation )
.addModels( new ConfiguredModel( model, toXAngle( orientation ), 180 - (int) facing.getHorizontalAngle(), false ) );
}
}
}
}
private void registerMonitorModel( String prefix, String corners, int front, int side, int top, int back )
{
String texturePrefix = ComputerCraft.MOD_ID + ":block/" + prefix + "_";
models().getBuilder( prefix + corners )
.parent( root )
.texture( "front", texturePrefix + front )
.texture( "side", texturePrefix + side )
.texture( "top", texturePrefix + top )
.texture( "back", texturePrefix + back );
}
private int toXAngle( Direction direction )
{
switch( direction )
{
default:
return 0;
case UP:
return 270;
case DOWN:
return 90;
}
}
}

View File

@@ -24,5 +24,6 @@ public class Generators
generator.addProvider( new Recipes( generator ) );
generator.addProvider( new LootTables( generator ) );
generator.addProvider( new Tags( generator ) );
generator.addProvider( new BlockModelProvider( generator, event.getExistingFileHelper() ) );
}
}

View File

@@ -32,7 +32,7 @@ public class BlockMonitor extends BlockGeneric
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
static final EnumProperty<MonitorEdgeState> STATE = EnumProperty.create( "state", MonitorEdgeState.class );
public static final EnumProperty<MonitorEdgeState> STATE = EnumProperty.create( "state", MonitorEdgeState.class );
public BlockMonitor( Properties settings, RegistryObject<? extends TileEntityType<? extends TileMonitor>> type )
{

View File

@@ -57,6 +57,12 @@ public enum MonitorEdgeState implements IStringSerializable
return BY_FLAG[(up ? UP : 0) | (down ? DOWN : 0) | (left ? LEFT : 0) | (right ? RIGHT : 0)];
}
@Override
public String toString()
{
return getName();
}
@Nonnull
@Override
public String getName()