Skip to content

Commit

Permalink
Metro Assets
Browse files Browse the repository at this point in the history
  • Loading branch information
a0a7 committed Sep 25, 2023
1 parent b12a67e commit 20f3ef2
Show file tree
Hide file tree
Showing 26 changed files with 949 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package systems.alexander.bellsandwhistles.block;

import com.simibubi.create.content.decoration.TrainTrapdoorBlock;
import com.simibubi.create.content.decoration.encasing.CasingBlock;
import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorBlock;
import com.tterrag.registrate.builders.BlockBuilder;
import net.minecraft.world.item.CreativeModeTab;
import systems.alexander.bellsandwhistles.BellsAndWhistles;
Expand Down Expand Up @@ -29,7 +32,6 @@ public static <T extends Block, P> NonNullFunction<BlockBuilder<T, P>, BlockBuil
}
public static final DeferredRegister<Block> BLOCKS =
DeferredRegister.create(ForgeRegistries.BLOCKS, BellsAndWhistles.MOD_ID);

public static final RegistryObject<Block> STATION_PLATFORM = registerBlock("station_platform",
() -> new PlatformBlock(BlockBehaviour.Properties.copy(Blocks.SMOOTH_STONE).sound(SoundType.STONE).noOcclusion()));
public static final RegistryObject<Block> ANDESITE_GRAB_RAILS = registerBlock("andesite_grab_rails",
Expand All @@ -46,6 +48,24 @@ public static <T extends Block, P> NonNullFunction<BlockBuilder<T, P>, BlockBuil
public static final RegistryObject<Block> COPPER_BOGIE_STEPS = registerBlock("copper_bogie_steps",
() -> new MetalBogieStepsBlock(BlockBehaviour.Properties.copy(Blocks.LADDER).sound(SoundType.METAL).noOcclusion()));

public static final RegistryObject<Block> METRO_CASING = registerBlock("metro_casing",
() -> new CasingBlock(BlockBehaviour.Properties.copy(Blocks.MOSSY_COBBLESTONE).sound(SoundType.METAL), true));

public static final RegistryObject<Block> CORRUGATED_METRO_CASING = registerBlock("corrugated_metro_casing",
() -> new CasingBlock(BlockBehaviour.Properties.copy(Blocks.MOSSY_COBBLESTONE).sound(SoundType.METAL), true));
public static final RegistryObject<Block> METRO_DOOR = registerBlock("metro_door",
() -> new SlidingDoorBlock(BlockBehaviour.Properties.copy(Blocks.MOSSY_COBBLESTONE).sound(SoundType.METAL).noOcclusion(), true));

public static final RegistryObject<Block> METRO_TRAPDOOR = registerBlock("metro_trapdoor",
() -> new TrainTrapdoorBlock(BlockBehaviour.Properties.copy(Blocks.MOSSY_COBBLESTONE).sound(SoundType.METAL).noOcclusion()));

public static final RegistryObject<Block> METRO_PANEL = registerBlock("metro_panel",
() -> new TrainTrapdoorBlock(BlockBehaviour.Properties.copy(Blocks.MOSSY_COBBLESTONE).sound(SoundType.METAL).noOcclusion()));

public static final RegistryObject<Block> CORRUGATED_METRO_PANEL = registerBlock("corrugated_metro_panel",
() -> new TrainTrapdoorBlock(BlockBehaviour.Properties.copy(Blocks.MOSSY_COBBLESTONE).sound(SoundType.METAL).noOcclusion()));


public static final RegistryObject<Block> METAL_PILOT = registerBlock("metal_pilot",
() -> new PilotBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK).noOcclusion()));
public static final RegistryObject<Block> ANDESITE_PILOT = registerBlock("andesite_pilot",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package systems.alexander.bellsandwhistles.block.custom;

import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.decoration.copycat.CopycatBlockEntity;
import com.simibubi.create.content.decoration.copycat.CopycatPanelBlock;
import com.simibubi.create.content.decoration.copycat.CopycatSpecialCases;
import com.simibubi.create.foundation.placement.IPlacementHelper;
import com.simibubi.create.foundation.placement.PlacementHelpers;
import com.simibubi.create.foundation.placement.PlacementOffset;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
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.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;

import java.util.List;
import java.util.function.Predicate;

public class PanelBlock extends Block {
public static final DirectionProperty FACING = BlockStateProperties.FACING;

private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper());

public PanelBlock(Properties pProperties) {
super(pProperties);
registerDefaultState(defaultBlockState().setValue(FACING, Direction.UP));
}
public static BlockState getMaterial(BlockGetter reader, BlockPos targetPos) {
return Blocks.STONE.defaultBlockState();
}
public boolean canFaceBeOccluded(BlockState state, Direction face) {
return state.getValue(FACING)
.getOpposite() == face;
}
public boolean shouldFaceAlwaysRender(BlockState state, Direction face) {
return canFaceBeOccluded(state, face.getOpposite());
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
BlockState stateForPlacement = super.getStateForPlacement(pContext);
return stateForPlacement.setValue(FACING, pContext.getNearestLookingDirection()
.getOpposite());
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
super.createBlockStateDefinition(pBuilder.add(FACING));
}

@Override
public boolean supportsExternalFaceHiding(BlockState state) {
return true;
}

@Override
public boolean hidesNeighborFace(BlockGetter level, BlockPos pos, BlockState state, BlockState neighborState,
Direction dir) {
if (state.is(this) == neighborState.is(this)) {
if (CopycatSpecialCases.isBarsMaterial(getMaterial(level, pos))
&& CopycatSpecialCases.isBarsMaterial(getMaterial(level, pos.relative(dir))))
return state.getValue(FACING) == neighborState.getValue(FACING);
if (getMaterial(level, pos).skipRendering(getMaterial(level, pos.relative(dir)), dir.getOpposite()))
return isOccluded(state, neighborState, dir.getOpposite());
}

return state.getValue(FACING) == dir.getOpposite()
&& getMaterial(level, pos).skipRendering(neighborState, dir.getOpposite());
}


public static boolean isOccluded(BlockState state, BlockState other, Direction pDirection) {
Direction facing = state.getValue(FACING);
if (facing.getOpposite() == other.getValue(FACING) && pDirection == facing)
return true;
if (other.getValue(FACING) != facing)
return false;
return pDirection.getAxis() != facing.getAxis();
}

@Override
public BlockState rotate(BlockState state, Rotation rot) {
return state.setValue(FACING, rot.rotate(state.getValue(FACING)));
}

@Override
@SuppressWarnings("deprecation")
public BlockState mirror(BlockState state, Mirror mirrorIn) {
return state.rotate(mirrorIn.getRotation(state.getValue(FACING)));
}


@MethodsReturnNonnullByDefault
private static class PlacementHelper implements IPlacementHelper {
@Override
public Predicate<ItemStack> getItemPredicate() {
return AllBlocks.COPYCAT_PANEL::isIn;
}

@Override
public Predicate<BlockState> getStatePredicate() {
return AllBlocks.COPYCAT_PANEL::has;
}

@Override
public PlacementOffset getOffset(Player player, Level world, BlockState state, BlockPos pos,
BlockHitResult ray) {
List<Direction> directions = IPlacementHelper.orderedByDistanceExceptAxis(pos, ray.getLocation(),
state.getValue(FACING)
.getAxis(),
dir -> world.getBlockState(pos.relative(dir))
.getMaterial()
.isReplaceable());

if (directions.isEmpty())
return PlacementOffset.fail();
else {
return PlacementOffset.success(pos.relative(directions.get(0)),
s -> s.setValue(FACING, state.getValue(FACING)));
}
}
}


}
Loading

0 comments on commit 20f3ef2

Please sign in to comment.