diff --git a/common/src/generated/resources/assets/railways/blockstates/buffer.json b/common/src/generated/resources/assets/railways/blockstates/buffer.json index 1e953fdac..8633d6916 100644 --- a/common/src/generated/resources/assets/railways/blockstates/buffer.json +++ b/common/src/generated/resources/assets/railways/blockstates/buffer.json @@ -1,32 +1,62 @@ { "variants": { - "facing=east,style=short": { + "diagonal=false,facing=east,style=short": { "model": "railways:block/buffer/buffer_stop_short_support", "y": 90 }, - "facing=east,style=standard": { + "diagonal=false,facing=east,style=standard": { "model": "railways:block/buffer/buffer_stop", "y": 90 }, - "facing=north,style=short": { + "diagonal=false,facing=north,style=short": { "model": "railways:block/buffer/buffer_stop_short_support" }, - "facing=north,style=standard": { + "diagonal=false,facing=north,style=standard": { "model": "railways:block/buffer/buffer_stop" }, - "facing=south,style=short": { + "diagonal=false,facing=south,style=short": { "model": "railways:block/buffer/buffer_stop_short_support", "y": 180 }, - "facing=south,style=standard": { + "diagonal=false,facing=south,style=standard": { "model": "railways:block/buffer/buffer_stop", "y": 180 }, - "facing=west,style=short": { + "diagonal=false,facing=west,style=short": { "model": "railways:block/buffer/buffer_stop_short_support", "y": 270 }, - "facing=west,style=standard": { + "diagonal=false,facing=west,style=standard": { + "model": "railways:block/buffer/buffer_stop", + "y": 270 + }, + "diagonal=true,facing=east,style=short": { + "model": "railways:block/buffer/buffer_stop_short_support", + "y": 90 + }, + "diagonal=true,facing=east,style=standard": { + "model": "railways:block/buffer/buffer_stop", + "y": 90 + }, + "diagonal=true,facing=north,style=short": { + "model": "railways:block/buffer/buffer_stop_short_support" + }, + "diagonal=true,facing=north,style=standard": { + "model": "railways:block/buffer/buffer_stop" + }, + "diagonal=true,facing=south,style=short": { + "model": "railways:block/buffer/buffer_stop_short_support", + "y": 180 + }, + "diagonal=true,facing=south,style=standard": { + "model": "railways:block/buffer/buffer_stop", + "y": 180 + }, + "diagonal=true,facing=west,style=short": { + "model": "railways:block/buffer/buffer_stop_short_support", + "y": 270 + }, + "diagonal=true,facing=west,style=standard": { "model": "railways:block/buffer/buffer_stop", "y": 270 } diff --git a/common/src/generated/resources/assets/railways/blockstates/buffer_mono.json b/common/src/generated/resources/assets/railways/blockstates/buffer_mono.json index a7b5d56b7..564a18bdf 100644 --- a/common/src/generated/resources/assets/railways/blockstates/buffer_mono.json +++ b/common/src/generated/resources/assets/railways/blockstates/buffer_mono.json @@ -1,106 +1,208 @@ { "variants": { - "facing=east,style=mono,upside_down=false": { + "diagonal=false,facing=east,style=mono,upside_down=false": { "model": "railways:block/buffer/monorail_mono_buffer_stop", - "y": 90 + "y": 270 }, - "facing=east,style=mono,upside_down=true": { + "diagonal=false,facing=east,style=mono,upside_down=true": { "model": "railways:block/buffer/monorail_mono_buffer_stop", "x": 180, - "y": 270 + "y": 90 }, - "facing=east,style=side,upside_down=false": { + "diagonal=false,facing=east,style=side,upside_down=false": { "model": "railways:block/buffer/monorail_side_buffer_stop", - "y": 90 + "y": 270 }, - "facing=east,style=side,upside_down=true": { + "diagonal=false,facing=east,style=side,upside_down=true": { "model": "railways:block/buffer/monorail_side_buffer_stop", "x": 180, + "y": 90 + }, + "diagonal=false,facing=east,style=standard,upside_down=false": { + "model": "railways:block/buffer/monorail_buffer_stop", "y": 270 }, - "facing=east,style=standard,upside_down=false": { + "diagonal=false,facing=east,style=standard,upside_down=true": { "model": "railways:block/buffer/monorail_buffer_stop", + "x": 180, "y": 90 }, - "facing=east,style=standard,upside_down=true": { + "diagonal=false,facing=north,style=mono,upside_down=false": { + "model": "railways:block/buffer/monorail_mono_buffer_stop", + "y": 180 + }, + "diagonal=false,facing=north,style=mono,upside_down=true": { + "model": "railways:block/buffer/monorail_mono_buffer_stop", + "x": 180 + }, + "diagonal=false,facing=north,style=side,upside_down=false": { + "model": "railways:block/buffer/monorail_side_buffer_stop", + "y": 180 + }, + "diagonal=false,facing=north,style=side,upside_down=true": { + "model": "railways:block/buffer/monorail_side_buffer_stop", + "x": 180 + }, + "diagonal=false,facing=north,style=standard,upside_down=false": { "model": "railways:block/buffer/monorail_buffer_stop", - "x": 180, - "y": 270 + "y": 180 }, - "facing=north,style=mono,upside_down=false": { + "diagonal=false,facing=north,style=standard,upside_down=true": { + "model": "railways:block/buffer/monorail_buffer_stop", + "x": 180 + }, + "diagonal=false,facing=south,style=mono,upside_down=false": { "model": "railways:block/buffer/monorail_mono_buffer_stop" }, - "facing=north,style=mono,upside_down=true": { + "diagonal=false,facing=south,style=mono,upside_down=true": { "model": "railways:block/buffer/monorail_mono_buffer_stop", "x": 180, "y": 180 }, - "facing=north,style=side,upside_down=false": { + "diagonal=false,facing=south,style=side,upside_down=false": { "model": "railways:block/buffer/monorail_side_buffer_stop" }, - "facing=north,style=side,upside_down=true": { + "diagonal=false,facing=south,style=side,upside_down=true": { "model": "railways:block/buffer/monorail_side_buffer_stop", "x": 180, "y": 180 }, - "facing=north,style=standard,upside_down=false": { + "diagonal=false,facing=south,style=standard,upside_down=false": { "model": "railways:block/buffer/monorail_buffer_stop" }, - "facing=north,style=standard,upside_down=true": { + "diagonal=false,facing=south,style=standard,upside_down=true": { "model": "railways:block/buffer/monorail_buffer_stop", "x": 180, "y": 180 }, - "facing=south,style=mono,upside_down=false": { + "diagonal=false,facing=west,style=mono,upside_down=false": { "model": "railways:block/buffer/monorail_mono_buffer_stop", - "y": 180 + "y": 90 }, - "facing=south,style=mono,upside_down=true": { + "diagonal=false,facing=west,style=mono,upside_down=true": { "model": "railways:block/buffer/monorail_mono_buffer_stop", - "x": 180 + "x": 180, + "y": 270 }, - "facing=south,style=side,upside_down=false": { + "diagonal=false,facing=west,style=side,upside_down=false": { "model": "railways:block/buffer/monorail_side_buffer_stop", - "y": 180 + "y": 90 }, - "facing=south,style=side,upside_down=true": { + "diagonal=false,facing=west,style=side,upside_down=true": { "model": "railways:block/buffer/monorail_side_buffer_stop", - "x": 180 + "x": 180, + "y": 270 }, - "facing=south,style=standard,upside_down=false": { + "diagonal=false,facing=west,style=standard,upside_down=false": { "model": "railways:block/buffer/monorail_buffer_stop", - "y": 180 + "y": 90 }, - "facing=south,style=standard,upside_down=true": { + "diagonal=false,facing=west,style=standard,upside_down=true": { "model": "railways:block/buffer/monorail_buffer_stop", - "x": 180 + "x": 180, + "y": 270 }, - "facing=west,style=mono,upside_down=false": { + "diagonal=true,facing=east,style=mono,upside_down=false": { "model": "railways:block/buffer/monorail_mono_buffer_stop", "y": 270 }, - "facing=west,style=mono,upside_down=true": { + "diagonal=true,facing=east,style=mono,upside_down=true": { "model": "railways:block/buffer/monorail_mono_buffer_stop", "x": 180, "y": 90 }, - "facing=west,style=side,upside_down=false": { + "diagonal=true,facing=east,style=side,upside_down=false": { "model": "railways:block/buffer/monorail_side_buffer_stop", "y": 270 }, - "facing=west,style=side,upside_down=true": { + "diagonal=true,facing=east,style=side,upside_down=true": { "model": "railways:block/buffer/monorail_side_buffer_stop", "x": 180, "y": 90 }, - "facing=west,style=standard,upside_down=false": { + "diagonal=true,facing=east,style=standard,upside_down=false": { "model": "railways:block/buffer/monorail_buffer_stop", "y": 270 }, - "facing=west,style=standard,upside_down=true": { + "diagonal=true,facing=east,style=standard,upside_down=true": { + "model": "railways:block/buffer/monorail_buffer_stop", + "x": 180, + "y": 90 + }, + "diagonal=true,facing=north,style=mono,upside_down=false": { + "model": "railways:block/buffer/monorail_mono_buffer_stop", + "y": 180 + }, + "diagonal=true,facing=north,style=mono,upside_down=true": { + "model": "railways:block/buffer/monorail_mono_buffer_stop", + "x": 180 + }, + "diagonal=true,facing=north,style=side,upside_down=false": { + "model": "railways:block/buffer/monorail_side_buffer_stop", + "y": 180 + }, + "diagonal=true,facing=north,style=side,upside_down=true": { + "model": "railways:block/buffer/monorail_side_buffer_stop", + "x": 180 + }, + "diagonal=true,facing=north,style=standard,upside_down=false": { + "model": "railways:block/buffer/monorail_buffer_stop", + "y": 180 + }, + "diagonal=true,facing=north,style=standard,upside_down=true": { + "model": "railways:block/buffer/monorail_buffer_stop", + "x": 180 + }, + "diagonal=true,facing=south,style=mono,upside_down=false": { + "model": "railways:block/buffer/monorail_mono_buffer_stop" + }, + "diagonal=true,facing=south,style=mono,upside_down=true": { + "model": "railways:block/buffer/monorail_mono_buffer_stop", + "x": 180, + "y": 180 + }, + "diagonal=true,facing=south,style=side,upside_down=false": { + "model": "railways:block/buffer/monorail_side_buffer_stop" + }, + "diagonal=true,facing=south,style=side,upside_down=true": { + "model": "railways:block/buffer/monorail_side_buffer_stop", + "x": 180, + "y": 180 + }, + "diagonal=true,facing=south,style=standard,upside_down=false": { + "model": "railways:block/buffer/monorail_buffer_stop" + }, + "diagonal=true,facing=south,style=standard,upside_down=true": { "model": "railways:block/buffer/monorail_buffer_stop", "x": 180, + "y": 180 + }, + "diagonal=true,facing=west,style=mono,upside_down=false": { + "model": "railways:block/buffer/monorail_mono_buffer_stop", "y": 90 + }, + "diagonal=true,facing=west,style=mono,upside_down=true": { + "model": "railways:block/buffer/monorail_mono_buffer_stop", + "x": 180, + "y": 270 + }, + "diagonal=true,facing=west,style=side,upside_down=false": { + "model": "railways:block/buffer/monorail_side_buffer_stop", + "y": 90 + }, + "diagonal=true,facing=west,style=side,upside_down=true": { + "model": "railways:block/buffer/monorail_side_buffer_stop", + "x": 180, + "y": 270 + }, + "diagonal=true,facing=west,style=standard,upside_down=false": { + "model": "railways:block/buffer/monorail_buffer_stop", + "y": 90 + }, + "diagonal=true,facing=west,style=standard,upside_down=true": { + "model": "railways:block/buffer/monorail_buffer_stop", + "x": 180, + "y": 270 } } } \ No newline at end of file diff --git a/common/src/generated/resources/assets/railways/blockstates/buffer_narrow.json b/common/src/generated/resources/assets/railways/blockstates/buffer_narrow.json index e8d118780..080929bb1 100644 --- a/common/src/generated/resources/assets/railways/blockstates/buffer_narrow.json +++ b/common/src/generated/resources/assets/railways/blockstates/buffer_narrow.json @@ -1,32 +1,62 @@ { "variants": { - "facing=east,style=mono": { + "diagonal=false,facing=east,style=mono": { "model": "railways:block/buffer/narrow_mono_buffer_stop", "y": 90 }, - "facing=east,style=standard": { + "diagonal=false,facing=east,style=standard": { "model": "railways:block/buffer/narrow_buffer_stop", "y": 90 }, - "facing=north,style=mono": { + "diagonal=false,facing=north,style=mono": { "model": "railways:block/buffer/narrow_mono_buffer_stop" }, - "facing=north,style=standard": { + "diagonal=false,facing=north,style=standard": { "model": "railways:block/buffer/narrow_buffer_stop" }, - "facing=south,style=mono": { + "diagonal=false,facing=south,style=mono": { "model": "railways:block/buffer/narrow_mono_buffer_stop", "y": 180 }, - "facing=south,style=standard": { + "diagonal=false,facing=south,style=standard": { "model": "railways:block/buffer/narrow_buffer_stop", "y": 180 }, - "facing=west,style=mono": { + "diagonal=false,facing=west,style=mono": { "model": "railways:block/buffer/narrow_mono_buffer_stop", "y": 270 }, - "facing=west,style=standard": { + "diagonal=false,facing=west,style=standard": { + "model": "railways:block/buffer/narrow_buffer_stop", + "y": 270 + }, + "diagonal=true,facing=east,style=mono": { + "model": "railways:block/buffer/narrow_mono_buffer_stop", + "y": 90 + }, + "diagonal=true,facing=east,style=standard": { + "model": "railways:block/buffer/narrow_buffer_stop", + "y": 90 + }, + "diagonal=true,facing=north,style=mono": { + "model": "railways:block/buffer/narrow_mono_buffer_stop" + }, + "diagonal=true,facing=north,style=standard": { + "model": "railways:block/buffer/narrow_buffer_stop" + }, + "diagonal=true,facing=south,style=mono": { + "model": "railways:block/buffer/narrow_mono_buffer_stop", + "y": 180 + }, + "diagonal=true,facing=south,style=standard": { + "model": "railways:block/buffer/narrow_buffer_stop", + "y": 180 + }, + "diagonal=true,facing=west,style=mono": { + "model": "railways:block/buffer/narrow_mono_buffer_stop", + "y": 270 + }, + "diagonal=true,facing=west,style=standard": { "model": "railways:block/buffer/narrow_buffer_stop", "y": 270 } diff --git a/common/src/generated/resources/assets/railways/blockstates/buffer_wide.json b/common/src/generated/resources/assets/railways/blockstates/buffer_wide.json index 60e0dae76..20490f1c1 100644 --- a/common/src/generated/resources/assets/railways/blockstates/buffer_wide.json +++ b/common/src/generated/resources/assets/railways/blockstates/buffer_wide.json @@ -1,17 +1,32 @@ { "variants": { - "facing=east": { + "diagonal=false,facing=east": { "model": "railways:block/buffer/wide_buffer_stop", "y": 90 }, - "facing=north": { + "diagonal=false,facing=north": { "model": "railways:block/buffer/wide_buffer_stop" }, - "facing=south": { + "diagonal=false,facing=south": { "model": "railways:block/buffer/wide_buffer_stop", "y": 180 }, - "facing=west": { + "diagonal=false,facing=west": { + "model": "railways:block/buffer/wide_buffer_stop", + "y": 270 + }, + "diagonal=true,facing=east": { + "model": "railways:block/buffer/wide_buffer_stop", + "y": 90 + }, + "diagonal=true,facing=north": { + "model": "railways:block/buffer/wide_buffer_stop" + }, + "diagonal=true,facing=south": { + "model": "railways:block/buffer/wide_buffer_stop", + "y": 180 + }, + "diagonal=true,facing=west": { "model": "railways:block/buffer/wide_buffer_stop", "y": 270 } diff --git a/common/src/generated/resources/assets/railways/lang/en_ud.json b/common/src/generated/resources/assets/railways/lang/en_ud.json index b743b6bb2..2f241a576 100644 --- a/common/src/generated/resources/assets/railways/lang/en_ud.json +++ b/common/src/generated/resources/assets/railways/lang/en_ud.json @@ -1084,6 +1084,7 @@ "railways.bogeys.styles.blomberg": "bɹǝqɯoןᗺ", "railways.bogeys.styles.coilspring": "buıɹdsןıoƆ", "railways.bogeys.styles.freight": "ʇɥbıǝɹℲ", + "railways.bogeys.styles.handcar": "ɹɐɔpuɐH", "railways.bogeys.styles.heavyweight": "ʇɥbıǝʍʎʌɐǝH", "railways.bogeys.styles.invisible": "ǝןqısıʌuI", "railways.bogeys.styles.invisible_monobogey": "ʎǝboqouoW ǝןqısıʌuI", @@ -1221,8 +1222,8 @@ "railways.tooltip.coupler.error.mode_not_permitted": "ǝpoɯ ʇuǝɹɹnɔ uı pǝʇʇıɯɹǝd ʇou uoıʇɔⱯ", "railways.tooltip.coupler.header": "uoıʇɐɯɹoɟuI ɹǝןdnoƆ", "railways.tooltip.coupler.mode": ":ǝpoW ɹǝןdnoƆ", - "railways.tooltip.coupler.train1": "%sɹ§ :Ɩ uıɐɹ⟘ן§", - "railways.tooltip.coupler.train2": "%sɹ§ :ᄅ uıɐɹ⟘ן§", + "railways.tooltip.coupler.train1": "%sɹ§Â :Ɩ uıɐɹ⟘ן§Â", + "railways.tooltip.coupler.train2": "%sɹ§Â :ᄅ uıɐɹ⟘ן§Â", "railways.tooltip.switch.header": "uoıʇɐɯɹoɟuI ɥɔʇıʍS", "railways.tooltip.switch.state": ":ǝʇɐʇS ɥɔʇıʍS", "railways.whistle.clear": "˙buıpuıq ǝןʇsıɥʍ pǝɹɐǝןƆ", @@ -1238,9 +1239,9 @@ "railways.whistle.tool.bound_auto_clear": "uıɐɹʇ punoq ǝɥʇ ɟo ǝןnpǝɥɔs oʇnɐ ǝɥʇ ssıɯsıp oʇ ɹıɐ uo ɹO", "railways.whistle.tool.bound_auto_usage": "suıɐɹʇ uoɯɯns oʇ suoıʇɐʇs uo sǝןʇsıɥʍ ǝsn uɐɔ sɹǝʎoןdǝᗡ", "railways.whistle.tool.bound_usage": "¡uıɐɹʇ punoq ǝɥʇ uoɯɯns oʇ uoıʇɐʇs ɹo ʞɔɐɹʇ ɐ uo ǝs∩", - "railways.whistle.tool.conductor_id": "ɹ§%s9§ :ɹoʇɔnpuoƆ", + "railways.whistle.tool.conductor_id": "ɹ§Â%s9§Â :ɹoʇɔnpuoƆ", "railways.whistle.tool.not_bound": "˙puıq oʇ uıɐɹʇ ɐ buıpıɹ ɹoʇɔnpuoɔ ɐ uo ǝsn 'punoq ʇoN", - "railways.whistle.tool.train_id": ")ɹ§%2$s9§( ɹ§%1$sǝ§ :uıɐɹ⟘", + "railways.whistle.tool.train_id": ")ɹ§Â%2$s9§Â( ɹ§Â%1$sǝ§Â :uıɐɹ⟘", "sounds.railways.conductor_whistle": "sǝןʇsıɥM ɹoʇɔnpuoƆ", "tag.block.railways.conductor_spy_usable": "ǝןqɐsn ʎds ɹoʇɔnpuoƆ", "tag.block.railways.locometal": "ןɐʇǝɯoɔoꞀ", diff --git a/common/src/generated/resources/assets/railways/lang/en_us.json b/common/src/generated/resources/assets/railways/lang/en_us.json index 9b20402dc..2cbeb3669 100644 --- a/common/src/generated/resources/assets/railways/lang/en_us.json +++ b/common/src/generated/resources/assets/railways/lang/en_us.json @@ -1084,6 +1084,7 @@ "railways.bogeys.styles.blomberg": "Blomberg", "railways.bogeys.styles.coilspring": "Coilspring", "railways.bogeys.styles.freight": "Freight", + "railways.bogeys.styles.handcar": "Handcar", "railways.bogeys.styles.heavyweight": "Heavyweight", "railways.bogeys.styles.invisible": "Invisible", "railways.bogeys.styles.invisible_monobogey": "Invisible Monobogey", @@ -1221,8 +1222,8 @@ "railways.tooltip.coupler.error.mode_not_permitted": "Action not permitted in current mode", "railways.tooltip.coupler.header": "Coupler Information", "railways.tooltip.coupler.mode": "Coupler Mode:", - "railways.tooltip.coupler.train1": "§lTrain 1: §r%s", - "railways.tooltip.coupler.train2": "§lTrain 2: §r%s", + "railways.tooltip.coupler.train1": "§lTrain 1: §r%s", + "railways.tooltip.coupler.train2": "§lTrain 2: §r%s", "railways.tooltip.switch.header": "Switch Information", "railways.tooltip.switch.state": "Switch State:", "railways.whistle.clear": "Cleared whistle binding.", @@ -1238,9 +1239,9 @@ "railways.whistle.tool.bound_auto_clear": "Or on air to dismiss the auto schedule of the bound train", "railways.whistle.tool.bound_auto_usage": "Deployers can use whistles on stations to summon trains", "railways.whistle.tool.bound_usage": "Use on a track or station to summon the bound train!", - "railways.whistle.tool.conductor_id": "Conductor: §6%s§r", + "railways.whistle.tool.conductor_id": "Conductor: §6%s§r", "railways.whistle.tool.not_bound": "Not bound, use on a conductor riding a train to bind.", - "railways.whistle.tool.train_id": "Train: §e%1$s§r (§6%2$s§r)", + "railways.whistle.tool.train_id": "Train: §e%1$s§r (§6%2$s§r)", "sounds.railways.conductor_whistle": "Conductor Whistles", "tag.block.railways.conductor_spy_usable": "Conductor spy usable", "tag.block.railways.locometal": "Locometal", diff --git a/common/src/main/java/com/railwayteam/railways/content/buffer/BufferBlockPlaceContext.java b/common/src/main/java/com/railwayteam/railways/content/buffer/BufferBlockPlaceContext.java index 5904ec468..88789eb49 100644 --- a/common/src/main/java/com/railwayteam/railways/content/buffer/BufferBlockPlaceContext.java +++ b/common/src/main/java/com/railwayteam/railways/content/buffer/BufferBlockPlaceContext.java @@ -30,35 +30,38 @@ import org.jetbrains.annotations.Nullable; public class BufferBlockPlaceContext extends BlockPlaceContext { + public final Direction facing; @Nullable public final TrackBufferBlock overrideBlock; + public final boolean diagonal; + private BufferBlockPlaceContext(Level level, @Nullable Player player, InteractionHand interactionHand, ItemStack itemStack, BlockHitResult blockHitResult, - Direction facing, @Nullable TrackBufferBlock overrideBlock) { + Direction facing, @Nullable TrackBufferBlock overrideBlock, boolean diagonal) { super(level, player, interactionHand, itemStack, blockHitResult); this.facing = facing; this.overrideBlock = overrideBlock; + this.diagonal = diagonal; } - - public static BufferBlockPlaceContext at(BlockPlaceContext context, BlockPos pos, Direction direction, Direction facing, @Nullable TrackBufferBlock overrideBlock) { + + public static BufferBlockPlaceContext at(BlockPlaceContext context, BlockPos pos, Direction direction, Direction facing, @Nullable TrackBufferBlock overrideBlock, boolean diagonal) { return new BufferBlockPlaceContext( - context.getLevel(), - context.getPlayer(), - context.getHand(), - context.getItemInHand(), - new BlockHitResult( - new Vec3( - (double)pos.getX() + 0.5 + (double)direction.getStepX() * 0.5, - (double)pos.getY() + 0.5 + (double)direction.getStepY() * 0.5, - (double)pos.getZ() + 0.5 + (double)direction.getStepZ() * 0.5 + context.getLevel(), + context.getPlayer(), + context.getHand(), + context.getItemInHand(), + new BlockHitResult( + new Vec3( + (double) pos.getX() + 0.5 + (double) direction.getStepX() * 0.5, + (double) pos.getY() + 0.5 + (double) direction.getStepY() * 0.5, + (double) pos.getZ() + 0.5 + (double) direction.getStepZ() * 0.5 + ), + direction, + pos, + false ), - direction, - pos, - false - ), - facing, - overrideBlock + facing, overrideBlock, diagonal ); } } diff --git a/common/src/main/java/com/railwayteam/railways/content/buffer/TrackBufferBlock.java b/common/src/main/java/com/railwayteam/railways/content/buffer/TrackBufferBlock.java index 00f164dbf..d152eac25 100644 --- a/common/src/main/java/com/railwayteam/railways/content/buffer/TrackBufferBlock.java +++ b/common/src/main/java/com/railwayteam/railways/content/buffer/TrackBufferBlock.java @@ -39,6 +39,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.Shapes; @@ -52,9 +53,15 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault public abstract class TrackBufferBlock extends HorizontalDirectionalBlock implements IBE, IWrenchable, ProperWaterloggedBlock { + + public static final BooleanProperty DIAGONAL = BooleanProperty.create("diagonal"); + protected TrackBufferBlock(Properties pProperties) { super(pProperties); - registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false)); + registerDefaultState(defaultBlockState() + .setValue(FACING, Direction.NORTH) + .setValue(WATERLOGGED, false) + .setValue(DIAGONAL, false)); } @Override @@ -65,13 +72,13 @@ protected TrackBufferBlock(Properties pProperties) { @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { - super.createBlockStateDefinition(builder.add(FACING, WATERLOGGED)); + super.createBlockStateDefinition(builder.add(FACING, WATERLOGGED, DIAGONAL)); } @Override @SuppressWarnings("deprecation") public void onRemove(@NotNull BlockState state, @NotNull Level worldIn, - @NotNull BlockPos pos, @NotNull BlockState newState, boolean isMoving) { + @NotNull BlockPos pos, @NotNull BlockState newState, boolean isMoving) { IBE.onRemove(state, worldIn, pos, newState); } @@ -97,7 +104,7 @@ public FluidState getFluidState(BlockState state) { public BlockState getStateForPlacement(BlockPlaceContext context) { BlockState state = super.getStateForPlacement(context); if (state != null && context instanceof BufferBlockPlaceContext bufferBlockPlaceContext) { - state = state.setValue(FACING, bufferBlockPlaceContext.facing); + state = state.setValue(FACING, bufferBlockPlaceContext.facing).setValue(DIAGONAL, bufferBlockPlaceContext.diagonal); } return withWater(state, context); } @@ -123,9 +130,20 @@ public VoxelShape getOcclusionShape(BlockState state, BlockGetter level, BlockPo @SuppressWarnings("deprecation") @Override public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, - BlockHitResult pHit) { + BlockHitResult pHit) { if (AdventureUtils.isAdventure(pPlayer)) return InteractionResult.PASS; return onBlockEntityUse(pLevel, pPos, be -> be.applyDyeIfValid(pPlayer.getItemInHand(pHand))); } + + public static int getBaseModelYRotationOf(BlockState state) { + return getBaseModelYRotationOf(state, 0); + } + + public static int getBaseModelYRotationOf(BlockState state, int offset) { + return (int) ( + (state.getValue(NarrowTrackBufferBlock.FACING).toYRot() + 180) + offset + ) % 360; + } + } diff --git a/common/src/main/java/com/railwayteam/railways/content/buffer/TrackBufferBlockItem.java b/common/src/main/java/com/railwayteam/railways/content/buffer/TrackBufferBlockItem.java index b78f058bf..43e94c4e6 100644 --- a/common/src/main/java/com/railwayteam/railways/content/buffer/TrackBufferBlockItem.java +++ b/common/src/main/java/com/railwayteam/railways/content/buffer/TrackBufferBlockItem.java @@ -54,15 +54,15 @@ import org.jetbrains.annotations.Nullable; public class TrackBufferBlockItem extends TrackTargetingBlockItem { - + public static NonNullBiFunction ofType(EdgePointType type) { return (b, p) -> new TrackBufferBlockItem(b, p, type); } - + public TrackBufferBlockItem(Block pBlock, Properties pProperties, EdgePointType type) { super(pBlock, pProperties, type); } - + @Nullable @Override protected BlockState getPlacementState(@NotNull BlockPlaceContext context) { @@ -72,16 +72,16 @@ protected BlockState getPlacementState(@NotNull BlockPlaceContext context) { } return super.getPlacementState(context); } - + private static boolean isOkShape(BlockState state) { TrackShape shape = state.getValue(TrackBlock.SHAPE); return switch (shape) { - case ZO, XO, - TE, TN, TS, TW -> true; + case ZO, XO, PD, ND, + TE, TN, TS, TW -> true; default -> false; }; } - + @Override public InteractionResult useOn(UseOnContext context) { ItemStack stack = context.getItemInHand(); @@ -89,41 +89,46 @@ public InteractionResult useOn(UseOnContext context) { Level level = context.getLevel(); BlockState state = level.getBlockState(pos); Player player = context.getPlayer(); - + if (player == null) return InteractionResult.FAIL; - + if (state.getBlock() instanceof ITrackBlock track) { if (level.isClientSide) return InteractionResult.SUCCESS; - + Vec3 lookAngle = player.getLookAngle(); Pair nearestTrackAxis = track.getNearestTrackAxis(level, pos, state, lookAngle); - boolean front = nearestTrackAxis.getSecond() == AxisDirection.POSITIVE; - Axis axis = Direction.getNearest(nearestTrackAxis.getFirst().x, nearestTrackAxis.getFirst().y, nearestTrackAxis.getFirst().z).getAxis(); + boolean front = nearestTrackAxis.getSecond() == AxisDirection.NEGATIVE; + Vec3 biasedDirection = nearestTrackAxis.getFirst().yRot(10); + Axis axis = Direction.getNearest( + biasedDirection.x, + biasedDirection.y, + biasedDirection.z + ).getAxis(); EdgePointType type = getType(stack); - + MutableObject result = new MutableObject<>(null); withGraphLocation(level, pos, front, null, type, (overlap, location) -> result.setValue(overlap)); - + if (result.getValue().feedback != null) { player.displayClientMessage(Lang.translateDirect(result.getValue().feedback) - .withStyle(ChatFormatting.RED), true); + .withStyle(ChatFormatting.RED), true); AllSoundEvents.DENY.play(level, null, pos, .5f, 1); return InteractionResult.FAIL; } if (!isOkShape(state)) { player.displayClientMessage(Components.translatable("railways.buffer.invalid_shape") - .withStyle(ChatFormatting.RED), true); + .withStyle(ChatFormatting.RED), true); AllSoundEvents.DENY.play(level, null, pos, .5f, 1); return InteractionResult.FAIL; } - + CompoundTag stackTag = stack.getOrCreateTag(); stack.setTag(stackTag); - + CompoundTag oldTeTag = stackTag.getCompound("BlockEntityTag"); - + CompoundTag teTag = new CompoundTag(); if (oldTeTag != null) { if (oldTeTag.contains("Material", Tag.TAG_COMPOUND)) @@ -134,10 +139,10 @@ public InteractionResult useOn(UseOnContext context) { teTag.put("Color", oldTeTag.get("Color")); } teTag.putBoolean("TargetDirection", front); - + BlockPos placedPos = pos.above(); Direction placeDirection = Direction.UP; - + TrackBufferBlock overrideBlock = null; if (track.getMaterial().trackType == CRTrackMaterials.CRTrackType.NARROW_GAUGE) { overrideBlock = CRBlocks.TRACK_BUFFER_NARROW.get(); @@ -148,33 +153,37 @@ public InteractionResult useOn(UseOnContext context) { placedPos = context.getClickedFace() == Direction.DOWN ? pos.below() : pos.above(); placeDirection = context.getClickedFace(); } - + teTag.put("TargetTrack", NbtUtils.writeBlockPos(pos.subtract(placedPos))); stackTag.put("BlockEntityTag", teTag); - + + TrackShape shape = state.getValue(TrackBlock.SHAPE); + boolean diagonal = shape == TrackShape.PD || shape == TrackShape.ND; + InteractionResult useOn = place(BufferBlockPlaceContext.at( - new BlockPlaceContext(context), placedPos, placeDirection, - Direction.fromAxisAndDirection(axis, nearestTrackAxis.getSecond()), overrideBlock + new BlockPlaceContext(context), placedPos, placeDirection, + Direction.fromAxisAndDirection(axis, nearestTrackAxis.getSecond()), + overrideBlock, diagonal )); - + teTag.remove("TargetTrack"); teTag.remove("TargetDirection"); - + return useOn; } - + return InteractionResult.PASS; } - + @Environment(EnvType.CLIENT) @Override public boolean useOnCurve(TrackBlockOutline.BezierPointSelection selection, ItemStack stack) { Minecraft mc = Minecraft.getInstance(); LocalPlayer player = mc.player; Level level = mc.level; - + if (player != null) { - + player.displayClientMessage(Lang.translateDirect("track_target.invalid") .withStyle(ChatFormatting.RED), true); AllSoundEvents.DENY.play(level, player, player.position(), .5f, 1); diff --git a/fabric/src/main/java/com/railwayteam/railways/content/buffer/fabric/BufferModel.java b/fabric/src/main/java/com/railwayteam/railways/content/buffer/fabric/BufferModel.java index 93bd0bd7e..39c67060b 100644 --- a/fabric/src/main/java/com/railwayteam/railways/content/buffer/fabric/BufferModel.java +++ b/fabric/src/main/java/com/railwayteam/railways/content/buffer/fabric/BufferModel.java @@ -18,8 +18,11 @@ package com.railwayteam.railways.content.buffer.fabric; +import com.mojang.math.Matrix3f; +import com.mojang.math.Vector3f; import com.railwayteam.railways.content.buffer.IDyedBuffer; import com.railwayteam.railways.content.buffer.IMaterialAdaptingBuffer; +import com.railwayteam.railways.content.buffer.TrackBufferBlock; import com.simibubi.create.foundation.model.BakedModelHelper; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -56,17 +59,32 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault public class BufferModel extends ForwardingBakedModel { + public BufferModel(BakedModel wrapped) { - this.wrapped = wrapped; + this.wrapped = wrapped; } - - @Override - public boolean isVanillaAdapter() { - return false; - } - + + private static final Matrix3f diagonalTransform = getDiagonalRotationMatrix(); + private static final RenderContext.QuadTransform diagonalTransformer = quad -> { + Vector3f faceNormal = quad.faceNormal(); + faceNormal.transform(diagonalTransform); + for (int i = 0; i < 4; i++) { + Vector3f vertexPos = quad.copyPos(i, new Vector3f()); + vertexPos.sub(new Vector3f(0.5f, 0.5f, 0.5f)); + vertexPos.transform(diagonalTransform); + vertexPos.add(new Vector3f(0.5f, 0.5f, 0.5f)); + quad.pos(i, vertexPos); + quad.normal(i, faceNormal); + } + + return true; + }; + @Override public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { + boolean isDiagonal = state.getValue(TrackBufferBlock.DIAGONAL); + if (isDiagonal) context.pushTransform(diagonalTransformer); + UnaryOperator materialSwapper = null; UnaryOperator colorSwapper = null; @@ -83,8 +101,16 @@ public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, Block } else { super.emitBlockQuads(blockView, state, pos, randomSupplier, context); } + if (isDiagonal) context.popTransform(); } - + + private static Matrix3f getDiagonalRotationMatrix() { + Matrix3f matrix = Matrix3f.createScaleMatrix(1, 1, 1); + matrix.mul(Vector3f.YP.rotationDegrees(-45)); + return matrix; + } + + @Override public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { UnaryOperator materialSwapper = null; diff --git a/forge/src/main/java/com/railwayteam/railways/content/buffer/forge/BufferModel.java b/forge/src/main/java/com/railwayteam/railways/content/buffer/forge/BufferModel.java index ab6734e35..42e68d6de 100644 --- a/forge/src/main/java/com/railwayteam/railways/content/buffer/forge/BufferModel.java +++ b/forge/src/main/java/com/railwayteam/railways/content/buffer/forge/BufferModel.java @@ -20,7 +20,10 @@ import com.railwayteam.railways.content.buffer.IDyedBuffer; import com.railwayteam.railways.content.buffer.IMaterialAdaptingBuffer; +import com.railwayteam.railways.content.buffer.TrackBufferBlock; +import com.simibubi.create.foundation.collision.Matrix3d; import com.simibubi.create.foundation.model.BakedModelHelper; +import com.simibubi.create.foundation.model.BakedQuadHelper; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.BakedQuad; @@ -39,13 +42,16 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; import net.minecraftforge.client.model.data.ModelData; import net.minecraftforge.client.model.data.ModelProperty; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.function.Function; import java.util.function.UnaryOperator; import static com.railwayteam.railways.content.buffer.BufferModelUtils.combineSwappers; @@ -88,12 +94,42 @@ public BufferModel(BakedModel wrapped) { BlockState material = data.get(MATERIAL); DyeColor color = data.get(COLOR); if (material != null || color != null) { - return BakedModelHelper.swapSprites(wrapped.getQuads(state, side, rand), combineSwappers(getSwapper(material), getSwapper(color))); + return BakedModelHelper.swapSprites(transformQuads(wrapped.getQuads(state, side, rand), state), combineSwappers(getSwapper(material), getSwapper(color))); } else { - return wrapped.getQuads(state, side, rand); + return transformQuads(wrapped.getQuads(state, side, rand), state); } } + private static final Matrix3d diagonalTransform = new Matrix3d() + .asYRotation((float) Math.toRadians(-45)); + + private BakedQuad applyDiagonalTransform(BakedQuad quad) { + BakedQuad newQuad = BakedQuadHelper.clone(quad); + int[] vertexData = newQuad.getVertices(); + + for (int vertex = 0; vertex < 4; vertex++) { + Vec3 vertexPos = BakedQuadHelper.getXYZ(vertexData, vertex); + vertexPos = vertexPos.subtract(0.5, 0.5, 0.5); + vertexPos = diagonalTransform.transform(vertexPos); + vertexPos = vertexPos.add(0.5, 0.5, 0.5); + BakedQuadHelper.setXYZ(vertexData, vertex, vertexPos); + } + return newQuad; + } + + private List transformQuads(List quads, @Nullable BlockState state) { + if (state == null) return quads; + boolean diagonal = state.getValue(TrackBufferBlock.DIAGONAL); + if (!diagonal) return quads; + + ArrayList transformedQuads = new ArrayList<>(); + for (BakedQuad quad : quads) { + transformedQuads.add(applyDiagonalTransform(quad)); + } + return transformedQuads; + } + + @SuppressWarnings("deprecation") @Override public List getQuads(@Nullable BlockState state, @Nullable Direction direction, @NotNull RandomSource random) { return Collections.emptyList();