Skip to content

Commit

Permalink
Add "Info-SOS stand"
Browse files Browse the repository at this point in the history
  • Loading branch information
WerySkok committed Jun 5, 2023
1 parent b794a28 commit fd7a551
Show file tree
Hide file tree
Showing 14 changed files with 776 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/src/main/java/ru/weryskok/mtrrumetro/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public interface Blocks {
RegistryObject<Block> MOSCOW_NEW_TICKET_BARRIER_SIDE_COVER = new RegistryObject<>(BlockMoscowNewTicketBarrierSideCover::new);
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()));
RegistryObject<Block> SPB_HORIZONTAL_ELEVATOR_DOOR = new RegistryObject<>(BlockSPBHorizontalElevatorDoor::new);
RegistryObject<Block> MOSCOW_OLD_INFOSOS_STAND = new RegistryObject<>(BlockMoscowOldInfoSosStand::new);
}
2 changes: 2 additions & 0 deletions common/src/main/java/ru/weryskok/mtrrumetro/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static void init(
registerBlock.accept("spb_horizontal_elevator_door", Blocks.SPB_HORIZONTAL_ELEVATOR_DOOR);
registerItem.accept("spb_horizontal_elevator_door", Items.SPB_HORIZONTAL_ELEVATOR_DOOR);
registerBlockEntityType.accept("spb_horizontal_elevator_door", BlockEntityTypes.SPB_HORIZONTAL_ELEVATOR_DOOR_TILE_ENTITY);

registerBlockItem.accept("moscow_old_infosos_stand", Blocks.MOSCOW_OLD_INFOSOS_STAND, CreativeModeTabs.RUSSIAN_METRO_STUFF);
}

@FunctionalInterface
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/ru/weryskok/mtrrumetro/MainClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public static void init() {

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.MOSCOW_OLD_INFOSOS_STAND.get());
}

public static void registerItemModelPredicates() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ru.weryskok.mtrrumetro.blocks;

import mtr.block.IBlock;
import mtr.mappings.BlockDirectionalMapper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
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.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public class BlockMoscowOldInfoSosStand extends BlockDirectionalMapper implements IBlock {
public BlockMoscowOldInfoSosStand() {
super(Properties.of(Material.METAL, MaterialColor.COLOR_GRAY).requiresCorrectToolForDrops().strength(2).noOcclusion());
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter blockGetter, BlockPos pos, CollisionContext collisionContext) {
double height = IBlock.getStatePropertySafe(state, THIRD) == EnumThird.UPPER ? 9.5 : 16;
return IBlock.getVoxelShapeByDirection(2, 0, 6.7, 14, height, 9.3, IBlock.getStatePropertySafe(state, FACING));
}

@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
if (!world.isClientSide) {
final Direction facing = IBlock.getStatePropertySafe(state, FACING);
world.setBlock(pos.above(), defaultBlockState().setValue(FACING, facing).setValue(THIRD, EnumThird.MIDDLE), 3);
world.setBlock(pos.above(2), defaultBlockState().setValue(FACING, facing).setValue(THIRD, EnumThird.UPPER), 3);
world.updateNeighborsAt(pos, Blocks.AIR);
state.updateNeighbourShapes(world, pos, 3);
}
}

@Override
public void playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) {
switch (IBlock.getStatePropertySafe(state, THIRD)) {
case MIDDLE:
IBlock.onBreakCreative(world, player, pos.below());
break;
case UPPER:
IBlock.onBreakCreative(world, player, pos.below(2));
break;
}
super.playerWillDestroy(world, pos, state, player);
}

@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
if ((direction == Direction.UP && IBlock.getStatePropertySafe(state, THIRD) != EnumThird.UPPER || direction == Direction.DOWN && IBlock.getStatePropertySafe(state, THIRD) != EnumThird.LOWER) && !newState.is(this)) {
return Blocks.AIR.defaultBlockState();
} else {
return state;
}
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
return IBlock.isReplaceable(ctx, Direction.UP, 3) ? defaultBlockState().setValue(FACING, ctx.getHorizontalDirection()).setValue(THIRD, EnumThird.LOWER) : null;
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, THIRD);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ru.weryskok.mtrrumetro.items;

import mtr.block.BlockPSDAPGBase;
import mtr.block.IBlock;
import mtr.item.ItemWithCreativeTabBase;
import net.minecraft.core.BlockPos;
Expand All @@ -13,6 +12,7 @@
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import ru.weryskok.mtrrumetro.CreativeModeTabs;
import ru.weryskok.mtrrumetro.Blocks;
import ru.weryskok.mtrrumetro.blocks.*;

public class ItemSPBHorizontalElevatorDoor extends ItemWithCreativeTabBase implements IBlock {

Expand All @@ -36,7 +36,7 @@ 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(BlockPSDAPGBase.FACING, playerFacing).setValue(HALF, y == 1 ? DoubleBlockHalf.UPPER : DoubleBlockHalf.LOWER);
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"multipart": [
{
"when": {
"facing": "north",
"third": "lower"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_bottom"
}
},
{
"when": {
"facing": "east",
"third": "lower"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_bottom",
"y": 90
}
},
{
"when": {
"facing": "south",
"third": "lower"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_bottom",
"y": 180
}
},
{
"when": {
"facing": "west",
"third": "lower"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_bottom",
"y": 270
}
},
{
"when": {
"facing": "north",
"third": "middle"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_middle"
}
},
{
"when": {
"facing": "east",
"third": "middle"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_middle",
"y": 90
}
},
{
"when": {
"facing": "south",
"third": "middle"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_middle",
"y": 180
}
},
{
"when": {
"facing": "west",
"third": "middle"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_middle",
"y": 270
}
},
{
"when": {
"facing": "north",
"third": "upper"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_top"
}
},
{
"when": {
"facing": "east",
"third": "upper"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_top",
"y": 90
}
},
{
"when": {
"facing": "south",
"third": "upper"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_top",
"y": 180
}
},
{
"when": {
"facing": "west",
"third": "upper"
},
"apply": {
"model": "russianmetro:block/moscow_old_infosos_stand_top",
"y": 270
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"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",
"block.russianmetro.moscow_old_infosos_stand": "Moscow \"Info-SOS\" Stand"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"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": "Петербургские станционные двери «Горизонтальный лифт»",
"block.russianmetro.moscow_old_infosos_stand": "Московский стенд «Инфосос»"
}
Loading

0 comments on commit fd7a551

Please sign in to comment.