Skip to content

Commit

Permalink
feat: Add Odd Horizontal Elevator Doors
Browse files Browse the repository at this point in the history
  • Loading branch information
WerySkok committed Oct 16, 2023
1 parent 1ce07cf commit 938daec
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@
import mtr.RegistryObject;
import mtr.mappings.BlockEntityMapper;
import mtr.mappings.RegistryUtilities;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import ru.weryskok.mtrrumetro.blocks.*;

import java.util.function.BiConsumer;

public class BlockEntityTypes {
public final BiConsumer<String, RegistryObject<? extends BlockEntityType<? extends BlockEntityMapper>>> registerBlockEntityType;
public static final RegistryObject<BlockEntityType<BlockSPBHorizontalElevatorDoor.TileEntitySPBHorizontalElevatorDoor>> SPB_HORIZONTAL_ELEVATOR_DOOR_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType(BlockSPBHorizontalElevatorDoor.TileEntitySPBHorizontalElevatorDoor::new, Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR.get()));
public static final RegistryObject<BlockEntityType<BlockSPBHorizontalElevatorDoor.TileEntitySPBHorizontalElevatorDoor>> SPB_HORIZONTAL_ELEVATOR_DOOR_TILE_ENTITY = new RegistryObject<>(() -> {
return RegistryUtilities.getBlockEntityType((BlockPos pos, BlockState state) -> new BlockSPBHorizontalElevatorDoor.TileEntitySPBHorizontalElevatorDoor(pos, state, false), Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR.get());
});
public static final RegistryObject<BlockEntityType<BlockSPBHorizontalElevatorDoor.TileEntitySPBHorizontalElevatorDoor>> SPB_HORIZONTAL_ELEVATOR_DOOR_ODD_TILE_ENTITY = new RegistryObject<>(() -> {
return RegistryUtilities.getBlockEntityType((BlockPos pos, BlockState state) -> new BlockSPBHorizontalElevatorDoor.TileEntitySPBHorizontalElevatorDoor(pos, state, true), Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR_ODD.get());
});

public BlockEntityTypes(BiConsumer<String, RegistryObject<? extends BlockEntityType<? extends BlockEntityMapper>>> registerBlockEntityType) {
this.registerBlockEntityType = registerBlockEntityType;
}

public void registerBlockEntites(){
registerBlockEntityType.accept("spb_horizontal_elevator_door", BlockEntityTypes.SPB_HORIZONTAL_ELEVATOR_DOOR_TILE_ENTITY);
registerBlockEntityType.accept("spb_horizontal_elevator_door_odd", BlockEntityTypes.SPB_HORIZONTAL_ELEVATOR_DOOR_ODD_TILE_ENTITY);
}
}
4 changes: 3 additions & 1 deletion common/src/main/java/ru/weryskok/mtrrumetro/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class Blocks {
public static final RegistryObject<Block> MOSCOW_NEW_TICKET_BARRIER_EXIT = new RegistryObject<>(()-> new BlockMoscowNewTicketBarrier(false));
public static final RegistryObject<Block> MOSCOW_NEW_TICKET_BARRIER_SIDE_COVER = new RegistryObject<>(BlockMoscowNewTicketBarrierSideCover::new);
public static final RegistryObject<Block> MOSCOW_NEW_TICKET_MACHINE = new RegistryObject<>(() -> new BlockMoscowNewTicketMachine(BlockBehaviour.Properties.of(Material.METAL, MaterialColor.COLOR_GRAY).requiresCorrectToolForDrops().strength(2).lightLevel(state -> 5).noOcclusion()));
public static final RegistryObject<Block> SPB_HORIZONTAL_ELEVATOR_DOOR = new RegistryObject<>(BlockSPBHorizontalElevatorDoor::new);
public static final RegistryObject<Block> SPB_HORIZONTAL_ELEVATOR_DOOR = new RegistryObject<>(() -> new BlockSPBHorizontalElevatorDoor(false));
public static final RegistryObject<Block> SPB_HORIZONTAL_ELEVATOR_DOOR_ODD = new RegistryObject<>(() -> new BlockSPBHorizontalElevatorDoor(true));
public static final RegistryObject<Block> MOSCOW_OLD_INFOSOS_STAND = new RegistryObject<>(BlockMoscowOldInfoSosStand::new);
public static final RegistryObject<Block> MOSCOW_METRO_LOGO = new RegistryObject<>(BlockMoscowMetroLogo::new);

Expand All @@ -47,5 +48,6 @@ public void registerBlockItems(){

public void registerBlocks(){
registerBlock.accept("spb_horizontal_elevator_door", Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR);
registerBlock.accept("spb_horizontal_elevator_door_odd", Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR_ODD);
}
}
4 changes: 3 additions & 1 deletion common/src/main/java/ru/weryskok/mtrrumetro/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

public class Items {
private final BiConsumer<String, RegistryObject<Item>> registerItem;
public static final RegistryObject<Item> SPB_HORIZONTAL_ELEVATOR_DOOR = new RegistryObject<>(ItemSPBHorizontalElevatorDoor::new);
public static final RegistryObject<Item> SPB_HORIZONTAL_ELEVATOR_DOOR = new RegistryObject<>(() -> new ItemSPBHorizontalElevatorDoor(false));
public static final RegistryObject<Item> SPB_HORIZONTAL_ELEVATOR_DOOR_ODD = new RegistryObject<>(() -> new ItemSPBHorizontalElevatorDoor(true));

public Items(BiConsumer<String, RegistryObject<Item>> registerItem) {
this.registerItem = registerItem;
}

public void registerItem(){
registerItem.accept("spb_horizontal_elevator_door", Items.SPB_HORIZONTAL_ELEVATOR_DOOR);
registerItem.accept("spb_horizontal_elevator_door_odd", Items.SPB_HORIZONTAL_ELEVATOR_DOOR_ODD);
}
}
5 changes: 3 additions & 2 deletions common/src/main/java/ru/weryskok/mtrrumetro/MainClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.weryskok.mtrrumetro;

import mtr.RegistryClient;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import ru.weryskok.mtrrumetro.render.*;

Expand All @@ -18,7 +17,9 @@ public static void init() {
RegistryClient.registerBlockRenderType(RenderType.cutoutMipped(), Blocks.MOSCOW_NEW_TICKET_MACHINE.get());

RegistryClient.registerBlockRenderType(RenderType.cutoutMipped(), Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR.get());
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.SPB_HORIZONTAL_ELEVATOR_DOOR_TILE_ENTITY.get(), RenderSPBHorizontalElevatorDoor::new);
RegistryClient.registerBlockRenderType(RenderType.cutoutMipped(), Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR_ODD.get());
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.SPB_HORIZONTAL_ELEVATOR_DOOR_TILE_ENTITY.get(), dispatcher -> new RenderSPBHorizontalElevatorDoor(dispatcher, false));
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.SPB_HORIZONTAL_ELEVATOR_DOOR_ODD_TILE_ENTITY.get(), dispatcher -> new RenderSPBHorizontalElevatorDoor(dispatcher, true));

RegistryClient.registerBlockRenderType(RenderType.cutoutMipped(), Blocks.MOSCOW_OLD_INFOSOS_STAND.get());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,68 @@
package ru.weryskok.mtrrumetro.blocks;

import mtr.block.BlockPSDAPGDoorBase;
import mtr.block.BlockPSDAPGGlassEndBase;
import mtr.block.IBlock;
import mtr.mappings.BlockEntityMapper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.block.state.properties.Property;
import ru.weryskok.mtrrumetro.BlockEntityTypes;
import ru.weryskok.mtrrumetro.Items;

public class BlockSPBHorizontalElevatorDoor extends BlockPSDAPGDoorBase {
boolean is_odd;

public BlockSPBHorizontalElevatorDoor() {
public BlockSPBHorizontalElevatorDoor(boolean is_odd) {
super();
this.is_odd = is_odd;
}

@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
if (is_odd){
boolean isTop = IBlock.getStatePropertySafe(state, HALF) == DoubleBlockHalf.UPPER;
return (isTop && direction == Direction.DOWN || !isTop && direction == Direction.UP) && !newState.is(this) ? Blocks.AIR.defaultBlockState() : state;
}
if (IBlock.getSideDirection(state) == direction && !newState.is(this)) {
return Blocks.AIR.defaultBlockState();
} else {
BlockState superState = super.updateShape(state, direction, newState, world, pos, posFrom);
if (superState.getBlock() == Blocks.AIR) {
return superState;
} else {
boolean end = world.getBlockState(pos.relative(IBlock.getSideDirection(state).getOpposite())).getBlock() instanceof BlockPSDAPGGlassEndBase;
return (BlockState)superState.setValue(END, end);
}
}
}

@Override
public BlockEntityMapper createBlockEntity(BlockPos pos, BlockState state) {
return new TileEntitySPBHorizontalElevatorDoor(pos, state);
return new TileEntitySPBHorizontalElevatorDoor(pos, state, is_odd);
}

@Override
public Item asItem() {
return Items.SPB_HORIZONTAL_ELEVATOR_DOOR.get();
return (is_odd? Items.SPB_HORIZONTAL_ELEVATOR_DOOR_ODD : Items.SPB_HORIZONTAL_ELEVATOR_DOOR).get();
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(new Property[]{END, FACING, HALF, SIDE, TEMP, UNLOCKED});
}

public static class TileEntitySPBHorizontalElevatorDoor extends TileEntityPSDAPGDoorBase {

public TileEntitySPBHorizontalElevatorDoor(BlockPos pos, BlockState state) {
super(BlockEntityTypes.SPB_HORIZONTAL_ELEVATOR_DOOR_TILE_ENTITY.get(), pos, state);
public TileEntitySPBHorizontalElevatorDoor(BlockPos pos, BlockState state, boolean is_odd) {
super((is_odd ? BlockEntityTypes.SPB_HORIZONTAL_ELEVATOR_DOOR_ODD_TILE_ENTITY : BlockEntityTypes.SPB_HORIZONTAL_ELEVATOR_DOOR_TILE_ENTITY).get(), pos, state);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.weryskok.mtrrumetro.items;

import mtr.RegistryObject;
import mtr.block.IBlock;
import mtr.item.ItemWithCreativeTabBase;
import net.minecraft.core.BlockPos;
Expand All @@ -16,14 +17,16 @@

public class ItemSPBHorizontalElevatorDoor extends ItemWithCreativeTabBase implements IBlock {

boolean is_odd;

public ItemSPBHorizontalElevatorDoor() {
public ItemSPBHorizontalElevatorDoor(boolean is_odd) {
super(CreativeModeTabs.RUSSIAN_METRO_STUFF);
this.is_odd = is_odd;
}

@Override
public InteractionResult useOn(UseOnContext context) {
final int horizontalBlocks = 2;
final int horizontalBlocks = is_odd ? 1 : 2;
if (blocksNotReplaceable(context, horizontalBlocks, 2, getBlockStateFromItem().getBlock())) {
return InteractionResult.FAIL;
}
Expand All @@ -36,9 +39,11 @@ public InteractionResult useOn(UseOnContext context) {
final BlockPos newPos = pos.relative(playerFacing.getClockWise(), x);

for (int y = 0; y < 2; y++) {
final BlockState state = getBlockStateFromItem().setValue(BlockSPBHorizontalElevatorDoor.FACING, playerFacing).setValue(HALF, y == 1 ? DoubleBlockHalf.UPPER : DoubleBlockHalf.LOWER);
BlockState newState = state.setValue(SIDE, x == 0 ? EnumSide.LEFT : EnumSide.RIGHT);
world.setBlockAndUpdate(newPos.above(y), newState);
BlockState state = getBlockStateFromItem().setValue(BlockSPBHorizontalElevatorDoor.FACING, playerFacing).setValue(HALF, y == 1 ? DoubleBlockHalf.UPPER : DoubleBlockHalf.LOWER);
if (!is_odd) {
state = state.setValue(SIDE, x == 0 ? EnumSide.LEFT : EnumSide.RIGHT);
}
world.setBlockAndUpdate(newPos.above(y), state);
}
}

Expand All @@ -47,7 +52,8 @@ public InteractionResult useOn(UseOnContext context) {
}

private BlockState getBlockStateFromItem() {
return Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR.get().defaultBlockState();
RegistryObject<Block> block = is_odd ? Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR_ODD : Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR;
return block.get().defaultBlockState();
}

// The same implementation from MTR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public class RenderSPBHorizontalElevatorDoor<T extends BlockPSDAPGDoorBase.TileE
private static final ModelSingleCube MODEL_PSD = new ModelSingleCube(36, 18, 0, 0, 0, 16, 16, 2);
private static final ModelSingleCube MODEL_PSD_DOOR_LOCKED = new ModelSingleCube(6, 6, 5, 6, 2.1f, 6, 6, 0);

public RenderSPBHorizontalElevatorDoor(BlockEntityRenderDispatcher dispatcher) {
boolean is_odd;

public RenderSPBHorizontalElevatorDoor(BlockEntityRenderDispatcher dispatcher, boolean is_odd) {
super(dispatcher);
this.is_odd = is_odd;
}

@Override
Expand All @@ -56,10 +59,28 @@ public void render(T entity, float tickDelta, PoseStack matrices, MultiBufferSou
UtilitiesClient.rotateYDegrees(matricesNew, -facing.toYRot());
UtilitiesClient.rotateXDegrees(matricesNew, 180);
});
if (is_odd) {
final StoredMatrixTransformations rightStoredMatrixTransformations = storedMatrixTransformations.copy();

rightStoredMatrixTransformations.add(matricesNew -> matricesNew.translate(open * (!side ? -1 : 1), 0, 0));
rightStoredMatrixTransformations.add(matricesNew -> matricesNew.translate(-0.5, 0, 0));
RenderTrains.scheduleRender(new ResourceLocation(String.format("russianmetro:textures/block/spb_horizontal_elevator_door_%s_%s.png", half ? "top" : "bottom", !side ? "right" : "left")), false, RenderTrains.QueuedRenderLayer.EXTERIOR, (matricesNew, vertexConsumer) -> {
rightStoredMatrixTransformations.transform(matricesNew);
MODEL_PSD.renderToBuffer(matricesNew, vertexConsumer, light, overlay, 1, 1, 1, 1);
matricesNew.popPose();
});

storedMatrixTransformations.add(matricesNew -> matricesNew.translate(open * (side ? -1 : 1), 0, 0));

if (half && !unlocked) {
RenderTrains.scheduleRender(new ResourceLocation("mtr:textures/block/sign/door_not_in_use.png"), false, RenderTrains.QueuedRenderLayer.EXTERIOR, (matricesNew, vertexConsumer) -> {
rightStoredMatrixTransformations.transform(matricesNew);
MODEL_PSD_DOOR_LOCKED.renderToBuffer(matricesNew, vertexConsumer, light, overlay, 1, 1, 1, 1);
matricesNew.popPose();
});
}

storedMatrixTransformations.add(matricesNew -> matricesNew.translate(0.5, 0, 0));
}
storedMatrixTransformations.add(matricesNew -> matricesNew.translate(open * (side ? -1 : 1), 0, 0));
RenderTrains.scheduleRender(new ResourceLocation(String.format("russianmetro:textures/block/spb_horizontal_elevator_door_%s_%s.png", half ? "top" : "bottom", side ? "right" : "left")), false, RenderTrains.QueuedRenderLayer.EXTERIOR, (matricesNew, vertexConsumer) -> {
storedMatrixTransformations.transform(matricesNew);
MODEL_PSD.renderToBuffer(matricesNew, vertexConsumer, light, overlay, 1, 1, 1, 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"multipart": [
{
"when": {
"facing": "west",
"side": "left",
"half": "lower",
"temp": "true"
},
"apply": {
"model": "russianmetro:block/temp_doors/spb_horizontal_elevator_door_odd_bottom"
}
},
{
"when": {
"facing": "north",
"side": "left",
"half": "lower",
"temp": "true"
},
"apply": {
"model": "russianmetro:block/temp_doors/spb_horizontal_elevator_door_odd_bottom",
"y": 90
}
},
{
"when": {
"facing": "east",
"side": "left",
"half": "lower",
"temp": "true"
},
"apply": {
"model": "russianmetro:block/temp_doors/spb_horizontal_elevator_door_odd_bottom",
"y": 180
}
},
{
"when": {
"facing": "south",
"side": "left",
"half": "lower",
"temp": "true"
},
"apply": {
"model": "russianmetro:block/temp_doors/spb_horizontal_elevator_door_odd_bottom",
"y": 270
}
},
{
"when": {
"facing": "west",
"side": "left",
"half": "upper",
"temp": "true"
},
"apply": {
"model": "russianmetro:block/temp_doors/spb_horizontal_elevator_door_odd_top"
}
},
{
"when": {
"facing": "north",
"side": "left",
"half": "upper",
"temp": "true"
},
"apply": {
"model": "russianmetro:block/temp_doors/spb_horizontal_elevator_door_odd_top",
"y": 90
}
},
{
"when": {
"facing": "east",
"side": "left",
"half": "upper",
"temp": "true"
},
"apply": {
"model": "russianmetro:block/temp_doors/spb_horizontal_elevator_door_odd_top",
"y": 180
}
},
{
"when": {
"facing": "south",
"side": "left",
"half": "upper",
"temp": "true"
},
"apply": {
"model": "russianmetro:block/temp_doors/spb_horizontal_elevator_door_odd_top",
"y": 270
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"block.russianmetro.moscow_new_ticket_barrier_exit": "Moscow New Ticket Barrier (Exit)",
"block.russianmetro.moscow_new_ticket_barrier_side_cover": "Moscow New Ticket Barrier (Side Cover)",
"block.russianmetro.moscow_new_ticket_machine": "Moscow Ticket Machine",
"item.russianmetro.spb_horizontal_elevator_door": "St. Petersburg \"Horizontal Elevator\" Station Doors",
"item.russianmetro.spb_horizontal_elevator_door": "St. Petersburg \"Horizontal Elevator\" Station Doors (Even)",
"item.russianmetro.spb_horizontal_elevator_door_odd": "St. Petersburg \"Horizontal Elevator\" Station Doors (Odd)",
"block.russianmetro.moscow_old_infosos_stand": "Moscow \"Info-SOS\" Stand",
"block.russianmetro.moscow_metro_logo": "Metro Emblem"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"block.russianmetro.moscow_new_ticket_barrier_exit": "Новый московский турникет (Выход)",
"block.russianmetro.moscow_new_ticket_barrier_side_cover": "Новый московский турникет (Боковая заглушка)",
"block.russianmetro.moscow_new_ticket_machine": "Московский автомат по продаже билетов",
"item.russianmetro.spb_horizontal_elevator_door": "Петербургские станционные двери «Горизонтальный лифт»",
"item.russianmetro.spb_horizontal_elevator_door": "Петербургские станционные двери «Горизонтальный лифт» (Чётные)",
"item.russianmetro.spb_horizontal_elevator_door_odd": "Петербургские станционные двери «Горизонтальный лифт» (Нечётные)",
"block.russianmetro.moscow_old_infosos_stand": "Московский стенд «Инфосос»",
"block.russianmetro.moscow_metro_logo": "Эмблема метро"
}

0 comments on commit 938daec

Please sign in to comment.