1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-16 18:19:55 +00:00

Switch to vanilla's model data generators

In some ways this isn't as nice as the Forge version (requires ATs,
doesn't check texture/model existence). However, it's more multi-loader
friendly and in some cases has much less boilerplate.

Blockstate JSON files are incredibly verbose, so we add a custom JSON
pretty printer which writes things in a slightly more compact manner.

This also changes how turtle upgrades are loaded - we now support
standard ResourceLocations (so computercraft:blocks/some_turtle_upgrade)
as well as ModelResourceLocations (computercraft:items/some_turtle_upgrade#inventory).
I don't think any resource packs need to touch our upgrades, but
apologies if this breaks anything.
This commit is contained in:
Jonathan Coates 2022-10-22 11:55:30 +01:00
parent ff89e5feeb
commit 0c3de1087e
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
144 changed files with 2095 additions and 2970 deletions

View File

@ -72,6 +72,7 @@
data {
workingDirectory project.file('run')
args '--mod', 'computercraft', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
property("cct.pretty-json", "true")
}
testClient {

View File

@ -0,0 +1,125 @@
{
"multipart": [
{
"when": {
"OR": [
{"east": "false", "north": "false", "south": "false", "cable": "true", "up": "true", "west": "false"},
{"down": "true", "east": "false", "north": "false", "south": "false", "cable": "true", "west": "false"}
]
},
"apply": {"model": "computercraft:block/cable_core_facing", "x": 90}
},
{
"when": {
"OR": [
{
"down": "false",
"east": "false",
"north": "false",
"south": "false",
"cable": "true",
"up": "false",
"west": "false"
},
{"down": "false", "east": "false", "north": "true", "cable": "true", "up": "false", "west": "false"},
{"down": "false", "east": "false", "south": "true", "cable": "true", "up": "false", "west": "false"}
]
},
"apply": {"model": "computercraft:block/cable_core_facing", "y": 0}
},
{
"when": {
"OR": [
{"down": "false", "east": "true", "north": "false", "south": "false", "cable": "true", "up": "false"},
{"down": "false", "north": "false", "south": "false", "cable": "true", "up": "false", "west": "true"}
]
},
"apply": {"model": "computercraft:block/cable_core_facing", "y": 90}
},
{
"when": {
"OR": [
{"down": "true", "north": "true", "cable": "true"},
{"down": "true", "south": "true", "cable": "true"},
{"down": "true", "cable": "true", "west": "true"},
{"down": "true", "east": "true", "cable": "true"},
{"north": "true", "cable": "true", "up": "true"},
{"south": "true", "cable": "true", "up": "true"},
{"cable": "true", "up": "true", "west": "true"},
{"east": "true", "cable": "true", "up": "true"},
{"north": "true", "cable": "true", "west": "true"},
{"east": "true", "north": "true", "cable": "true"},
{"south": "true", "cable": "true", "west": "true"},
{"east": "true", "south": "true", "cable": "true"}
]
},
"apply": {"model": "computercraft:block/cable_core_any"}
},
{"when": {"down": "true"}, "apply": {"model": "computercraft:block/cable_arm", "x": 270, "y": 0}},
{"when": {"up": "true"}, "apply": {"model": "computercraft:block/cable_arm", "x": 90, "y": 0}},
{"when": {"north": "true"}, "apply": {"model": "computercraft:block/cable_arm", "x": 0, "y": 180}},
{"when": {"south": "true"}, "apply": {"model": "computercraft:block/cable_arm", "x": 0, "y": 0}},
{"when": {"west": "true"}, "apply": {"model": "computercraft:block/cable_arm", "x": 0, "y": 90}},
{"when": {"east": "true"}, "apply": {"model": "computercraft:block/cable_arm", "x": 0, "y": 270}},
{"when": {"modem": "down_off"}, "apply": {"model": "computercraft:block/wired_modem_off", "x": 90, "y": 0}},
{
"when": {"modem": "down_off_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_off_peripheral", "x": 90, "y": 0}
},
{"when": {"modem": "down_on"}, "apply": {"model": "computercraft:block/wired_modem_on", "x": 90, "y": 0}},
{
"when": {"modem": "down_on_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_on_peripheral", "x": 90, "y": 0}
},
{"when": {"modem": "up_off"}, "apply": {"model": "computercraft:block/wired_modem_off", "x": 270, "y": 0}},
{
"when": {"modem": "up_off_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_off_peripheral", "x": 270, "y": 0}
},
{"when": {"modem": "up_on"}, "apply": {"model": "computercraft:block/wired_modem_on", "x": 270, "y": 0}},
{
"when": {"modem": "up_on_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_on_peripheral", "x": 270, "y": 0}
},
{"when": {"modem": "north_off"}, "apply": {"model": "computercraft:block/wired_modem_off", "x": 0, "y": 0}},
{
"when": {"modem": "north_off_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_off_peripheral", "x": 0, "y": 0}
},
{"when": {"modem": "north_on"}, "apply": {"model": "computercraft:block/wired_modem_on", "x": 0, "y": 0}},
{
"when": {"modem": "north_on_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_on_peripheral", "x": 0, "y": 0}
},
{"when": {"modem": "south_off"}, "apply": {"model": "computercraft:block/wired_modem_off", "x": 0, "y": 180}},
{
"when": {"modem": "south_off_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_off_peripheral", "x": 0, "y": 180}
},
{"when": {"modem": "south_on"}, "apply": {"model": "computercraft:block/wired_modem_on", "x": 0, "y": 180}},
{
"when": {"modem": "south_on_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_on_peripheral", "x": 0, "y": 180}
},
{"when": {"modem": "west_off"}, "apply": {"model": "computercraft:block/wired_modem_off", "x": 0, "y": 270}},
{
"when": {"modem": "west_off_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_off_peripheral", "x": 0, "y": 270}
},
{"when": {"modem": "west_on"}, "apply": {"model": "computercraft:block/wired_modem_on", "x": 0, "y": 270}},
{
"when": {"modem": "west_on_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_on_peripheral", "x": 0, "y": 270}
},
{"when": {"modem": "east_off"}, "apply": {"model": "computercraft:block/wired_modem_off", "x": 0, "y": 90}},
{
"when": {"modem": "east_off_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_off_peripheral", "x": 0, "y": 90}
},
{"when": {"modem": "east_on"}, "apply": {"model": "computercraft:block/wired_modem_on", "x": 0, "y": 90}},
{
"when": {"modem": "east_on_peripheral"},
"apply": {"model": "computercraft:block/wired_modem_on_peripheral", "x": 0, "y": 90}
}
]
}

View File

@ -1,49 +1,16 @@
{
"variants": {
"facing=north,state=off": {
"model": "computercraft:block/computer_advanced_off"
},
"facing=south,state=off": {
"model": "computercraft:block/computer_advanced_off",
"y": 180
},
"facing=west,state=off": {
"model": "computercraft:block/computer_advanced_off",
"y": 270
},
"facing=east,state=off": {
"model": "computercraft:block/computer_advanced_off",
"y": 90
},
"facing=north,state=on": {
"model": "computercraft:block/computer_advanced_on"
},
"facing=south,state=on": {
"model": "computercraft:block/computer_advanced_on",
"y": 180
},
"facing=west,state=on": {
"model": "computercraft:block/computer_advanced_on",
"y": 270
},
"facing=east,state=on": {
"model": "computercraft:block/computer_advanced_on",
"y": 90
},
"facing=north,state=blinking": {
"model": "computercraft:block/computer_advanced_blinking"
},
"facing=south,state=blinking": {
"model": "computercraft:block/computer_advanced_blinking",
"y": 180
},
"facing=west,state=blinking": {
"model": "computercraft:block/computer_advanced_blinking",
"y": 270
},
"facing=east,state=blinking": {
"model": "computercraft:block/computer_advanced_blinking",
"y": 90
}
"facing=east,state=blinking": {"y": 90, "model": "computercraft:block/computer_advanced_blinking"},
"facing=east,state=off": {"y": 90, "model": "computercraft:block/computer_advanced_off"},
"facing=east,state=on": {"y": 90, "model": "computercraft:block/computer_advanced_on"},
"facing=north,state=blinking": {"y": 0, "model": "computercraft:block/computer_advanced_blinking"},
"facing=north,state=off": {"y": 0, "model": "computercraft:block/computer_advanced_off"},
"facing=north,state=on": {"y": 0, "model": "computercraft:block/computer_advanced_on"},
"facing=south,state=blinking": {"y": 180, "model": "computercraft:block/computer_advanced_blinking"},
"facing=south,state=off": {"y": 180, "model": "computercraft:block/computer_advanced_off"},
"facing=south,state=on": {"y": 180, "model": "computercraft:block/computer_advanced_on"},
"facing=west,state=blinking": {"y": 270, "model": "computercraft:block/computer_advanced_blinking"},
"facing=west,state=off": {"y": 270, "model": "computercraft:block/computer_advanced_off"},
"facing=west,state=on": {"y": 270, "model": "computercraft:block/computer_advanced_on"}
}
}

View File

@ -1,49 +1,16 @@
{
"variants": {
"facing=north,state=off": {
"model": "computercraft:block/computer_command_off"
},
"facing=south,state=off": {
"model": "computercraft:block/computer_command_off",
"y": 180
},
"facing=west,state=off": {
"model": "computercraft:block/computer_command_off",
"y": 270
},
"facing=east,state=off": {
"model": "computercraft:block/computer_command_off",
"y": 90
},
"facing=north,state=on": {
"model": "computercraft:block/computer_command_on"
},
"facing=south,state=on": {
"model": "computercraft:block/computer_command_on",
"y": 180
},
"facing=west,state=on": {
"model": "computercraft:block/computer_command_on",
"y": 270
},
"facing=east,state=on": {
"model": "computercraft:block/computer_command_on",
"y": 90
},
"facing=north,state=blinking": {
"model": "computercraft:block/computer_command_blinking"
},
"facing=south,state=blinking": {
"model": "computercraft:block/computer_command_blinking",
"y": 180
},
"facing=west,state=blinking": {
"model": "computercraft:block/computer_command_blinking",
"y": 270
},
"facing=east,state=blinking": {
"model": "computercraft:block/computer_command_blinking",
"y": 90
}
"facing=east,state=blinking": {"y": 90, "model": "computercraft:block/computer_command_blinking"},
"facing=east,state=off": {"y": 90, "model": "computercraft:block/computer_command_off"},
"facing=east,state=on": {"y": 90, "model": "computercraft:block/computer_command_on"},
"facing=north,state=blinking": {"y": 0, "model": "computercraft:block/computer_command_blinking"},
"facing=north,state=off": {"y": 0, "model": "computercraft:block/computer_command_off"},
"facing=north,state=on": {"y": 0, "model": "computercraft:block/computer_command_on"},
"facing=south,state=blinking": {"y": 180, "model": "computercraft:block/computer_command_blinking"},
"facing=south,state=off": {"y": 180, "model": "computercraft:block/computer_command_off"},
"facing=south,state=on": {"y": 180, "model": "computercraft:block/computer_command_on"},
"facing=west,state=blinking": {"y": 270, "model": "computercraft:block/computer_command_blinking"},
"facing=west,state=off": {"y": 270, "model": "computercraft:block/computer_command_off"},
"facing=west,state=on": {"y": 270, "model": "computercraft:block/computer_command_on"}
}
}

View File

@ -1,49 +1,16 @@
{
"variants": {
"facing=north,state=off": {
"model": "computercraft:block/computer_normal_off"
},
"facing=south,state=off": {
"model": "computercraft:block/computer_normal_off",
"y": 180
},
"facing=west,state=off": {
"model": "computercraft:block/computer_normal_off",
"y": 270
},
"facing=east,state=off": {
"model": "computercraft:block/computer_normal_off",
"y": 90
},
"facing=north,state=on": {
"model": "computercraft:block/computer_normal_on"
},
"facing=south,state=on": {
"model": "computercraft:block/computer_normal_on",
"y": 180
},
"facing=west,state=on": {
"model": "computercraft:block/computer_normal_on",
"y": 270
},
"facing=east,state=on": {
"model": "computercraft:block/computer_normal_on",
"y": 90
},
"facing=north,state=blinking": {
"model": "computercraft:block/computer_normal_blinking"
},
"facing=south,state=blinking": {
"model": "computercraft:block/computer_normal_blinking",
"y": 180
},
"facing=west,state=blinking": {
"model": "computercraft:block/computer_normal_blinking",
"y": 270
},
"facing=east,state=blinking": {
"model": "computercraft:block/computer_normal_blinking",
"y": 90
}
"facing=east,state=blinking": {"y": 90, "model": "computercraft:block/computer_normal_blinking"},
"facing=east,state=off": {"y": 90, "model": "computercraft:block/computer_normal_off"},
"facing=east,state=on": {"y": 90, "model": "computercraft:block/computer_normal_on"},
"facing=north,state=blinking": {"y": 0, "model": "computercraft:block/computer_normal_blinking"},
"facing=north,state=off": {"y": 0, "model": "computercraft:block/computer_normal_off"},
"facing=north,state=on": {"y": 0, "model": "computercraft:block/computer_normal_on"},
"facing=south,state=blinking": {"y": 180, "model": "computercraft:block/computer_normal_blinking"},
"facing=south,state=off": {"y": 180, "model": "computercraft:block/computer_normal_off"},
"facing=south,state=on": {"y": 180, "model": "computercraft:block/computer_normal_on"},
"facing=west,state=blinking": {"y": 270, "model": "computercraft:block/computer_normal_blinking"},
"facing=west,state=off": {"y": 270, "model": "computercraft:block/computer_normal_off"},
"facing=west,state=on": {"y": 270, "model": "computercraft:block/computer_normal_on"}
}
}

View File

@ -0,0 +1,16 @@
{
"variants": {
"facing=east,state=empty": {"y": 90, "model": "computercraft:block/disk_drive_empty"},
"facing=east,state=full": {"y": 90, "model": "computercraft:block/disk_drive_full"},
"facing=east,state=invalid": {"y": 90, "model": "computercraft:block/disk_drive_invalid"},
"facing=north,state=empty": {"y": 0, "model": "computercraft:block/disk_drive_empty"},
"facing=north,state=full": {"y": 0, "model": "computercraft:block/disk_drive_full"},
"facing=north,state=invalid": {"y": 0, "model": "computercraft:block/disk_drive_invalid"},
"facing=south,state=empty": {"y": 180, "model": "computercraft:block/disk_drive_empty"},
"facing=south,state=full": {"y": 180, "model": "computercraft:block/disk_drive_full"},
"facing=south,state=invalid": {"y": 180, "model": "computercraft:block/disk_drive_invalid"},
"facing=west,state=empty": {"y": 270, "model": "computercraft:block/disk_drive_empty"},
"facing=west,state=full": {"y": 270, "model": "computercraft:block/disk_drive_full"},
"facing=west,state=invalid": {"y": 270, "model": "computercraft:block/disk_drive_invalid"}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,20 @@
{
"variants": {
"bottom=false,facing=east,top=false": {"y": 90, "model": "computercraft:block/printer_empty"},
"bottom=false,facing=east,top=true": {"y": 90, "model": "computercraft:block/printer_top_full"},
"bottom=false,facing=north,top=false": {"y": 0, "model": "computercraft:block/printer_empty"},
"bottom=false,facing=north,top=true": {"y": 0, "model": "computercraft:block/printer_top_full"},
"bottom=false,facing=south,top=false": {"y": 180, "model": "computercraft:block/printer_empty"},
"bottom=false,facing=south,top=true": {"y": 180, "model": "computercraft:block/printer_top_full"},
"bottom=false,facing=west,top=false": {"y": 270, "model": "computercraft:block/printer_empty"},
"bottom=false,facing=west,top=true": {"y": 270, "model": "computercraft:block/printer_top_full"},
"bottom=true,facing=east,top=false": {"y": 90, "model": "computercraft:block/printer_bottom_full"},
"bottom=true,facing=east,top=true": {"y": 90, "model": "computercraft:block/printer_both_full"},
"bottom=true,facing=north,top=false": {"y": 0, "model": "computercraft:block/printer_bottom_full"},
"bottom=true,facing=north,top=true": {"y": 0, "model": "computercraft:block/printer_both_full"},
"bottom=true,facing=south,top=false": {"y": 180, "model": "computercraft:block/printer_bottom_full"},
"bottom=true,facing=south,top=true": {"y": 180, "model": "computercraft:block/printer_both_full"},
"bottom=true,facing=west,top=false": {"y": 270, "model": "computercraft:block/printer_bottom_full"},
"bottom=true,facing=west,top=true": {"y": 270, "model": "computercraft:block/printer_both_full"}
}
}

View File

@ -1,19 +1,8 @@
{
"variants": {
"facing=north": {
"model": "computercraft:block/speaker"
},
"facing=south": {
"model": "computercraft:block/speaker",
"y": 180
},
"facing=west": {
"model": "computercraft:block/speaker",
"y": 270
},
"facing=east": {
"model": "computercraft:block/speaker",
"y": 90
}
"facing=east": {"model": "computercraft:block/speaker", "y": 90},
"facing=north": {"model": "computercraft:block/speaker"},
"facing=south": {"model": "computercraft:block/speaker", "y": 180},
"facing=west": {"model": "computercraft:block/speaker", "y": 270}
}
}

View File

@ -1,19 +1,8 @@
{
"variants": {
"facing=north": {
"model": "computercraft:block/turtle_advanced"
},
"facing=south": {
"model": "computercraft:block/turtle_advanced",
"y": 180
},
"facing=west": {
"model": "computercraft:block/turtle_advanced",
"y": 270
},
"facing=east": {
"model": "computercraft:block/turtle_advanced",
"y": 90
}
"facing=east": {"model": "computercraft:block/turtle_advanced", "y": 90},
"facing=north": {"model": "computercraft:block/turtle_advanced", "y": 0},
"facing=south": {"model": "computercraft:block/turtle_advanced", "y": 180},
"facing=west": {"model": "computercraft:block/turtle_advanced", "y": 270}
}
}

View File

@ -1,19 +1,8 @@
{
"variants": {
"facing=north": {
"model": "computercraft:block/turtle_normal"
},
"facing=south": {
"model": "computercraft:block/turtle_normal",
"y": 180
},
"facing=west": {
"model": "computercraft:block/turtle_normal",
"y": 270
},
"facing=east": {
"model": "computercraft:block/turtle_normal",
"y": 90
}
"facing=east": {"model": "computercraft:block/turtle_normal", "y": 90},
"facing=north": {"model": "computercraft:block/turtle_normal", "y": 0},
"facing=south": {"model": "computercraft:block/turtle_normal", "y": 180},
"facing=west": {"model": "computercraft:block/turtle_normal", "y": 270}
}
}

View File

@ -1,16 +1,8 @@
{
"variants": {
"modem=false,peripheral=false": {
"model": "computercraft:block/wired_modem_full_off"
},
"modem=true,peripheral=false": {
"model": "computercraft:block/wired_modem_full_on"
},
"modem=false,peripheral=true": {
"model": "computercraft:block/wired_modem_full_off_peripheral"
},
"modem=true,peripheral=true": {
"model": "computercraft:block/wired_modem_full_on_peripheral"
}
"modem=false,peripheral=false": {"model": "computercraft:block/wired_modem_full_off"},
"modem=false,peripheral=true": {"model": "computercraft:block/wired_modem_full_off_peripheral"},
"modem=true,peripheral=false": {"model": "computercraft:block/wired_modem_full_on"},
"modem=true,peripheral=true": {"model": "computercraft:block/wired_modem_full_on_peripheral"}
}
}

View File

@ -1,54 +1,16 @@
{
"variants": {
"facing=down,on=false": {
"model": "computercraft:block/wireless_modem_advanced_off",
"x": 90,
"y": 90
},
"facing=up,on=false": {
"model": "computercraft:block/wireless_modem_advanced_off",
"x": 270,
"y": 90
},
"facing=north,on=false": {
"model": "computercraft:block/wireless_modem_advanced_off"
},
"facing=south,on=false": {
"model": "computercraft:block/wireless_modem_advanced_off",
"y": 180
},
"facing=west,on=false": {
"model": "computercraft:block/wireless_modem_advanced_off",
"y": 270
},
"facing=east,on=false": {
"model": "computercraft:block/wireless_modem_advanced_off",
"y": 90
},
"facing=down,on=true": {
"model": "computercraft:block/wireless_modem_advanced_on",
"x": 90,
"y": 90
},
"facing=up,on=true": {
"model": "computercraft:block/wireless_modem_advanced_on",
"x": 270,
"y": 90
},
"facing=north,on=true": {
"model": "computercraft:block/wireless_modem_advanced_on"
},
"facing=south,on=true": {
"model": "computercraft:block/wireless_modem_advanced_on",
"y": 180
},
"facing=west,on=true": {
"model": "computercraft:block/wireless_modem_advanced_on",
"y": 270
},
"facing=east,on=true": {
"model": "computercraft:block/wireless_modem_advanced_on",
"y": 90
}
"facing=down,on=false": {"y": 0, "x": 90, "model": "computercraft:block/wireless_modem_advanced_off"},
"facing=down,on=true": {"y": 0, "x": 90, "model": "computercraft:block/wireless_modem_advanced_on"},
"facing=east,on=false": {"y": 90, "x": 0, "model": "computercraft:block/wireless_modem_advanced_off"},
"facing=east,on=true": {"y": 90, "x": 0, "model": "computercraft:block/wireless_modem_advanced_on"},
"facing=north,on=false": {"y": 0, "x": 0, "model": "computercraft:block/wireless_modem_advanced_off"},
"facing=north,on=true": {"y": 0, "x": 0, "model": "computercraft:block/wireless_modem_advanced_on"},
"facing=south,on=false": {"y": 180, "x": 0, "model": "computercraft:block/wireless_modem_advanced_off"},
"facing=south,on=true": {"y": 180, "x": 0, "model": "computercraft:block/wireless_modem_advanced_on"},
"facing=up,on=false": {"y": 0, "x": 270, "model": "computercraft:block/wireless_modem_advanced_off"},
"facing=up,on=true": {"y": 0, "x": 270, "model": "computercraft:block/wireless_modem_advanced_on"},
"facing=west,on=false": {"y": 270, "x": 0, "model": "computercraft:block/wireless_modem_advanced_off"},
"facing=west,on=true": {"y": 270, "x": 0, "model": "computercraft:block/wireless_modem_advanced_on"}
}
}

View File

@ -1,54 +1,16 @@
{
"variants": {
"facing=down,on=false": {
"model": "computercraft:block/wireless_modem_normal_off",
"x": 90,
"y": 90
},
"facing=up,on=false": {
"model": "computercraft:block/wireless_modem_normal_off",
"x": 270,
"y": 90
},
"facing=north,on=false": {
"model": "computercraft:block/wireless_modem_normal_off"
},
"facing=south,on=false": {
"model": "computercraft:block/wireless_modem_normal_off",
"y": 180
},
"facing=west,on=false": {
"model": "computercraft:block/wireless_modem_normal_off",
"y": 270
},
"facing=east,on=false": {
"model": "computercraft:block/wireless_modem_normal_off",
"y": 90
},
"facing=down,on=true": {
"model": "computercraft:block/wireless_modem_normal_on",
"x": 90,
"y": 90
},
"facing=up,on=true": {
"model": "computercraft:block/wireless_modem_normal_on",
"x": 270,
"y": 90
},
"facing=north,on=true": {
"model": "computercraft:block/wireless_modem_normal_on"
},
"facing=south,on=true": {
"model": "computercraft:block/wireless_modem_normal_on",
"y": 180
},
"facing=west,on=true": {
"model": "computercraft:block/wireless_modem_normal_on",
"y": 270
},
"facing=east,on=true": {
"model": "computercraft:block/wireless_modem_normal_on",
"y": 90
}
"facing=down,on=false": {"y": 0, "x": 90, "model": "computercraft:block/wireless_modem_normal_off"},
"facing=down,on=true": {"y": 0, "x": 90, "model": "computercraft:block/wireless_modem_normal_on"},
"facing=east,on=false": {"y": 90, "x": 0, "model": "computercraft:block/wireless_modem_normal_off"},
"facing=east,on=true": {"y": 90, "x": 0, "model": "computercraft:block/wireless_modem_normal_on"},
"facing=north,on=false": {"y": 0, "x": 0, "model": "computercraft:block/wireless_modem_normal_off"},
"facing=north,on=true": {"y": 0, "x": 0, "model": "computercraft:block/wireless_modem_normal_on"},
"facing=south,on=false": {"y": 180, "x": 0, "model": "computercraft:block/wireless_modem_normal_off"},
"facing=south,on=true": {"y": 180, "x": 0, "model": "computercraft:block/wireless_modem_normal_on"},
"facing=up,on=false": {"y": 0, "x": 270, "model": "computercraft:block/wireless_modem_normal_off"},
"facing=up,on=true": {"y": 0, "x": 270, "model": "computercraft:block/wireless_modem_normal_on"},
"facing=west,on=false": {"y": 270, "x": 0, "model": "computercraft:block/wireless_modem_normal_off"},
"facing=west,on=true": {"y": 270, "x": 0, "model": "computercraft:block/wireless_modem_normal_on"}
}
}

View File

@ -1,8 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"side": "computercraft:block/computer_advanced_side",
"top": "computercraft:block/computer_advanced_top",
"front": "computercraft:block/computer_advanced_front_blink",
"top": "computercraft:block/computer_advanced_top"
"side": "computercraft:block/computer_advanced_side"
}
}

View File

@ -1,8 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"side": "computercraft:block/computer_advanced_side",
"top": "computercraft:block/computer_advanced_top",
"front": "computercraft:block/computer_advanced_front",
"top": "computercraft:block/computer_advanced_top"
"side": "computercraft:block/computer_advanced_side"
}
}

View File

@ -1,8 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"side": "computercraft:block/computer_advanced_side",
"top": "computercraft:block/computer_advanced_top",
"front": "computercraft:block/computer_advanced_front_on",
"top": "computercraft:block/computer_advanced_top"
"side": "computercraft:block/computer_advanced_side"
}
}

View File

@ -1,8 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"side": "computercraft:block/computer_command_side",
"top": "computercraft:block/computer_command_top",
"front": "computercraft:block/computer_command_front_blink",
"top": "computercraft:block/computer_command_top"
"side": "computercraft:block/computer_command_side"
}
}

View File

@ -1,8 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"side": "computercraft:block/computer_command_side",
"top": "computercraft:block/computer_command_top",
"front": "computercraft:block/computer_command_front",
"top": "computercraft:block/computer_command_top"
"side": "computercraft:block/computer_command_side"
}
}

View File

@ -1,8 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"side": "computercraft:block/computer_command_side",
"top": "computercraft:block/computer_command_top",
"front": "computercraft:block/computer_command_front_on",
"top": "computercraft:block/computer_command_top"
"side": "computercraft:block/computer_command_side"
}
}

View File

@ -1,8 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"side": "computercraft:block/computer_normal_side",
"top": "computercraft:block/computer_normal_top",
"front": "computercraft:block/computer_normal_front_blink",
"top": "computercraft:block/computer_normal_top"
"side": "computercraft:block/computer_normal_side"
}
}

View File

@ -1,8 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"side": "computercraft:block/computer_normal_side",
"top": "computercraft:block/computer_normal_top",
"front": "computercraft:block/computer_normal_front",
"top": "computercraft:block/computer_normal_top"
"side": "computercraft:block/computer_normal_side"
}
}

View File

@ -1,8 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"side": "computercraft:block/computer_normal_side",
"top": "computercraft:block/computer_normal_top",
"front": "computercraft:block/computer_normal_front_on",
"top": "computercraft:block/computer_normal_top"
"side": "computercraft:block/computer_normal_side"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"top": "computercraft:block/disk_drive_top",
"front": "computercraft:block/disk_drive_front",
"side": "computercraft:block/disk_drive_side"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"top": "computercraft:block/disk_drive_top",
"front": "computercraft:block/disk_drive_front_accepted",
"side": "computercraft:block/disk_drive_side"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"top": "computercraft:block/disk_drive_top",
"front": "computercraft:block/disk_drive_front_rejected",
"side": "computercraft:block/disk_drive_side"
}
}

View File

@ -1,8 +1,9 @@
{
"parent": "minecraft:block/orientable",
"parent": "computercraft:block/monitor_base",
"textures": {
"side": "computercraft:block/monitor_advanced_4",
"front": "computercraft:block/monitor_advanced_15",
"top": "computercraft:block/monitor_advanced_0"
"side": "computercraft:block/monitor_advanced_4",
"top": "computercraft:block/monitor_advanced_0",
"back": "computercraft:block/monitor_advanced_32"
}
}

View File

@ -1,8 +1,9 @@
{
"parent": "minecraft:block/orientable",
"parent": "computercraft:block/monitor_base",
"textures": {
"side": "computercraft:block/monitor_normal_4",
"front": "computercraft:block/monitor_normal_15",
"top": "computercraft:block/monitor_normal_0"
"side": "computercraft:block/monitor_normal_4",
"top": "computercraft:block/monitor_normal_0",
"back": "computercraft:block/monitor_normal_32"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"top": "computercraft:block/printer_top",
"front": "computercraft:block/printer_front_both_trays",
"side": "computercraft:block/printer_side"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"top": "computercraft:block/printer_top",
"front": "computercraft:block/printer_front_bottom_tray",
"side": "computercraft:block/printer_side"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"top": "computercraft:block/printer_top",
"front": "computercraft:block/printer_front_empty",
"side": "computercraft:block/printer_side"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"top": "computercraft:block/printer_top",
"front": "computercraft:block/printer_front_top_tray",
"side": "computercraft:block/printer_side"
}
}

View File

@ -1,8 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"side": "computercraft:block/speaker_side",
"top": "computercraft:block/speaker_top",
"front": "computercraft:block/speaker_front",
"top": "computercraft:block/speaker_top"
"side": "computercraft:block/speaker_side"
}
}

View File

@ -1,4 +1 @@
{
"loader": "computercraft:turtle",
"model": "computercraft:block/turtle_advanced_base"
}
{"parent": "computercraft:block/turtle_base", "textures": {"texture": "computercraft:block/turtle_advanced"}}

View File

@ -1,6 +0,0 @@
{
"parent": "computercraft:block/turtle_base",
"textures": {
"texture": "computercraft:block/turtle_advanced"
}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_left",
"textures": {"texture": "computercraft:block/turtle_crafty_face"}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_right",
"textures": {"texture": "computercraft:block/turtle_crafty_face"}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_left",
"textures": {"texture": "computercraft:block/wireless_modem_advanced_face"}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_right",
"textures": {"texture": "computercraft:block/wireless_modem_advanced_face"}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_left",
"textures": {"texture": "computercraft:block/wireless_modem_advanced_face_on"}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_right",
"textures": {"texture": "computercraft:block/wireless_modem_advanced_face_on"}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_left",
"textures": {"texture": "computercraft:block/wireless_modem_normal_face"}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_right",
"textures": {"texture": "computercraft:block/wireless_modem_normal_face"}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_left",
"textures": {"texture": "computercraft:block/wireless_modem_normal_face_on"}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_right",
"textures": {"texture": "computercraft:block/wireless_modem_normal_face_on"}
}

View File

@ -1,4 +1 @@
{
"loader": "computercraft:turtle",
"model": "computercraft:block/turtle_normal_base"
}
{"parent": "computercraft:block/turtle_base", "textures": {"texture": "computercraft:block/turtle_normal"}}

View File

@ -1,6 +0,0 @@
{
"parent": "computercraft:block/turtle_base",
"textures": {
"texture": "computercraft:block/turtle_normal"
}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_left",
"textures": {"texture": "computercraft:block/turtle_speaker_face"}
}

View File

@ -0,0 +1,4 @@
{
"parent": "computercraft:block/turtle_upgrade_base_right",
"textures": {"texture": "computercraft:block/turtle_speaker_face"}
}

View File

@ -1,6 +1 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "computercraft:block/wired_modem_face"
}
}
{"parent": "minecraft:block/cube_all", "textures": {"all": "computercraft:block/wired_modem_face"}}

View File

@ -1,6 +1 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "computercraft:block/wired_modem_face_peripheral"
}
}
{"parent": "minecraft:block/cube_all", "textures": {"all": "computercraft:block/wired_modem_face_peripheral"}}

View File

@ -1,6 +1 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "computercraft:block/wired_modem_face_on"
}
}
{"parent": "minecraft:block/cube_all", "textures": {"all": "computercraft:block/wired_modem_face_on"}}

View File

@ -1,6 +1 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "computercraft:block/wired_modem_face_peripheral_on"
}
}
{"parent": "minecraft:block/cube_all", "textures": {"all": "computercraft:block/wired_modem_face_peripheral_on"}}

View File

@ -1,7 +1,4 @@
{
"parent": "computercraft:block/modem",
"textures": {
"front": "computercraft:block/wired_modem_face",
"back": "computercraft:block/modem_back"
}
"textures": {"front": "computercraft:block/wired_modem_face", "back": "computercraft:block/modem_back"}
}

View File

@ -1,7 +1,4 @@
{
"parent": "computercraft:block/modem",
"textures": {
"front": "computercraft:block/wired_modem_face_peripheral",
"back": "computercraft:block/modem_back"
}
"textures": {"front": "computercraft:block/wired_modem_face_peripheral", "back": "computercraft:block/modem_back"}
}

View File

@ -1,7 +1,4 @@
{
"parent": "computercraft:block/modem",
"textures": {
"front": "computercraft:block/wired_modem_face_on",
"back": "computercraft:block/modem_back"
}
"textures": {"front": "computercraft:block/wired_modem_face_on", "back": "computercraft:block/modem_back"}
}

View File

@ -1,7 +1,4 @@
{
"parent": "computercraft:block/modem",
"textures": {
"front": "computercraft:block/wireless_modem_advanced_face",
"back": "computercraft:block/modem_back"
}
"textures": {"front": "computercraft:block/wireless_modem_advanced_face", "back": "computercraft:block/modem_back"}
}

View File

@ -1,7 +1,4 @@
{
"parent": "computercraft:block/modem",
"textures": {
"front": "computercraft:block/wireless_modem_normal_face",
"back": "computercraft:block/modem_back"
}
"textures": {"front": "computercraft:block/wireless_modem_normal_face", "back": "computercraft:block/modem_back"}
}

View File

@ -1,7 +1,4 @@
{
"parent": "computercraft:block/modem",
"textures": {
"front": "computercraft:block/wireless_modem_normal_face_on",
"back": "computercraft:block/modem_back"
}
"textures": {"front": "computercraft:block/wireless_modem_normal_face_on", "back": "computercraft:block/modem_back"}
}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/computer_advanced_blinking"
}
{"parent": "computercraft:block/computer_advanced_blinking"}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/computer_command_blinking"
}
{"parent": "computercraft:block/computer_command_blinking"}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/computer_normal_blinking"
}
{"parent": "computercraft:block/computer_normal_blinking"}

View File

@ -0,0 +1,4 @@
{
"parent": "minecraft:item/generated",
"textures": {"layer0": "computercraft:item/disk_frame", "layer1": "computercraft:item/disk_colour"}
}

View File

@ -0,0 +1 @@
{"parent": "computercraft:block/disk_drive_empty"}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/monitor_advanced_item"
}
{"parent": "computercraft:block/monitor_advanced_item"}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/monitor_normal_item"
}
{"parent": "computercraft:block/monitor_normal_item"}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "computercraft:item/pocket_computer_blink",
"layer1": "computercraft:item/pocket_computer_advanced",
"layer2": "computercraft:item/pocket_computer_light"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "computercraft:item/pocket_computer_on",
"layer1": "computercraft:item/pocket_computer_advanced",
"layer2": "computercraft:item/pocket_computer_light"
}
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "computercraft:item/pocket_computer_frame",
"layer1": "computercraft:item/pocket_computer_colour"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "computercraft:item/pocket_computer_blink",
"layer1": "computercraft:item/pocket_computer_colour",
"layer2": "computercraft:item/pocket_computer_light"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "computercraft:item/pocket_computer_on",
"layer1": "computercraft:item/pocket_computer_colour",
"layer2": "computercraft:item/pocket_computer_light"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "computercraft:item/pocket_computer_blink",
"layer1": "computercraft:item/pocket_computer_normal",
"layer2": "computercraft:item/pocket_computer_light"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "computercraft:item/pocket_computer_on",
"layer1": "computercraft:item/pocket_computer_normal",
"layer2": "computercraft:item/pocket_computer_light"
}
}

View File

@ -0,0 +1 @@
{"parent": "minecraft:item/generated", "textures": {"layer0": "computercraft:item/printed_book"}}

View File

@ -0,0 +1 @@
{"parent": "minecraft:item/generated", "textures": {"layer0": "computercraft:item/printed_page"}}

View File

@ -0,0 +1 @@
{"parent": "minecraft:item/generated", "textures": {"layer0": "computercraft:item/printed_pages"}}

View File

@ -0,0 +1 @@
{"parent": "computercraft:block/printer_empty"}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/speaker"
}
{"parent": "computercraft:block/speaker"}

View File

@ -0,0 +1,4 @@
{
"parent": "minecraft:item/generated",
"textures": {"layer0": "computercraft:item/disk_frame", "layer1": "computercraft:item/disk_colour"}
}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/turtle_advanced"
}
{"loader": "computercraft:turtle", "model": "computercraft:block/turtle_advanced"}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/turtle_normal"
}
{"loader": "computercraft:turtle", "model": "computercraft:block/turtle_normal"}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/wired_modem_off"
}
{"parent": "computercraft:block/wired_modem_off"}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/wired_modem_full_off"
}
{"parent": "computercraft:block/wired_modem_full_off"}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/wireless_modem_advanced_off"
}
{"parent": "computercraft:block/wireless_modem_advanced_off"}

View File

@ -1,3 +1 @@
{
"parent": "computercraft:block/wireless_modem_normal_off"
}
{"parent": "computercraft:block/wireless_modem_normal_off"}

View File

@ -10,6 +10,7 @@
import net.minecraft.client.renderer.model.ModelManager;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.TransformationMatrix;
import javax.annotation.Nonnull;
@ -41,6 +42,12 @@ public static TransformedModel of( @Nonnull ModelResourceLocation location )
return new TransformedModel( modelManager.getModel( location ) );
}
public static TransformedModel of( @Nonnull ResourceLocation location )
{
ModelManager modelManager = Minecraft.getInstance().getModelManager();
return new TransformedModel( modelManager.getModel( location ) );
}
public static TransformedModel of( @Nonnull ItemStack item, @Nonnull TransformationMatrix transform )
{
IBakedModel model = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getItemModel( item );

View File

@ -21,7 +21,6 @@
import net.minecraft.client.gui.ScreenManager;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemModelsProperties;
@ -45,24 +44,25 @@ public final class ClientRegistry
{
private static final String[] EXTRA_MODELS = new String[] {
// Turtle upgrades
"turtle_modem_normal_off_left",
"turtle_modem_normal_on_left",
"turtle_modem_normal_off_right",
"turtle_modem_normal_on_right",
"block/turtle_modem_normal_off_left",
"block/turtle_modem_normal_on_left",
"block/turtle_modem_normal_off_right",
"block/turtle_modem_normal_on_right",
"turtle_modem_advanced_off_left",
"turtle_modem_advanced_on_left",
"turtle_modem_advanced_off_right",
"turtle_modem_advanced_on_right",
"turtle_crafting_table_left",
"turtle_crafting_table_right",
"block/turtle_modem_advanced_off_left",
"block/turtle_modem_advanced_on_left",
"block/turtle_modem_advanced_off_right",
"block/turtle_modem_advanced_on_right",
"turtle_speaker_upgrade_left",
"turtle_speaker_upgrade_right",
"block/turtle_crafting_table_left",
"block/turtle_crafting_table_right",
"block/turtle_speaker_left",
"block/turtle_speaker_right",
// Turtle block renderer
"turtle_colour",
"turtle_elf_overlay",
"block/turtle_colour",
"block/turtle_elf_overlay",
};
private ClientRegistry() {}
@ -73,7 +73,7 @@ public static void registerModels( ModelRegistryEvent event )
ModelLoaderRegistry.registerLoader( new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ), TurtleModelLoader.INSTANCE );
for( String model : EXTRA_MODELS )
{
ModelLoader.addSpecialModel( new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, model ), "inventory" ) );
ModelLoader.addSpecialModel( new ResourceLocation( ComputerCraft.MOD_ID, model ) );
}
}

View File

@ -7,6 +7,7 @@
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
@ -42,8 +43,8 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
{
private static final ModelResourceLocation NORMAL_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_normal", "inventory" );
private static final ModelResourceLocation ADVANCED_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_advanced", "inventory" );
private static final ModelResourceLocation COLOUR_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_colour", "inventory" );
private static final ModelResourceLocation ELF_OVERLAY_MODEL = new ModelResourceLocation( "computercraft:turtle_elf_overlay", "inventory" );
private static final ResourceLocation COLOUR_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_colour" );
private static final ResourceLocation ELF_OVERLAY_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_elf_overlay" );
private final Random random = new Random( 0 );
@ -52,7 +53,7 @@ public TileEntityTurtleRenderer( TileEntityRendererDispatcher renderDispatcher )
super( renderDispatcher );
}
public static ModelResourceLocation getTurtleModel( ComputerFamily family, boolean coloured )
public static ResourceLocation getTurtleModel( ComputerFamily family, boolean coloured )
{
switch( family )
{
@ -64,9 +65,9 @@ public static ModelResourceLocation getTurtleModel( ComputerFamily family, boole
}
}
public static ModelResourceLocation getTurtleOverlayModel( ResourceLocation overlay, boolean christmas )
public static ResourceLocation getTurtleOverlayModel( ResourceLocation overlay, boolean christmas )
{
if( overlay != null ) return new ModelResourceLocation( overlay, "inventory" );
if( overlay != null ) return overlay;
if( christmas ) return ELF_OVERLAY_MODEL;
return null;
}
@ -121,7 +122,7 @@ public void render( @Nonnull TileTurtle turtle, float partialTicks, @Nonnull Mat
renderModel( transform, buffer, lightmapCoord, overlayLight, getTurtleModel( family, colour != -1 ), colour == -1 ? null : new int[] { colour } );
// Render the overlay
ModelResourceLocation overlayModel = getTurtleOverlayModel( overlay, HolidayUtil.getCurrentHoliday() == Holiday.CHRISTMAS );
ResourceLocation overlayModel = getTurtleOverlayModel( overlay, HolidayUtil.getCurrentHoliday() == Holiday.CHRISTMAS );
if( overlayModel != null )
{
renderModel( transform, buffer, lightmapCoord, overlayLight, overlayModel, null );
@ -153,7 +154,7 @@ private void renderUpgrade( @Nonnull MatrixStack transform, @Nonnull IVertexBuil
transform.popPose();
}
private void renderModel( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder renderer, int lightmapCoord, int overlayLight, ModelResourceLocation modelLocation, int[] tints )
private void renderModel( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder renderer, int lightmapCoord, int overlayLight, ResourceLocation modelLocation, int[] tints )
{
ModelManager modelManager = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getModelManager();
renderModel( transform, renderer, lightmapCoord, overlayLight, modelManager.getModel( modelLocation ), tints );

View File

@ -139,7 +139,7 @@ private IBakedModel buildModel( TurtleModelCombination combo )
{
Minecraft mc = Minecraft.getInstance();
ModelManager modelManager = mc.getItemRenderer().getItemModelShaper().getModelManager();
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.overlay, combo.christmas );
ResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.overlay, combo.christmas );
IBakedModel baseModel = combo.colour ? colourModel : familyModel;
IBakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null;

View File

@ -1,44 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.data;
import com.google.gson.JsonObject;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.generators.CustomLoaderBuilder;
import net.minecraftforge.client.model.generators.ModelBuilder;
import net.minecraftforge.common.data.ExistingFileHelper;
import java.util.function.BiFunction;
import java.util.function.Consumer;
public class BasicCustomLoader<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
{
private final Consumer<JsonObject> extra;
protected BasicCustomLoader( ResourceLocation loaderId, T parent, ExistingFileHelper existingFileHelper, Consumer<JsonObject> extra )
{
super( loaderId, parent, existingFileHelper );
this.extra = extra;
}
public static <T extends ModelBuilder<T>> BiFunction<T, ExistingFileHelper, CustomLoaderBuilder<T>> makeFactory( ResourceLocation id )
{
return makeFactory( id, j -> {} );
}
public static <T extends ModelBuilder<T>> BiFunction<T, ExistingFileHelper, CustomLoaderBuilder<T>> makeFactory( ResourceLocation id, Consumer<JsonObject> extra )
{
return ( parent, x ) -> new BasicCustomLoader<>( id, parent, x, extra );
}
@Override
public JsonObject toJson( JsonObject json )
{
super.toJson( json );
extra.accept( json );
return json;
}
}

View File

@ -0,0 +1,473 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.data;
import com.google.gson.JsonObject;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.Registry;
import dan200.computercraft.shared.computer.blocks.BlockComputer;
import dan200.computercraft.shared.peripheral.diskdrive.BlockDiskDrive;
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant;
import dan200.computercraft.shared.peripheral.modem.wireless.BlockWirelessModem;
import dan200.computercraft.shared.peripheral.monitor.BlockMonitor;
import dan200.computercraft.shared.peripheral.monitor.MonitorEdgeState;
import dan200.computercraft.shared.peripheral.printer.BlockPrinter;
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.data.*;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.Property;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;
import static net.minecraft.data.ModelTextures.getBlockTexture;
import static net.minecraft.data.ModelsResourceUtil.getModelLocation;
class BlockModelGenerator
{
private static final ModelsUtil MONITOR_BASE = new ModelsUtil(
Optional.of( new ResourceLocation( ComputerCraft.MOD_ID, "block/monitor_base" ) ),
Optional.empty(),
StockTextureAliases.FRONT, StockTextureAliases.SIDE, StockTextureAliases.TOP, StockTextureAliases.BACK
);
private static final ModelsUtil MODEM = new ModelsUtil(
Optional.of( new ResourceLocation( ComputerCraft.MOD_ID, "block/modem" ) ),
Optional.empty(),
StockTextureAliases.FRONT, StockTextureAliases.BACK
);
private static final ModelsUtil TURTLE = new ModelsUtil(
Optional.of( new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_base" ) ),
Optional.empty(),
StockTextureAliases.TEXTURE
);
private static final ModelsUtil TURTLE_UPGRADE_LEFT = new ModelsUtil(
Optional.of( new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_upgrade_base_left" ) ),
Optional.of( "_left" ),
StockTextureAliases.TEXTURE
);
private static final ModelsUtil TURTLE_UPGRADE_RIGHT = new ModelsUtil(
Optional.of( new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_upgrade_base_right" ) ),
Optional.of( "_left" ),
StockTextureAliases.TEXTURE
);
public static void addBlockModels( BlockModelProvider generators )
{
registerComputer( generators, Registry.ModBlocks.COMPUTER_NORMAL.get() );
registerComputer( generators, Registry.ModBlocks.COMPUTER_ADVANCED.get() );
registerComputer( generators, Registry.ModBlocks.COMPUTER_COMMAND.get() );
registerTurtle( generators, Registry.ModBlocks.TURTLE_NORMAL.get() );
registerTurtle( generators, Registry.ModBlocks.TURTLE_ADVANCED.get() );
registerWirelessModem( generators, Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() );
registerWirelessModem( generators, Registry.ModBlocks.WIRELESS_MODEM_ADVANCED.get() );
registerWiredModems( generators );
registerMonitor( generators, Registry.ModBlocks.MONITOR_NORMAL.get() );
registerMonitor( generators, Registry.ModBlocks.MONITOR_ADVANCED.get() );
generators.createHorizontallyRotatedBlock( Registry.ModBlocks.SPEAKER.get(), TexturedModel.ORIENTABLE_ONLY_TOP );
registerDiskDrive( generators );
registerPrinter( generators );
registerCable( generators );
registerTurtleUpgrade( generators, "block/turtle_crafting_table", "block/turtle_crafty_face" );
registerTurtleUpgrade( generators, "block/turtle_speaker", "block/turtle_speaker_face" );
registerTurtleModem( generators, "block/turtle_modem_normal", "block/wireless_modem_normal_face" );
registerTurtleModem( generators, "block/turtle_modem_advanced", "block/wireless_modem_advanced_face" );
}
private static void registerDiskDrive( BlockModelProvider generators )
{
BlockDiskDrive diskDrive = Registry.ModBlocks.DISK_DRIVE.get();
generators.blockStateOutput.accept( FinishedVariantBlockState.multiVariant( diskDrive )
.with( createHorizontalFacingDispatch() )
.with( createModelDispatch( BlockDiskDrive.STATE, value -> {
String textureSuffix;
switch( value )
{
case EMPTY:
textureSuffix = "_front";
break;
case INVALID:
textureSuffix = "_front_rejected";
break;
case FULL:
textureSuffix = "_front_accepted";
break;
default:
throw new IllegalArgumentException();
}
return StockModelShapes.CUBE_ORIENTABLE.createWithSuffix(
diskDrive, "_" + value.getSerializedName(),
ModelTextures.orientableCube( diskDrive ).put( StockTextureAliases.FRONT, getBlockTexture( diskDrive, textureSuffix ) ),
generators.modelOutput
);
} ) )
);
generators.delegateItemModel( diskDrive, getModelLocation( diskDrive, "_empty" ) );
}
private static void registerPrinter( BlockModelProvider generators )
{
BlockPrinter printer = Registry.ModBlocks.PRINTER.get();
generators.blockStateOutput.accept( FinishedVariantBlockState.multiVariant( printer )
.with( createHorizontalFacingDispatch() )
.with( createModelDispatch( BlockPrinter.TOP, BlockPrinter.BOTTOM, ( top, bottom ) -> {
String model, texture;
if( top && bottom )
{
model = "_both_full";
texture = "_both_trays";
}
else if( top )
{
model = "_top_full";
texture = "_top_tray";
}
else if( bottom )
{
model = "_bottom_full";
texture = "_bottom_tray";
}
else
{
texture = model = "_empty";
}
return StockModelShapes.CUBE_ORIENTABLE.createWithSuffix( printer, model,
ModelTextures.orientableCube( printer ).put( StockTextureAliases.FRONT, getBlockTexture( printer, "_front" + texture ) ),
generators.modelOutput
);
} ) )
);
generators.delegateItemModel( printer, getModelLocation( printer, "_empty" ) );
}
private static void registerComputer( BlockModelProvider generators, BlockComputer block )
{
generators.blockStateOutput.accept( FinishedVariantBlockState.multiVariant( block )
.with( createHorizontalFacingDispatch() )
.with( createModelDispatch( BlockComputer.STATE, state -> StockModelShapes.CUBE_ORIENTABLE.createWithSuffix(
block, "_" + state.getSerializedName(),
ModelTextures.orientableCube( block ).put( StockTextureAliases.FRONT, getBlockTexture( block, "_front" + state.getTexture() ) ),
generators.modelOutput
) ) )
);
generators.delegateItemModel( block, getModelLocation( block, "_blinking" ) );
}
private static void registerTurtle( BlockModelProvider generators, BlockTurtle block )
{
ResourceLocation model = TURTLE.create( block, ModelTextures.defaultTexture( block ), generators.modelOutput );
generators.blockStateOutput.accept(
FinishedVariantBlockState.multiVariant( block, BlockModelDefinition.variant().with( BlockModelFields.MODEL, model ) )
.with( createHorizontalFacingDispatch() )
);
generators.modelOutput.accept( getModelLocation( block.asItem() ), () -> {
JsonObject out = new JsonObject();
out.addProperty( "loader", "computercraft:turtle" );
out.addProperty( "model", model.toString() );
return out;
} );
}
private static void registerWirelessModem( BlockModelProvider generators, BlockWirelessModem block )
{
generators.blockStateOutput.accept( FinishedVariantBlockState.multiVariant( block )
.with( createFacingDispatch() )
.with( createModelDispatch( BlockWirelessModem.ON,
on -> modemModel( generators, getModelLocation( block, on ? "_on" : "_off" ), getBlockTexture( block, "_face" + (on ? "_on" : "") ) )
) ) );
generators.delegateItemModel( block, getModelLocation( block, "_off" ) );
}
private static void registerWiredModems( BlockModelProvider generators )
{
BlockWiredModemFull fullBlock = Registry.ModBlocks.WIRED_MODEM_FULL.get();
generators.blockStateOutput.accept( FinishedVariantBlockState.multiVariant( fullBlock )
.with( createModelDispatch( BlockWiredModemFull.MODEM_ON, BlockWiredModemFull.PERIPHERAL_ON, ( on, peripheral ) -> {
String suffix = (on ? "_on" : "_off") + (peripheral ? "_peripheral" : "");
ResourceLocation faceTexture = new ResourceLocation( ComputerCraft.MOD_ID, "block/wired_modem_face" + (peripheral ? "_peripheral" : "") + (on ? "_on" : "") );
// TODO: Do this somewhere more elegant!
modemModel( generators, new ResourceLocation( ComputerCraft.MOD_ID, "block/wired_modem" + suffix ), faceTexture );
return StockModelShapes.CUBE_ALL.create(
getModelLocation( fullBlock, suffix ),
new ModelTextures().put( StockTextureAliases.ALL, faceTexture ),
generators.modelOutput
);
} ) ) );
generators.delegateItemModel( fullBlock, getModelLocation( fullBlock, "_off" ) );
generators.delegateItemModel( Registry.ModItems.WIRED_MODEM.get(), new ResourceLocation( ComputerCraft.MOD_ID, "block/wired_modem_off" ) );
}
private static ResourceLocation modemModel( BlockModelProvider generators, ResourceLocation name, ResourceLocation texture )
{
return MODEM.create(
name,
new ModelTextures()
.put( StockTextureAliases.FRONT, texture )
.put( StockTextureAliases.BACK, new ResourceLocation( ComputerCraft.MOD_ID, "block/modem_back" ) ),
generators.modelOutput
);
}
private static void registerMonitor( BlockModelProvider generators, BlockMonitor block )
{
monitorModel( generators, block, "", 16, 4, 0, 32 );
monitorModel( generators, block, "_d", 20, 7, 0, 36 );
monitorModel( generators, block, "_l", 19, 4, 1, 33 );
monitorModel( generators, block, "_ld", 31, 7, 1, 45 );
monitorModel( generators, block, "_lr", 18, 4, 2, 34 );
monitorModel( generators, block, "_lrd", 30, 7, 2, 46 );
monitorModel( generators, block, "_lru", 24, 5, 2, 40 );
monitorModel( generators, block, "_lrud", 27, 6, 2, 43 );
monitorModel( generators, block, "_lu", 25, 5, 1, 39 );
monitorModel( generators, block, "_lud", 28, 6, 1, 42 );
monitorModel( generators, block, "_r", 17, 4, 3, 35 );
monitorModel( generators, block, "_rd", 29, 7, 3, 47 );
monitorModel( generators, block, "_ru", 23, 5, 3, 41 );
monitorModel( generators, block, "_rud", 26, 6, 3, 44 );
monitorModel( generators, block, "_u", 22, 5, 0, 38 );
monitorModel( generators, block, "_ud", 21, 6, 0, 37 );
generators.blockStateOutput.accept( FinishedVariantBlockState.multiVariant( block )
.with( createHorizontalFacingDispatch() )
.with( createVerticalFacingDispatch( BlockMonitor.ORIENTATION ) )
.with( createModelDispatch( BlockMonitor.STATE, edge -> getModelLocation( block, edge == MonitorEdgeState.NONE ? "" : "_" + edge.getSerializedName() ) ) )
);
generators.delegateItemModel( block, monitorModel( generators, block, "_item", 15, 4, 0, 32 ) );
}
private static ResourceLocation monitorModel( BlockModelProvider generators, BlockMonitor block, String corners, int front, int side, int top, int back )
{
return MONITOR_BASE.create(
getModelLocation( block, corners ),
new ModelTextures()
.put( StockTextureAliases.FRONT, getBlockTexture( block, "_" + front ) )
.put( StockTextureAliases.SIDE, getBlockTexture( block, "_" + side ) )
.put( StockTextureAliases.TOP, getBlockTexture( block, "_" + top ) )
.put( StockTextureAliases.BACK, getBlockTexture( block, "_" + back ) ),
generators.modelOutput
);
}
private static void registerCable( BlockModelProvider generators )
{
FinishedMultiPartBlockState generator = FinishedMultiPartBlockState.multiPart( Registry.ModBlocks.CABLE.get() );
// When a cable only has a neighbour in a single direction, we redirect the core to face that direction.
ResourceLocation coreFacing = new ResourceLocation( ComputerCraft.MOD_ID, "block/cable_core_facing" );
generator.with( // Up/Down
IMultiPartPredicateBuilder.or(
cableNoNeighbour( Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST ).term( BlockCable.UP, true ),
cableNoNeighbour( Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST ).term( BlockCable.DOWN, true )
),
BlockModelDefinition.variant().with( BlockModelFields.MODEL, coreFacing ).with( BlockModelFields.X_ROT, BlockModelFields.Rotation.R90 )
);
generator.with( // North/South and no neighbours
IMultiPartPredicateBuilder.or(
cableNoNeighbour( Direction.UP, Direction.DOWN, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST ),
cableNoNeighbour( Direction.UP, Direction.DOWN, Direction.EAST, Direction.WEST ).term( BlockCable.NORTH, true ),
cableNoNeighbour( Direction.UP, Direction.DOWN, Direction.EAST, Direction.WEST ).term( BlockCable.SOUTH, true )
),
BlockModelDefinition.variant().with( BlockModelFields.MODEL, coreFacing ).with( BlockModelFields.Y_ROT, BlockModelFields.Rotation.R0 )
);
generator.with( // East/West
IMultiPartPredicateBuilder.or(
cableNoNeighbour( Direction.NORTH, Direction.SOUTH, Direction.UP, Direction.DOWN ).term( BlockCable.EAST, true ),
cableNoNeighbour( Direction.NORTH, Direction.SOUTH, Direction.UP, Direction.DOWN ).term( BlockCable.WEST, true )
),
BlockModelDefinition.variant().with( BlockModelFields.MODEL, coreFacing ).with( BlockModelFields.Y_ROT, BlockModelFields.Rotation.R90 )
);
// Find all other possibilities and emit a "solid" core which doesn't have a facing direction.
ResourceLocation core = new ResourceLocation( ComputerCraft.MOD_ID, "block/cable_core_any" );
List<IMultiPartPredicateBuilder.Properties> rightAngles = new ArrayList<>();
for( int i = 0; i < DirectionUtil.FACINGS.length; i++ )
{
for( int j = i; j < DirectionUtil.FACINGS.length; j++ )
{
if( DirectionUtil.FACINGS[i].getAxis() == DirectionUtil.FACINGS[j].getAxis() ) continue;
rightAngles.add( new IMultiPartPredicateBuilder.Properties()
.term( BlockCable.CABLE, true ).term( CABLE_DIRECTIONS[i], true ).term( CABLE_DIRECTIONS[j], true )
);
}
}
generator.with( IMultiPartPredicateBuilder.or( rightAngles.toArray( new IMultiPartPredicateBuilder[0] ) ), BlockModelDefinition.variant().with( BlockModelFields.MODEL, core ) );
// Then emit the actual cable arms
ResourceLocation arm = new ResourceLocation( ComputerCraft.MOD_ID, "block/cable_arm" );
for( Direction direction : DirectionUtil.FACINGS )
{
generator.with(
new IMultiPartPredicateBuilder.Properties().term( CABLE_DIRECTIONS[direction.ordinal()], true ),
BlockModelDefinition.variant()
.with( BlockModelFields.MODEL, arm )
.with( BlockModelFields.X_ROT, toXAngle( direction.getOpposite() ) )
.with( BlockModelFields.Y_ROT, toYAngle( direction.getOpposite() ) )
);
}
// And the modems!
for( Direction direction : DirectionUtil.FACINGS )
{
for( boolean on : BOOLEANS )
{
for( boolean peripheral : BOOLEANS )
{
String suffix = (on ? "_on" : "_off") + (peripheral ? "_peripheral" : "");
generator.with(
new IMultiPartPredicateBuilder.Properties().term( BlockCable.MODEM, CableModemVariant.from( direction, on, peripheral ) ),
BlockModelDefinition.variant()
.with( BlockModelFields.MODEL, new ResourceLocation( ComputerCraft.MOD_ID, "block/wired_modem" + suffix ) )
.with( BlockModelFields.X_ROT, toXAngle( direction ) )
.with( BlockModelFields.Y_ROT, toYAngle( direction ) )
);
}
}
}
generators.blockStateOutput.accept( generator );
}
private static final BooleanProperty[] CABLE_DIRECTIONS = { BlockCable.DOWN, BlockCable.UP, BlockCable.NORTH, BlockCable.SOUTH, BlockCable.WEST, BlockCable.EAST };
private static final boolean[] BOOLEANS = new boolean[] { false, true };
private static IMultiPartPredicateBuilder.Properties cableNoNeighbour( Direction... directions )
{
IMultiPartPredicateBuilder.Properties condition = new IMultiPartPredicateBuilder.Properties().term( BlockCable.CABLE, true );
for( Direction direction : directions ) condition.term( CABLE_DIRECTIONS[direction.ordinal()], false );
return condition;
}
private static void registerTurtleUpgrade( BlockModelProvider generators, String name, String texture )
{
TURTLE_UPGRADE_LEFT.create(
new ResourceLocation( ComputerCraft.MOD_ID, name + "_left" ),
ModelTextures.defaultTexture( new ResourceLocation( ComputerCraft.MOD_ID, texture ) ),
generators.modelOutput
);
TURTLE_UPGRADE_RIGHT.create(
new ResourceLocation( ComputerCraft.MOD_ID, name + "_right" ),
ModelTextures.defaultTexture( new ResourceLocation( ComputerCraft.MOD_ID, texture ) ),
generators.modelOutput
);
}
private static void registerTurtleModem( BlockModelProvider generators, String name, String texture )
{
registerTurtleUpgrade( generators, name + "_off", texture );
registerTurtleUpgrade( generators, name + "_on", texture + "_on" );
}
private static BlockModelFields.Rotation toXAngle( Direction direction )
{
switch( direction )
{
default:
return BlockModelFields.Rotation.R0;
case UP:
return BlockModelFields.Rotation.R270;
case DOWN:
return BlockModelFields.Rotation.R90;
}
}
private static BlockModelFields.Rotation toYAngle( Direction direction )
{
switch( direction )
{
default:
return BlockModelFields.Rotation.R0;
case NORTH:
return BlockModelFields.Rotation.R0;
case SOUTH:
return BlockModelFields.Rotation.R180;
case EAST:
return BlockModelFields.Rotation.R90;
case WEST:
return BlockModelFields.Rotation.R270;
}
}
private static BlockStateVariantBuilder createHorizontalFacingDispatch()
{
BlockStateVariantBuilder.One<Direction> dispatch = BlockStateVariantBuilder.property( BlockStateProperties.HORIZONTAL_FACING );
for( Direction direction : BlockStateProperties.HORIZONTAL_FACING.getPossibleValues() )
{
dispatch.select( direction, BlockModelDefinition.variant().with( BlockModelFields.Y_ROT, toYAngle( direction ) ) );
}
return dispatch;
}
private static BlockStateVariantBuilder createVerticalFacingDispatch( Property<Direction> property )
{
BlockStateVariantBuilder.One<Direction> dispatch = BlockStateVariantBuilder.property( property );
for( Direction direction : property.getPossibleValues() )
{
dispatch.select( direction, BlockModelDefinition.variant().with( BlockModelFields.X_ROT, toXAngle( direction ) ) );
}
return dispatch;
}
private static BlockStateVariantBuilder createFacingDispatch()
{
BlockStateVariantBuilder.One<Direction> dispatch = BlockStateVariantBuilder.property( BlockStateProperties.FACING );
for( Direction direction : BlockStateProperties.FACING.getPossibleValues() )
{
dispatch.select( direction, BlockModelDefinition.variant()
.with( BlockModelFields.Y_ROT, toYAngle( direction ) )
.with( BlockModelFields.X_ROT, toXAngle( direction ) )
);
}
return dispatch;
}
private static <T extends Comparable<T>> BlockStateVariantBuilder createModelDispatch( Property<T> property, Function<T, ResourceLocation> makeModel )
{
BlockStateVariantBuilder.One<T> variant = BlockStateVariantBuilder.property( property );
for( T value : property.getPossibleValues() )
{
variant.select( value, BlockModelDefinition.variant().with( BlockModelFields.MODEL, makeModel.apply( value ) ) );
}
return variant;
}
private static <T extends Comparable<T>, U extends Comparable<U>> BlockStateVariantBuilder createModelDispatch(
Property<T> propertyT, Property<U> propertyU, BiFunction<T, U, ResourceLocation> makeModel
)
{
BlockStateVariantBuilder.Two<T, U> variant = BlockStateVariantBuilder.properties( propertyT, propertyU );
for( T valueT : propertyT.getPossibleValues() )
{
for( U valueU : propertyU.getPossibleValues() )
{
variant.select( valueT, valueU, BlockModelDefinition.variant().with( BlockModelFields.MODEL, makeModel.apply( valueT, valueU ) ) );
}
}
return variant;
}
}

View File

@ -1,285 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. 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.computer.blocks.BlockComputer;
import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
import dan200.computercraft.shared.peripheral.modem.wireless.BlockWirelessModem;
import dan200.computercraft.shared.peripheral.monitor.BlockMonitor;
import dan200.computercraft.shared.peripheral.monitor.MonitorEdgeState;
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
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 net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull;
import java.util.Objects;
public class BlockModelProvider extends BlockStateProvider
{
private ModelFile monitorBase;
private ModelFile turtleBase;
private ModelFile modemBase;
public BlockModelProvider( DataGenerator generator, ExistingFileHelper existingFileHelper )
{
super( generator, ComputerCraft.MOD_ID, existingFileHelper );
}
@Nonnull
@Override
public String getName()
{
return "Block states and models";
}
@Override
protected void registerStatesAndModels()
{
monitorBase = models().getExistingFile( new ResourceLocation( ComputerCraft.MOD_ID, "block/monitor_base" ) );
turtleBase = models().getExistingFile( new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_base" ) );
modemBase = models().getExistingFile( new ResourceLocation( ComputerCraft.MOD_ID, "block/modem" ) );
registerComputer( Registry.ModBlocks.COMPUTER_NORMAL.get() );
registerComputer( Registry.ModBlocks.COMPUTER_ADVANCED.get() );
registerComputer( Registry.ModBlocks.COMPUTER_COMMAND.get() );
registerTurtle( Registry.ModBlocks.TURTLE_NORMAL.get() );
registerTurtle( Registry.ModBlocks.TURTLE_ADVANCED.get() );
registerWirelessModem( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() );
registerWirelessModem( Registry.ModBlocks.WIRELESS_MODEM_ADVANCED.get() );
registerWiredModems();
registerMonitors( Registry.ModBlocks.MONITOR_NORMAL.get() );
registerMonitors( Registry.ModBlocks.MONITOR_ADVANCED.get() );
// Register the simple things.
ModelFile speaker = models().orientable(
name( Registry.ModBlocks.SPEAKER.get() ),
blockTexture( Registry.ModBlocks.SPEAKER.get(), "_side" ),
blockTexture( Registry.ModBlocks.SPEAKER.get(), "_front" ),
blockTexture( Registry.ModBlocks.SPEAKER.get(), "_top" )
);
horizontalBlock( Registry.ModBlocks.SPEAKER.get(), speaker );
simpleBlockItem( Registry.ModBlocks.SPEAKER.get(), speaker );
}
private void registerComputer( BlockComputer block )
{
VariantBlockStateBuilder builder = getVariantBuilder( block );
for( ComputerState state : BlockComputer.STATE.getPossibleValues() )
{
BlockModelBuilder model = models().orientable(
extendedName( block, "_" + state ),
blockTexture( block, "_side" ),
blockTexture( block, "_front" + state.getTexture() ),
blockTexture( block, "_top" )
);
for( Direction facing : BlockComputer.FACING.getPossibleValues() )
{
builder.partialState()
.with( BlockComputer.STATE, state )
.with( BlockComputer.FACING, facing )
.addModels( new ConfiguredModel( model, 0, toYAngle( facing ), false ) );
}
}
simpleBlockItem( block, models().getBuilder( extendedName( block, "_blinking" ) ) );
}
private void registerTurtle( BlockTurtle block )
{
VariantBlockStateBuilder builder = getVariantBuilder( block );
BlockModelBuilder base = models()
.getBuilder( extendedName( block, "_base" ) )
.parent( turtleBase )
.texture( "texture", blockTexture( block ) );
BlockModelBuilder model = models()
.getBuilder( name( block ) )
.customLoader( BasicCustomLoader.makeFactory( new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ), x -> {
x.addProperty( "model", base.getLocation().toString() );
} ) )
.end();
for( Direction facing : BlockTurtle.FACING.getPossibleValues() )
{
builder.partialState()
.with( BlockTurtle.FACING, facing )
.addModels( new ConfiguredModel( model, 0, toYAngle( facing ), false ) );
}
simpleBlockItem( block, models().getBuilder( name( block ) ) );
}
private void registerWirelessModem( BlockWirelessModem block )
{
VariantBlockStateBuilder builder = getVariantBuilder( block );
for( boolean on : BlockWirelessModem.ON.getPossibleValues() )
{
ModelFile model = modemModel( extendedName( block, on ? "_on" : "_off" ), blockTexture( block, "_face" + (on ? "_on" : "") ) );
for( Direction facing : BlockWirelessModem.FACING.getPossibleValues() )
{
builder.partialState()
.with( BlockWirelessModem.FACING, facing )
.with( BlockWirelessModem.ON, on )
.addModels( new ConfiguredModel( model, toXAngle( facing ), toYAngle( facing ), false ) );
}
}
simpleBlockItem( block, models().getBuilder( extendedName( block, "_off" ) ) );
}
private void registerWiredModems()
{
Block fullBlock = Registry.ModBlocks.WIRED_MODEM_FULL.get();
VariantBlockStateBuilder fullBlockState = getVariantBuilder( fullBlock );
for( boolean on : BlockWiredModemFull.MODEM_ON.getPossibleValues() )
{
for( boolean peripheral : BlockWiredModemFull.PERIPHERAL_ON.getPossibleValues() )
{
String suffix = (on ? "_on" : "_off") + (peripheral ? "_peripheral" : "");
ResourceLocation faceTexture = new ResourceLocation(
ComputerCraft.MOD_ID,
"block/wired_modem_face" + (peripheral ? "_peripheral" : "") + (on ? "_on" : "")
);
ModelFile fullBlockModel = models().cubeAll( blockTexture( fullBlock, suffix ).toString(), faceTexture );
fullBlockState.partialState()
.with( BlockWiredModemFull.MODEM_ON, on )
.with( BlockWiredModemFull.PERIPHERAL_ON, peripheral )
.addModels( new ConfiguredModel( fullBlockModel ) );
modemModel( "wired_modem" + suffix, faceTexture );
}
}
simpleBlockItem( fullBlock, models().getBuilder( extendedName( fullBlock, "_off" ) ) );
itemModels()
.getBuilder( name( Registry.ModItems.WIRED_MODEM.get() ) )
.parent( models().getBuilder( "wired_modem_off" ) );
}
private ModelFile modemModel( String name, ResourceLocation texture )
{
return models()
.getBuilder( name )
.parent( modemBase )
.texture( "front", texture )
.texture( "back", new ResourceLocation( ComputerCraft.MOD_ID, "block/modem_back" ) );
}
private void registerMonitors( BlockMonitor block )
{
String name = blockTexture( block ).toString();
monitorModel( name, "", 16, 4, 0, 32 );
monitorModel( name, "_d", 20, 7, 0, 36 );
monitorModel( name, "_l", 19, 4, 1, 33 );
monitorModel( name, "_ld", 31, 7, 1, 45 );
monitorModel( name, "_lr", 18, 4, 2, 34 );
monitorModel( name, "_lrd", 30, 7, 2, 46 );
monitorModel( name, "_lru", 24, 5, 2, 40 );
monitorModel( name, "_lrud", 27, 6, 2, 43 );
monitorModel( name, "_lu", 25, 5, 1, 39 );
monitorModel( name, "_lud", 28, 6, 1, 42 );
monitorModel( name, "_r", 17, 4, 3, 35 );
monitorModel( name, "_rd", 29, 7, 3, 47 );
monitorModel( name, "_ru", 23, 5, 3, 41 );
monitorModel( name, "_rud", 26, 6, 3, 44 );
monitorModel( name, "_u", 22, 5, 0, 38 );
monitorModel( name, "_ud", 21, 6, 0, 37 );
VariantBlockStateBuilder builder = getVariantBuilder( block );
for( MonitorEdgeState edge : BlockMonitor.STATE.getPossibleValues() )
{
String suffix = edge == MonitorEdgeState.NONE ? "" : "_" + edge.getSerializedName();
ModelFile model = models().getBuilder( extend( block.getRegistryName(), suffix ) );
for( Direction facing : BlockMonitor.FACING.getPossibleValues() )
{
for( Direction orientation : BlockMonitor.ORIENTATION.getPossibleValues() )
{
builder.partialState()
.with( BlockMonitor.STATE, edge )
.with( BlockMonitor.FACING, facing )
.with( BlockMonitor.ORIENTATION, orientation )
.addModels( new ConfiguredModel( model, toXAngle( orientation ), toYAngle( facing ), false ) );
}
}
}
simpleBlockItem( block, models().orientable(
extendedName( block, "_item" ),
blockTexture( block, "_4" ),
blockTexture( block, "_15" ),
blockTexture( block, "_0" )
) );
}
private void monitorModel( String prefix, String corners, int front, int side, int top, int back )
{
String texturePrefix = prefix + "_";
models().getBuilder( prefix + corners )
.parent( monitorBase )
.texture( "front", texturePrefix + front )
.texture( "side", texturePrefix + side )
.texture( "top", texturePrefix + top )
.texture( "back", texturePrefix + back );
}
private static int toXAngle( Direction direction )
{
switch( direction )
{
default:
return 0;
case UP:
return 270;
case DOWN:
return 90;
}
}
private static int toYAngle( Direction direction )
{
return ((int) direction.toYRot() + 180) % 360;
}
private static ResourceLocation blockTexture( Block block, String suffix )
{
ResourceLocation id = block.getRegistryName();
return new ResourceLocation( id.getNamespace(), "block/" + id.getPath() + suffix );
}
@Nonnull
private String name( @Nonnull IForgeRegistryEntry<?> term )
{
return Objects.requireNonNull( term.getRegistryName() ).toString();
}
@Nonnull
private String extendedName( @Nonnull IForgeRegistryEntry<?> term, @Nonnull String suffix )
{
return extend( Objects.requireNonNull( term.getRegistryName() ), suffix );
}
@Nonnull
private String extend( @Nonnull ResourceLocation location, @Nonnull String suffix )
{
return new ResourceLocation( location.getNamespace(), location.getPath() + suffix ).toString();
}
}

View File

@ -25,7 +25,7 @@ public static void gather( GatherDataEvent event )
generator.addProvider( new RecipeGenerator( generator ) );
generator.addProvider( new LootTableGenerator( generator ) );
generator.addProvider( new BlockModelProvider( generator, existingFiles ) );
generator.addProvider( new ModelProvider( generator, BlockModelGenerator::addBlockModels, ItemModelGenerator::addItemModels ) );
BlockTagsGenerator blockTags = new BlockTagsGenerator( generator, existingFiles );
generator.addProvider( blockTags );

View File

@ -0,0 +1,109 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. 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 net.minecraft.data.*;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import java.util.Optional;
import static net.minecraft.data.ModelsResourceUtil.getModelLocation;
public final class ItemModelGenerator
{
private ItemModelGenerator()
{
}
public static void addItemModels( ItemModelProvider generators )
{
registerDisk( generators, Registry.ModItems.DISK.get() );
registerDisk( generators, Registry.ModItems.TREASURE_DISK.get() );
registerPocketComputer( generators, getModelLocation( Registry.ModItems.POCKET_COMPUTER_NORMAL.get() ), false );
registerPocketComputer( generators, getModelLocation( Registry.ModItems.POCKET_COMPUTER_ADVANCED.get() ), false );
registerPocketComputer( generators, new ResourceLocation( ComputerCraft.MOD_ID, "item/pocket_computer_colour" ), true );
generators.generateFlatItem( Registry.ModItems.PRINTED_BOOK.get(), StockModelShapes.FLAT_ITEM );
generators.generateFlatItem( Registry.ModItems.PRINTED_PAGE.get(), StockModelShapes.FLAT_ITEM );
generators.generateFlatItem( Registry.ModItems.PRINTED_PAGES.get(), StockModelShapes.FLAT_ITEM );
}
private static void registerPocketComputer( ItemModelProvider generators, ResourceLocation id, boolean off )
{
createFlatItem( generators, addSuffix( id, "_blinking" ),
new ResourceLocation( ComputerCraft.MOD_ID, "item/pocket_computer_blink" ),
id,
new ResourceLocation( ComputerCraft.MOD_ID, "item/pocket_computer_light" )
);
createFlatItem( generators, addSuffix( id, "_on" ),
new ResourceLocation( ComputerCraft.MOD_ID, "item/pocket_computer_on" ),
id,
new ResourceLocation( ComputerCraft.MOD_ID, "item/pocket_computer_light" )
);
// Don't emit the default/off state for advanced/normal pocket computers, as they have item overrides.
if( off )
{
createFlatItem( generators, id,
new ResourceLocation( ComputerCraft.MOD_ID, "item/pocket_computer_frame" ),
id
);
}
}
private static void registerDisk( ItemModelProvider generators, Item item )
{
createFlatItem( generators, item,
new ResourceLocation( ComputerCraft.MOD_ID, "item/disk_frame" ),
new ResourceLocation( ComputerCraft.MOD_ID, "item/disk_colour" )
);
}
private static void createFlatItem( ItemModelProvider generators, Item item, ResourceLocation... ids )
{
createFlatItem( generators, getModelLocation( item ), ids );
}
/**
* Generate a flat item from an arbitrary number of layers.
*
* @param generators The current item generator helper.
* @param model The model we're writing to.
* @param textures The textures which make up this model.
* @see net.minecraft.client.renderer.model.ItemModelGenerator The parser for this file format.
*/
private static void createFlatItem( ItemModelProvider generators, ResourceLocation model, ResourceLocation... textures )
{
if( textures.length > 5 ) throw new IndexOutOfBoundsException( "Too many layers" );
if( textures.length == 0 ) throw new IndexOutOfBoundsException( "Must have at least one texture" );
if( textures.length == 1 )
{
StockModelShapes.FLAT_ITEM.create( model, ModelTextures.layer0( textures[0] ), generators.output );
return;
}
StockTextureAliases[] slots = new StockTextureAliases[textures.length];
ModelTextures mapping = new ModelTextures();
for( int i = 0; i < textures.length; i++ )
{
StockTextureAliases slot = slots[i] = StockTextureAliases.create( "layer" + i );
mapping.put( slot, textures[i] );
}
new ModelsUtil( Optional.of( new ResourceLocation( "item/generated" ) ), Optional.empty(), slots )
.create( model, mapping, generators.output );
}
private static ResourceLocation addSuffix( ResourceLocation location, String suffix )
{
return new ResourceLocation( location.getNamespace(), location.getPath() + suffix );
}
}

View File

@ -0,0 +1,122 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.data;
import com.google.gson.JsonElement;
import net.minecraft.block.Block;
import net.minecraft.data.*;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nonnull;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* A copy of {@link net.minecraft.data.BlockStateProvider} which accepts a custom generator.
* <p>
* Please don't sue me Mojang. Or at least make these changes to vanilla before doing so!
*/
public class ModelProvider implements IDataProvider
{
private static final Logger LOGGER = LogManager.getLogger();
private final DataGenerator generator;
private final Consumer<BlockModelProvider> blocks;
private final Consumer<ItemModelProvider> items;
public ModelProvider( DataGenerator generator, Consumer<BlockModelProvider> blocks, Consumer<ItemModelProvider> items )
{
this.generator = generator;
this.blocks = blocks;
this.items = items;
}
@Override
public void run( @Nonnull DirectoryCache output )
{
Map<Block, IFinishedBlockState> blockStates = new HashMap<>();
Consumer<IFinishedBlockState> addBlockState = generator -> {
Block block = generator.getBlock();
if( blockStates.containsKey( block ) )
{
throw new IllegalStateException( "Duplicate blockstate definition for " + block );
}
blockStates.put( block, generator );
};
Map<ResourceLocation, Supplier<JsonElement>> models = new HashMap<>();
BiConsumer<ResourceLocation, Supplier<JsonElement>> addModel = ( id, contents ) -> {
if( models.containsKey( id ) ) throw new IllegalStateException( "Duplicate model definition for " + id );
models.put( id, contents );
};
Set<Item> explicitItems = new HashSet<>();
blocks.accept( new BlockModelProvider( addBlockState, addModel, explicitItems::add ) );
items.accept( new ItemModelProvider( addModel ) );
for( Block block : ForgeRegistries.BLOCKS )
{
if( !blockStates.containsKey( block ) ) continue;
Item item = Item.BY_BLOCK.get( block );
if( item == null || explicitItems.contains( item ) ) continue;
ResourceLocation model = ModelsResourceUtil.getModelLocation( item );
if( !models.containsKey( model ) )
{
models.put( model, new BlockModelWriter( ModelsResourceUtil.getModelLocation( block ) ) );
}
}
saveCollection( output, generator.getOutputFolder(), blockStates, ModelProvider::createBlockStatePath );
saveCollection( output, generator.getOutputFolder(), models, ModelProvider::createModelPath );
}
private <T> void saveCollection( DirectoryCache output, Path root, Map<T, ? extends Supplier<JsonElement>> items, BiFunction<Path, T, Path> getLocation )
{
for( Map.Entry<T, ? extends Supplier<JsonElement>> entry : items.entrySet() )
{
Path path = getLocation.apply( root, entry.getKey() );
try
{
PrettyJsonWriter.save( output, entry.getValue().get(), path );
}
catch( Exception exception )
{
LOGGER.error( "Couldn't save {}", path, exception );
}
}
}
private static Path createBlockStatePath( Path path, Block block )
{
ResourceLocation id = ForgeRegistries.BLOCKS.getKey( block );
return path.resolve( "assets/" + id.getNamespace() + "/blockstates/" + id.getPath() + ".json" );
}
private static Path createModelPath( Path path, ResourceLocation id )
{
return path.resolve( "assets/" + id.getNamespace() + "/models/" + id.getPath() + ".json" );
}
@Nonnull
@Override
public String getName()
{
return "Block State Definitions";
}
}

View File

@ -0,0 +1,403 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.data;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.stream.JsonWriter;
import net.minecraft.data.DirectoryCache;
import net.minecraft.data.IDataProvider;
import javax.annotation.Nullable;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
/**
* Alternative version of {@link JsonWriter} which attempts to lay out the JSON in a more compact format.
* <p>
* Yes, this is at least a little deranged.
*/
public class PrettyJsonWriter extends JsonWriter
{
private static final boolean ENABLED = System.getProperty( "cct.pretty-json" ) != null;
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
private static final int MAX_WIDTH = 120;
private final Writer out;
/**
* A stack of objects. This is either a {@link String} (in which case we've received an object key but no value)
* or a {@link DocList} (which either represents an array or object).
*/
private final Deque<Object> stack = new ArrayDeque<>();
public PrettyJsonWriter( Writer out )
{
super( out );
this.out = out;
}
/**
* Create a JSON writer. This will either be a pretty or normal version, depending on whether the global flag is
* set.
*
* @param out The writer to emit to.
* @return The constructed JSON writer.
*/
public static JsonWriter createWriter( Writer out )
{
return ENABLED ? new PrettyJsonWriter( out ) : new JsonWriter( out );
}
public static void save( DirectoryCache cache, JsonElement json, Path path ) throws IOException
{
StringWriter writer = new StringWriter();
GSON.toJson( json, createWriter( writer ) );
String contents = writer.toString();
String hash = IDataProvider.SHA1.hashUnencodedChars( contents ).toString();
if( !Objects.equals( cache.getHash( path ), hash ) || !Files.exists( path ) )
{
Files.createDirectories( path.getParent() );
try( BufferedWriter bufferedwriter = Files.newBufferedWriter( path ) )
{
bufferedwriter.write( contents );
}
}
cache.putNew( path, hash );
}
private void pushValue( Object object ) throws IOException
{
// We've popped our top object, just write a value.
if( stack.isEmpty() )
{
write( out, object, MAX_WIDTH, 0 );
return;
}
// Otherwise we either need to push to our list or finish a record pair.
Object head = stack.getLast();
if( head instanceof DocList )
{
((DocList) head).add( object );
}
else
{
stack.removeLast();
((DocList) stack.getLast()).add( new Pair( (String) head, object ) );
}
}
@Override
public JsonWriter beginArray()
{
stack.add( new DocList( "[", "]" ) );
return this;
}
@Override
public JsonWriter endArray() throws IOException
{
DocList list = (DocList) stack.removeLast();
pushValue( list );
return this;
}
@Override
public JsonWriter beginObject()
{
stack.add( new DocList( "{", "}" ) );
return this;
}
@Override
public JsonWriter endObject() throws IOException
{
return endArray();
}
@Override
public JsonWriter name( String name ) throws IOException
{
stack.add( escapeString( name ) );
return this;
}
@Override
public JsonWriter jsonValue( String value ) throws IOException
{
pushValue( value );
return this;
}
@Override
public JsonWriter value( @Nullable String value ) throws IOException
{
return value == null ? nullValue() : jsonValue( escapeString( value ) );
}
@Override
public JsonWriter nullValue() throws IOException
{
if( !getSerializeNulls() && stack.peekLast() instanceof String )
{
stack.removeLast();
return this;
}
return jsonValue( "null" );
}
@Override
public JsonWriter value( boolean value ) throws IOException
{
return jsonValue( Boolean.toString( value ) );
}
@Override
public JsonWriter value( @Nullable Boolean value ) throws IOException
{
return value == null ? nullValue() : jsonValue( Boolean.toString( value ) );
}
@Override
public JsonWriter value( double value ) throws IOException
{
return jsonValue( Double.toString( value ) );
}
@Override
public JsonWriter value( long value ) throws IOException
{
return jsonValue( Long.toString( value ) );
}
@Override
public JsonWriter value( @Nullable Number value ) throws IOException
{
return value == null ? nullValue() : jsonValue( value.toString() );
}
@Override
public void close() throws IOException
{
if( !stack.isEmpty() ) throw new IllegalArgumentException( "Object is remaining on the stack" );
out.close();
}
/**
* A key/value pair inside a JSON object.
*/
private static final class Pair
{
/**
* The escaped object key.
*/
final String key;
/**
* The object value.
*/
final Object value;
private Pair( String key, Object value )
{
this.key = key;
this.value = value;
}
int width()
{
return key.length() + 2 + PrettyJsonWriter.width( value );
}
int write( Writer out, int space, int indent ) throws IOException
{
out.write( key );
out.write( ": " );
return PrettyJsonWriter.write( out, value, space - key.length() - 2, indent );
}
}
/**
* A list of terms inside a JSON document. Either an array or a JSON object.
*/
private static class DocList
{
final String prefix;
final String suffix;
final List<Object> contents = new ArrayList<>();
int width;
DocList( String prefix, String suffix )
{
this.prefix = prefix;
this.suffix = suffix;
width = prefix.length() + suffix.length();
}
void add( Object value )
{
contents.add( value );
width += width( value ) + (contents.isEmpty() ? 0 : 2);
}
int write( Writer writer, int space, int indent ) throws IOException
{
writer.append( prefix );
if( width <= space )
{
// We've sufficient room on this line, so write everything on one line.
// Take into account the suffix length here, as we ignore it the case we wrap.
space -= prefix.length() + suffix.length();
boolean comma = false;
for( Object value : contents )
{
if( comma )
{
writer.append( ", " );
space -= 2;
}
comma = true;
space = PrettyJsonWriter.write( writer, value, space, indent );
}
}
else
{
// We've run out of room, so write each value on separate lines.
String indentStr = Strings.repeat( " ", indent );
writer.append( "\n " ).append( indentStr );
boolean comma = false;
for( Object value : contents )
{
if( comma )
{
writer.append( ",\n " ).append( indentStr );
}
comma = true;
PrettyJsonWriter.write( writer, value, MAX_WIDTH - indent - 2, indent + 2 );
}
writer.append( "\n" ).append( indentStr );
}
writer.append( suffix );
return space;
}
}
/**
* Estimate the width of an object.
*
* @param object The object to emit.
* @return The computed width.
*/
private static int width( Object object )
{
if( object instanceof String ) return ((String) object).length();
if( object instanceof DocList ) return ((DocList) object).width;
if( object instanceof Pair ) return ((Pair) object).width();
throw new IllegalArgumentException( "Not a valid document" );
}
/**
* Write a value to the output stream.
*
* @param writer The writer to emit to.
* @param object The object to write.
* @param space The amount of space left on this line. Will be no larger than {@link #MAX_WIDTH}, but may be negative.
* @param indent The current indent.
* @return The new amount of space left on this line. This is undefined if the writer wraps.
* @throws IOException If the underlying writer fails.
*/
private static int write( Writer writer, Object object, int space, int indent ) throws IOException
{
if( object instanceof String )
{
String str = (String) object;
writer.write( str );
return space - str.length();
}
else if( object instanceof DocList )
{
return ((DocList) object).write( writer, space, indent );
}
else if( object instanceof Pair )
{
return ((Pair) object).write( writer, space, indent );
}
else
{
throw new IllegalArgumentException( "Not a valid document" );
}
}
private static String escapeString( String value )
{
StringBuilder builder = new StringBuilder();
builder.append( '\"' );
int length = value.length();
for( int i = 0; i < length; i++ )
{
char c = value.charAt( i );
String replacement = null;
if( c < STRING_REPLACE.length )
{
replacement = STRING_REPLACE[c];
}
else if( c == '\u2028' )
{
replacement = "\\u2028";
}
else if( c == '\u2029' )
{
replacement = "\\u2029";
}
if( replacement == null )
{
builder.append( c );
}
else
{
builder.append( replacement );
}
}
builder.append( '\"' );
return builder.toString();
}
private static final String[] STRING_REPLACE = new String[128];
static
{
for( int i = 0; i <= 0x1f; i++ ) STRING_REPLACE[i] = String.format( "\\u%04x", i );
STRING_REPLACE['"'] = "\\\"";
STRING_REPLACE['\\'] = "\\\\";
STRING_REPLACE['\t'] = "\\t";
STRING_REPLACE['\b'] = "\\b";
STRING_REPLACE['\n'] = "\\n";
STRING_REPLACE['\r'] = "\\r";
STRING_REPLACE['\f'] = "\\f";
}
}

View File

@ -45,12 +45,12 @@ public class BlockCable extends BlockGeneric implements IWaterLoggable
public static final EnumProperty<CableModemVariant> MODEM = EnumProperty.create( "modem", CableModemVariant.class );
public static final BooleanProperty CABLE = BooleanProperty.create( "cable" );
private static final BooleanProperty NORTH = BooleanProperty.create( "north" );
private static final BooleanProperty SOUTH = BooleanProperty.create( "south" );
private static final BooleanProperty EAST = BooleanProperty.create( "east" );
private static final BooleanProperty WEST = BooleanProperty.create( "west" );
private static final BooleanProperty UP = BooleanProperty.create( "up" );
private static final BooleanProperty DOWN = BooleanProperty.create( "down" );
public static final BooleanProperty NORTH = BooleanProperty.create( "north" );
public static final BooleanProperty SOUTH = BooleanProperty.create( "south" );
public static final BooleanProperty EAST = BooleanProperty.create( "east" );
public static final BooleanProperty WEST = BooleanProperty.create( "west" );
public static final BooleanProperty UP = BooleanProperty.create( "up" );
public static final BooleanProperty DOWN = BooleanProperty.create( "down" );
static final EnumMap<Direction, BooleanProperty> CONNECTIONS =
new EnumMap<>( new ImmutableMap.Builder<Direction, BooleanProperty>()

View File

@ -32,8 +32,8 @@
public class BlockPrinter extends BlockGeneric
{
private static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
static final BooleanProperty TOP = BooleanProperty.create( "top" );
static final BooleanProperty BOTTOM = BooleanProperty.create( "bottom" );
public static final BooleanProperty TOP = BooleanProperty.create( "top" );
public static final BooleanProperty BOTTOM = BooleanProperty.create( "bottom" );
public BlockPrinter( Properties settings )
{

View File

@ -5,6 +5,7 @@
*/
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.AbstractTurtleUpgrade;
@ -12,7 +13,6 @@
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleUpgradeType;
import net.minecraft.block.Blocks;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -21,8 +21,8 @@
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" );
private static final ResourceLocation leftModel = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_crafting_table_left" );
private static final ResourceLocation rightModel = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_crafting_table_right" );
public TurtleCraftingTable( ResourceLocation id )
{

Some files were not shown because too many files have changed in this diff Show More