Skip to content

Commit

Permalink
APG Tianjin
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Aug 6, 2024
1 parent ec1c4c7 commit 3d00e90
Show file tree
Hide file tree
Showing 21 changed files with 800 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public interface BlockEntityTypes
BlockEntityTypeRegistryObject<BlockRailwaySignTianjinBMT.BlockEntity> RAILWAY_SIGN_TIANJIN_BMT_5_EVEN = Registry.registerBlockEntityType("railway_sign_tianjin_bmt_5_even", (pos, state) -> new BlockRailwaySignTianjinBMT.BlockEntity(5, false, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_BMT_5_EVEN::get);
BlockEntityTypeRegistryObject<BlockRailwaySignTianjinBMT.BlockEntity> RAILWAY_SIGN_TIANJIN_BMT_6_EVEN = Registry.registerBlockEntityType("railway_sign_tianjin_bmt_6_even", (pos, state) -> new BlockRailwaySignTianjinBMT.BlockEntity(6, false, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_BMT_6_EVEN::get);
BlockEntityTypeRegistryObject<BlockRailwaySignTianjinBMT.BlockEntity> RAILWAY_SIGN_TIANJIN_BMT_7_EVEN = Registry.registerBlockEntityType("railway_sign_tianjin_bmt_7_even", (pos, state) -> new BlockRailwaySignTianjinBMT.BlockEntity(7, false, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_BMT_7_EVEN::get);
BlockEntityTypeRegistryObject<BlockAPGDoorTianjin.BlockEntity> APG_DOOR_TIANJIN = Registry.registerBlockEntityType("apg_door_tianjin", BlockAPGDoorTianjin.BlockEntity::new, BlockList.APG_DOOR_TIANJIN::get);

static void registerBlockEntities() {
// Calling this class to initialize constants
Expand Down
3 changes: 3 additions & 0 deletions fabric/src/main/java/ziyue/tjmetro/mod/BlockList.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public interface BlockList
BlockRegistryObject RAILWAY_SIGN_TIANJIN_BMT_6_EVEN = Registry.registerBlockWithBlockItem("railway_sign_tianjin_bmt_6_even", () -> new Block(new BlockRailwaySignTianjinBMT(6, false)), RAILWAY_SIGNS);
BlockRegistryObject RAILWAY_SIGN_TIANJIN_BMT_7_EVEN = Registry.registerBlockWithBlockItem("railway_sign_tianjin_bmt_7_even", () -> new Block(new BlockRailwaySignTianjinBMT(7, false)), RAILWAY_SIGNS);
BlockRegistryObject RAILWAY_SIGN_TIANJIN_BMT_MIDDLE = Registry.registerBlock("railway_sign_tianjin_bmt_middle", () -> new Block(new BlockRailwaySignTianjinBMT(0, false)));
BlockRegistryObject APG_DOOR_TIANJIN = Registry.registerBlock("apg_door_tianjin", () -> new Block(new BlockAPGDoorTianjin()));
BlockRegistryObject APG_GLASS_TIANJIN = Registry.registerBlock("apg_glass_tianjin", () -> new Block(new BlockAPGGlassTianjin()));
BlockRegistryObject APG_GLASS_END_TIANJIN = Registry.registerBlock("apg_glass_end_tianjin", () -> new Block(new BlockAPGGlassEndTianjin()));

static void registerBlocks() {
// Calling this class to initialize constants
Expand Down
11 changes: 7 additions & 4 deletions fabric/src/main/java/ziyue/tjmetro/mod/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
import org.mtr.mapping.holder.Item;
import org.mtr.mapping.mapper.ItemExtension;
import org.mtr.mapping.registry.ItemRegistryObject;
import ziyue.tjmetro.mod.item.ItemPSDTianjinBase;
import ziyue.tjmetro.mod.item.ItemPSDAPGTianjinBase;

import static ziyue.tjmetro.mod.client.Filters.GATES;
import static ziyue.tjmetro.mod.client.Filters.MISCELLANEOUS;

public interface ItemList
{
ItemRegistryObject WRENCH = Registry.registerItem("wrench", itemSettings -> new Item(new ItemExtension(itemSettings.maxCount(1))), MISCELLANEOUS);
ItemRegistryObject PSD_DOOR_TIANJIN = Registry.registerItem("psd_door_tianjin", itemSettings -> new Item(new ItemPSDTianjinBase(BlockList.PSD_DOOR_TIANJIN, itemSettings)), GATES);
ItemRegistryObject PSD_GLASS_TIANJIN = Registry.registerItem("psd_glass_tianjin", itemSettings -> new Item(new ItemPSDTianjinBase(BlockList.PSD_GLASS_TIANJIN, itemSettings)), GATES);
ItemRegistryObject PSD_GLASS_END_TIANJIN = Registry.registerItem("psd_glass_end_tianjin", itemSettings -> new Item(new ItemPSDTianjinBase(BlockList.PSD_GLASS_END_TIANJIN, itemSettings)), GATES);
ItemRegistryObject PSD_DOOR_TIANJIN = Registry.registerItem("psd_door_tianjin", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.PSD_DOOR_TIANJIN, itemSettings)), GATES);
ItemRegistryObject PSD_GLASS_TIANJIN = Registry.registerItem("psd_glass_tianjin", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.PSD_GLASS_TIANJIN, itemSettings)), GATES);
ItemRegistryObject PSD_GLASS_END_TIANJIN = Registry.registerItem("psd_glass_end_tianjin", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.PSD_GLASS_END_TIANJIN, itemSettings)), GATES);
ItemRegistryObject APG_DOOR_TIANJIN = Registry.registerItem("apg_door_tianjin", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.APG_DOOR_TIANJIN, itemSettings)), GATES);
ItemRegistryObject APG_GLASS_TIANJIN = Registry.registerItem("apg_glass_tianjin", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.APG_GLASS_TIANJIN, itemSettings)), GATES);
ItemRegistryObject APG_GLASS_END_TIANJIN = Registry.registerItem("apg_glass_end_tianjin", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.APG_GLASS_END_TIANJIN, itemSettings)), GATES);

static void registerItems() {
// Calling this class to initialize constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.mtr.mapping.mapper.TextHelper;
import org.mtr.mod.Blocks;
import org.mtr.mod.Items;
import org.mtr.mod.render.RenderAPGGlass;
import org.mtr.mod.render.RenderPSDAPGDoor;
import ziyue.tjmetro.mod.client.Filters;
import ziyue.tjmetro.mod.config.ConfigClient;
Expand All @@ -29,6 +30,9 @@ public static void init() {
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.PSD_DOOR_TIANJIN);
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.PSD_GLASS_TIANJIN);
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.PSD_GLASS_END_TIANJIN);
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.APG_DOOR_TIANJIN);
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.APG_GLASS_TIANJIN);
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.APG_GLASS_END_TIANJIN);
RegistryClient.registerBlockRenderType(RenderLayer.getTranslucent(), BlockList.ROLLING);

RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.STATION_NAME_SIGN_1, RenderStationNameSign::new);
Expand Down Expand Up @@ -84,7 +88,7 @@ public static void init() {
RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_BMT_5_EVEN, RenderRailwaySignTianjinBMT::new);
RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_BMT_6_EVEN, RenderRailwaySignTianjinBMT::new);
RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_BMT_7_EVEN, RenderRailwaySignTianjinBMT::new);

RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.APG_DOOR_TIANJIN, dispatcher -> new RenderPSDAPGDoor<>(dispatcher, 2));

RegistryClient.registerEntityRenderer(EntityTypes.SEAT, RenderSeat::new);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ziyue.tjmetro.mod.block;

import org.mtr.mapping.holder.BlockPos;
import org.mtr.mapping.holder.BlockState;
import org.mtr.mapping.holder.Item;
import org.mtr.mapping.mapper.BlockEntityExtension;
import org.mtr.mod.block.BlockPSDAPGDoorBase;
import ziyue.tjmetro.mod.BlockEntityTypes;
import ziyue.tjmetro.mod.ItemList;
import ziyue.tjmetro.mod.block.base.BlockFlagAPGTianjin;

import javax.annotation.Nonnull;

public class BlockAPGDoorTianjin extends BlockPSDAPGDoorBase implements BlockFlagAPGTianjin
{
@Override
protected boolean isAPG() {
return true;
}

@Nonnull
@Override
public Item asItem2() {
return ItemList.APG_DOOR_TIANJIN.get();
}

@Override
public BlockEntityExtension createBlockEntity(BlockPos blockPos, BlockState blockState) {
return new BlockEntity(blockPos, blockState);
}

public static class BlockEntity extends BlockPSDAPGDoorBase.BlockEntityBase {
public BlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.APG_DOOR_TIANJIN.get(), pos, state);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ziyue.tjmetro.mod.block;

import org.mtr.mapping.holder.Item;
import org.mtr.mod.block.BlockAPGGlassEnd;
import ziyue.tjmetro.mod.ItemList;
import ziyue.tjmetro.mod.block.base.BlockFlagAPGTianjin;

import javax.annotation.Nonnull;

public class BlockAPGGlassEndTianjin extends BlockAPGGlassEnd implements BlockFlagAPGTianjin
{
@Override
protected boolean isAPG() {
return true;
}

@Nonnull
@Override
public Item asItem2() {
return ItemList.APG_GLASS_END_TIANJIN.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ziyue.tjmetro.mod.block;

import org.mtr.mapping.holder.BlockPos;
import org.mtr.mapping.holder.BlockState;
import org.mtr.mapping.holder.Item;
import org.mtr.mapping.mapper.BlockEntityExtension;
import org.mtr.mod.block.BlockAPGGlass;
import ziyue.tjmetro.mod.ItemList;
import ziyue.tjmetro.mod.block.base.BlockFlagAPGTianjin;

import javax.annotation.Nonnull;

public class BlockAPGGlassTianjin extends BlockAPGGlass implements BlockFlagAPGTianjin
{
@Override
protected boolean isAPG() {
return true;
}

@Nonnull
@Override
public Item asItem2() {
return ItemList.APG_GLASS_TIANJIN.get();
}

@Override
public BlockEntityExtension createBlockEntity(BlockPos blockPos, BlockState blockState) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import org.mtr.mapping.mapper.BlockEntityExtension;
import org.mtr.mod.block.BlockPSDAPGDoorBase;
import ziyue.tjmetro.mod.BlockEntityTypes;
import ziyue.tjmetro.mod.BlockList;
import ziyue.tjmetro.mod.ItemList;
import ziyue.tjmetro.mod.block.base.BlockFlagPSDTianjin;

import javax.annotation.Nonnull;

public class BlockPSDDoorTianjin extends BlockPSDAPGDoorBase
public class BlockPSDDoorTianjin extends BlockPSDAPGDoorBase implements BlockFlagPSDTianjin
{
@Nonnull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import org.mtr.mapping.holder.Item;
import org.mtr.mod.block.BlockPSDAPGGlassEndBase;
import ziyue.tjmetro.mod.ItemList;
import ziyue.tjmetro.mod.block.base.BlockFlagPSDTianjin;

import javax.annotation.Nonnull;

public class BlockPSDGlassEndTianjin extends BlockPSDAPGGlassEndBase
public class BlockPSDGlassEndTianjin extends BlockPSDAPGGlassEndBase implements BlockFlagPSDTianjin
{
@Nonnull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import org.mtr.mapping.holder.Item;
import org.mtr.mod.block.BlockPSDAPGGlassBase;
import ziyue.tjmetro.mod.ItemList;
import ziyue.tjmetro.mod.block.base.BlockFlagPSDTianjin;

import javax.annotation.Nonnull;

public class BlockPSDGlassTianjin extends BlockPSDAPGGlassBase
public class BlockPSDGlassTianjin extends BlockPSDAPGGlassBase implements BlockFlagPSDTianjin
{
@Nonnull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import ziyue.tjmetro.mod.BlockEntityTypes;
import ziyue.tjmetro.mod.BlockList;
import ziyue.tjmetro.mod.ItemList;
import ziyue.tjmetro.mod.block.base.BlockFlagPSDTianjin;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.function.Consumer;

public class BlockPSDTopTianjin extends BlockPSDTop
public class BlockPSDTopTianjin extends BlockPSDTop implements BlockFlagPSDTianjin
{
public static final EnumProperty<EnumDoorType> STYLE = EnumProperty.of("style", EnumDoorType.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ziyue.tjmetro.mod.block.base;

public interface BlockFlagAPGTianjin
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ziyue.tjmetro.mod.block.base;

public interface BlockFlagPSDTianjin
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
import org.mtr.mapping.mapper.ItemExtension;
import org.mtr.mapping.mapper.TextHelper;
import org.mtr.mapping.registry.BlockRegistryObject;
import org.mtr.mod.block.BlockPSDAPGBase;
import org.mtr.mod.block.IBlock;
import ziyue.tjmetro.mod.BlockList;
import ziyue.tjmetro.mod.block.BlockPSDDoorTianjin;
import ziyue.tjmetro.mod.block.BlockPSDGlassEndTianjin;
import ziyue.tjmetro.mod.block.BlockPSDGlassTianjin;
import ziyue.tjmetro.mod.block.BlockPSDTopTianjin;
import org.mtr.mod.block.*;
import ziyue.tjmetro.mod.block.*;
import ziyue.tjmetro.mod.block.base.BlockFlagPSDTianjin;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -19,20 +15,20 @@
import static org.mtr.mod.item.ItemPSDAPGBase.blocksNotReplaceable;
import static ziyue.tjmetro.mod.block.BlockPSDTopTianjin.STYLE;

public class ItemPSDTianjinBase extends ItemExtension implements IBlock
public class ItemPSDAPGTianjinBase extends ItemExtension implements IBlock
{
public final Block block;

public ItemPSDTianjinBase(BlockRegistryObject block, ItemSettings settings) {
public ItemPSDAPGTianjinBase(BlockRegistryObject block, ItemSettings settings) {
super(settings);
this.block = block.get();
}

@Nonnull
@Override
public ActionResult useOnBlock2(ItemUsageContext context) {
final int horizontalBlocks = block.data instanceof BlockPSDDoorTianjin ? 2 : 1;
if (blocksNotReplaceable(context, horizontalBlocks, 3, getBlockStateFromItem().getBlock())) return ActionResult.FAIL;
final int horizontalBlocks = block.data instanceof BlockPSDAPGDoorBase ? 2 : 1;
if (blocksNotReplaceable(context, horizontalBlocks, 3, this.block)) return ActionResult.FAIL;

final World world = context.getWorld();
final Direction playerFacing = context.getPlayerFacing();
Expand All @@ -42,46 +38,41 @@ public ActionResult useOnBlock2(ItemUsageContext context) {
final BlockPos newPos = pos.offset(playerFacing.rotateYClockwise(), x);

for (int y = 0; y < 2; y++) {
final BlockState state = getBlockStateFromItem().with(new Property<>(BlockPSDAPGBase.FACING.data), playerFacing.data).with(new Property<>(HALF.data), y == 1 ? DoubleBlockHalf.UPPER : DoubleBlockHalf.LOWER);
if (block.data instanceof BlockPSDDoorTianjin) {
final BlockState state = this.block.getDefaultState().with(new Property<>(BlockPSDAPGBase.FACING.data), playerFacing.data).with(new Property<>(HALF.data), y == 1 ? DoubleBlockHalf.UPPER : DoubleBlockHalf.LOWER);
if (block.data instanceof BlockPSDAPGDoorBase) {
BlockState neighborState = state.with(new Property<>(SIDE.data), x == 0 ? EnumSide.LEFT : EnumSide.RIGHT);
world.setBlockState(newPos.up(y), neighborState);
} else {
world.setBlockState(newPos.up(y), state.with(new Property<>(SIDE_EXTENDED.data), EnumSide.SINGLE));
}
}
world.setBlockState(newPos.up(2), BlockPSDTopTianjin.getActualState(WorldAccess.cast(world), newPos.up(2)).with(new Property<>(STYLE.data), BlockPSDTopTianjin.EnumDoorType.STATION_NAME));
if (this.block.data instanceof BlockFlagPSDTianjin) {
world.setBlockState(newPos.up(2), BlockPSDTopTianjin.getActualState(WorldAccess.cast(world), newPos.up(2)).with(new Property<>(STYLE.data), BlockPSDTopTianjin.EnumDoorType.STATION_NAME));
}
}

context.getStack().decrement(1);
return ActionResult.SUCCESS;
}

protected BlockState getBlockStateFromItem() {
if (this.block.data instanceof BlockPSDDoorTianjin) {
return BlockList.PSD_DOOR_TIANJIN.get().getDefaultState();
} else if (this.block.data instanceof BlockPSDGlassTianjin) {
return BlockList.PSD_GLASS_TIANJIN.get().getDefaultState();
} else if (this.block.data instanceof BlockPSDGlassEndTianjin) {
return BlockList.PSD_GLASS_END_TIANJIN.get().getDefaultState();
}
return null;
}

@Override
public void addTooltips(ItemStack stack, @Nullable World world, List<MutableText> tooltip, TooltipContext options) {
if (this.block.data instanceof BlockPSDDoorTianjin) {
if (this.block.data instanceof BlockPSDAPGDoorBase) {
tooltip.add(TextHelper.translatable("tooltip.mtr.psd_apg_door").formatted(TextFormatting.GRAY));
} else if (this.block.data instanceof BlockPSDGlassTianjin) {
tooltip.add(TextHelper.translatable("tooltip.mtr.psd_apg_glass").formatted(TextFormatting.GRAY));
} else if (this.block.data instanceof BlockPSDGlassEndTianjin) {
} else if (this.block.data instanceof BlockPSDAPGGlassEndBase) {
tooltip.add(TextHelper.translatable("tooltip.mtr.psd_apg_glass_end").formatted(TextFormatting.GRAY));
} else if (this.block.data instanceof BlockPSDAPGGlassBase) {
tooltip.add(TextHelper.translatable("tooltip.mtr.psd_apg_glass").formatted(TextFormatting.GRAY));
}
}

@Nonnull
@Override
public String getTranslationKey2() {
return "block.tjmetro.psd_tianjin";
if (this.block.data instanceof BlockFlagPSDTianjin) {
return "block.tjmetro.psd_tianjin";
} else {
return "block.tjmetro.apg_tianjin";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "mtr:block/apg_door"
}
}
}
Loading

0 comments on commit 3d00e90

Please sign in to comment.