-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f66155
commit 290456e
Showing
13 changed files
with
292 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
common/src/main/java/ziyue/tjmetro/block/BlockStationNamePlate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package ziyue.tjmetro.block; | ||
|
||
import mtr.Blocks; | ||
import mtr.block.IBlock; | ||
import mtr.mappings.BlockEntityClientSerializableMapper; | ||
import mtr.mappings.BlockEntityMapper; | ||
import mtr.mappings.EntityBlockMapper; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.HorizontalDirectionalBlock; | ||
import net.minecraft.world.level.block.SimpleWaterloggedBlock; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.StateDefinition; | ||
import net.minecraft.world.level.block.state.properties.IntegerProperty; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.minecraft.world.level.material.Fluids; | ||
import net.minecraft.world.phys.shapes.CollisionContext; | ||
import net.minecraft.world.phys.shapes.Shapes; | ||
import net.minecraft.world.phys.shapes.VoxelShape; | ||
import org.jetbrains.annotations.Nullable; | ||
import ziyue.tjmetro.BlockEntityTypes; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.WATERLOGGED; | ||
|
||
public class BlockStationNamePlate extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock, EntityBlockMapper | ||
{ | ||
public static final IntegerProperty POS = IntegerProperty.create("pos", 0, 3); | ||
|
||
public BlockStationNamePlate() { | ||
this(BlockBehaviour.Properties.copy(Blocks.STATION_NAME_TALL_WALL.get())); | ||
} | ||
|
||
public BlockStationNamePlate(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) { | ||
BlockState blockState = defaultBlockState().setValue(FACING, blockPlaceContext.getHorizontalDirection()).setValue(WATERLOGGED, false); | ||
if (IBlock.isReplaceable(blockPlaceContext, blockState.getValue(FACING).getClockWise(), 4)) { | ||
for (int i = 1; i < 4; i++) { | ||
blockPlaceContext.getLevel().setBlock(blockPlaceContext.getClickedPos().relative(blockState.getValue(FACING).getClockWise(), i), blockState.setValue(POS, i), 2); | ||
} | ||
return blockState.setValue(POS, 0); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void playerWillDestroy(Level level, BlockPos blockPos, BlockState blockState, Player player) { | ||
for (int i = 1; i < blockState.getValue(POS) + 1; i++) { | ||
IBlockExtends.breakBlock(level, blockPos.relative(blockState.getValue(FACING).getCounterClockWise(), i), this); | ||
} | ||
for (int i = 1; i < 4 - blockState.getValue(POS); i++) { | ||
IBlockExtends.breakBlock(level, blockPos.relative(blockState.getValue(FACING).getClockWise(), i), this); | ||
} | ||
super.playerWillDestroy(level, blockPos, blockState, player); | ||
} | ||
|
||
@Override | ||
public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) { | ||
final Direction facing = IBlock.getStatePropertySafe(blockState, FACING); | ||
final int pos = IBlock.getStatePropertySafe(blockState, POS); | ||
if ((pos % 3) != 0) { | ||
return IBlock.getVoxelShapeByDirection(0, 0, 7, 16, 12, 9, facing); | ||
} else { | ||
final VoxelShape main = IBlock.getVoxelShapeByDirection(3.25, 0, 7, 16, 12, 9, (pos == 3) ? facing.getOpposite() : facing); | ||
final VoxelShape pole = IBlock.getVoxelShapeByDirection(2, 0, 7, 3.25, 16, 9, (pos == 3) ? facing.getOpposite() : facing); | ||
return Shapes.or(main, pole); | ||
} | ||
} | ||
|
||
@Override | ||
public BlockEntityMapper createBlockEntity(BlockPos pos, BlockState state) { | ||
return new TileEntityStationNamePlate(pos, state); | ||
} | ||
|
||
@Override | ||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { | ||
builder.add(FACING, WATERLOGGED, POS); | ||
} | ||
|
||
@Override | ||
public FluidState getFluidState(BlockState blockState) { | ||
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState); | ||
} | ||
|
||
public static class TileEntityStationNamePlate extends BlockEntityClientSerializableMapper | ||
{ | ||
public final float yOffset; | ||
public final float zOffset; | ||
protected Long selectedId; | ||
protected static final String KEY_SELECTED_ID = "selected_id"; | ||
|
||
public TileEntityStationNamePlate(BlockPos pos, BlockState state) { | ||
super(BlockEntityTypes.STATION_NAME_PLATE_TILE_ENTITY.get(), pos, state); | ||
this.yOffset = 0.0F; | ||
this.zOffset = 0.00625F; | ||
this.selectedId = -1L; | ||
} | ||
|
||
@Override | ||
public void readCompoundTag(CompoundTag compoundTag) { | ||
selectedId = compoundTag.getLong(KEY_SELECTED_ID); | ||
} | ||
|
||
@Override | ||
public void writeCompoundTag(CompoundTag compoundTag) { | ||
compoundTag.putLong(KEY_SELECTED_ID, selectedId); | ||
} | ||
|
||
public void setData(Long selectedId) { | ||
Consumer<Direction> setStyle = direction -> { | ||
BlockPos offsetPos = getBlockPos(); | ||
while (level.getBlockEntity(offsetPos) instanceof TileEntityStationNamePlate entity) { | ||
entity.selectedId = selectedId; | ||
entity.setChanged(); | ||
entity.syncData(); | ||
offsetPos = offsetPos.relative(direction); | ||
} | ||
}; | ||
setStyle.accept(IBlock.getStatePropertySafe(getBlockState(), FACING).getClockWise()); | ||
setStyle.accept(IBlock.getStatePropertySafe(getBlockState(), FACING).getCounterClockWise()); | ||
this.selectedId = selectedId; | ||
setChanged(); | ||
syncData(); | ||
} | ||
|
||
public Long getSelectedId() { | ||
return selectedId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
common/src/main/java/ziyue/tjmetro/render/RenderStationNamePlate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package ziyue.tjmetro.render; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import mtr.block.BlockStationNameBase; | ||
import mtr.block.IBlock; | ||
import mtr.client.ClientData; | ||
import mtr.client.IDrawing; | ||
import mtr.data.IGui; | ||
import mtr.data.RailwayData; | ||
import mtr.data.Station; | ||
import mtr.mappings.BlockEntityRendererMapper; | ||
import mtr.mappings.Text; | ||
import mtr.mappings.UtilitiesClient; | ||
import mtr.render.RenderTrains; | ||
import mtr.render.StoredMatrixTransformations; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import ziyue.tjmetro.block.BlockStationNameEntranceTianjin; | ||
import ziyue.tjmetro.block.BlockStationNamePlate; | ||
import ziyue.tjmetro.client.ClientCache; | ||
|
||
import static ziyue.tjmetro.block.BlockStationNamePlate.POS; | ||
|
||
/** | ||
* @author ZiYueCommentary | ||
* @see mtr.render.RenderStationNameTiled | ||
* @see BlockStationNameEntranceTianjin | ||
* @since beta-1 | ||
*/ | ||
|
||
public class RenderStationNamePlate<T extends BlockStationNamePlate.TileEntityStationNamePlate> extends BlockEntityRendererMapper<T> implements IGui, IDrawing | ||
{ | ||
public RenderStationNamePlate(BlockEntityRenderDispatcher dispatcher) { | ||
super(dispatcher); | ||
} | ||
|
||
@Override | ||
public void render(T entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) { | ||
final BlockGetter world = entity.getLevel(); | ||
if (world == null) return; | ||
|
||
|
||
final BlockPos pos = entity.getBlockPos(); | ||
final BlockState state = world.getBlockState(pos); | ||
final Direction facing = IBlock.getStatePropertySafe(state, BlockStationNameBase.FACING); | ||
|
||
final StoredMatrixTransformations storedMatrixTransformations = new StoredMatrixTransformations(); | ||
storedMatrixTransformations.add(matricesNew -> { | ||
matricesNew.translate(0.5 + entity.getBlockPos().getX(), 0.5 + entity.yOffset + entity.getBlockPos().getY(), 0.5 + entity.getBlockPos().getZ()); | ||
UtilitiesClient.rotateYDegrees(matricesNew, -facing.toYRot()); | ||
UtilitiesClient.rotateZDegrees(matricesNew, 180); | ||
}); | ||
|
||
final Station station = RailwayData.getStation(ClientData.STATIONS, ClientData.DATA_CACHE, pos); | ||
final StoredMatrixTransformations storedMatrixTransformations2 = storedMatrixTransformations.copy(); | ||
storedMatrixTransformations2.add(matricesNew -> matricesNew.translate(0, 0, 0.5 - entity.zOffset - SMALL_OFFSET)); | ||
|
||
final int lengthLeft = entity.getBlockState().getValue(POS); | ||
final int propagateProperty = IBlock.getStatePropertySafe(world, pos, BlockStationNameEntranceTianjin.STYLE); | ||
final float logoSize = 0.5F; | ||
|
||
final ClientCache.DynamicResource resource = ClientCache.DATA_CACHE.getStationNameEntrance(station.id, entity.getSelectedId(), propagateProperty, IGui.insertTranslation("gui.mtr.station_cjk", "gui.mtr.station", 1, station.name), false, 4); | ||
|
||
RenderTrains.scheduleRender(resource.resourceLocation, false, RenderTrains.QueuedRenderLayer.INTERIOR, (poseStack, vertexConsumer) -> { | ||
storedMatrixTransformations2.transform(poseStack); | ||
IDrawing.drawTexture(poseStack, vertexConsumer, -0.5F, -logoSize / 2, 1, logoSize, (float) (lengthLeft - 1) / 4, 0, (float) lengthLeft / 4, 1, facing, ARGB_WHITE, light); | ||
poseStack.popPose(); | ||
}); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
common/src/main/resources/assets/tjmetro/blockstates/station_name_plate.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"variants": { | ||
"facing=north,pos=0": { "model": "mtr:block/railway_sign_end_one_and_a_half" }, | ||
"facing=east,pos=0": { "model": "mtr:block/railway_sign_end_one_and_a_half", "y": 90 }, | ||
"facing=south,pos=0": { "model": "mtr:block/railway_sign_end_one_and_a_half", "y": 180 }, | ||
"facing=west,pos=0": { "model": "mtr:block/railway_sign_end_one_and_a_half", "y": 270 }, | ||
"facing=north,pos=1": { "model": "mtr:block/railway_sign_middle" }, | ||
"facing=east,pos=1": { "model": "mtr:block/railway_sign_middle", "y": 90 }, | ||
"facing=south,pos=1": { "model": "mtr:block/railway_sign_middle", "y": 180 }, | ||
"facing=west,pos=1": { "model": "mtr:block/railway_sign_middle", "y": 270 }, | ||
"facing=north,pos=2": { "model": "mtr:block/railway_sign_middle" }, | ||
"facing=east,pos=2": { "model": "mtr:block/railway_sign_middle", "y": 90 }, | ||
"facing=south,pos=2": { "model": "mtr:block/railway_sign_middle", "y": 180 }, | ||
"facing=west,pos=2": { "model": "mtr:block/railway_sign_middle", "y": 270 }, | ||
"facing=north,pos=3": { "model": "mtr:block/railway_sign_end_one_and_a_half", "y": 180 }, | ||
"facing=east,pos=3": { "model": "mtr:block/railway_sign_end_one_and_a_half", "y": 270 }, | ||
"facing=south,pos=3": { "model": "mtr:block/railway_sign_end_one_and_a_half" }, | ||
"facing=west,pos=3": { "model": "mtr:block/railway_sign_end_one_and_a_half", "y": 90 } | ||
} | ||
} |
Binary file added
BIN
+3.69 KB
common/src/main/resources/assets/tjmetro/textures/block/logo_stroke.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.