Compare commits

..

No commits in common. "c4cacd402b2cf0e820ff597b33cf7f0a62607b3c" and "ede9ae13396de8e3a2daa537d290e6ffe4f3cb01" have entirely different histories.

View file

@ -27,34 +27,33 @@ import us.minecraftchest2.hdm_mod.world.dimension.SimpleTeleporter;
import javax.annotation.Nullable;
import java.util.stream.Stream;
/**
* Custom window block class, serving as a dimensional portal between worlds.
* Inherits directional placement capabilities from HorizontalBlock.
* A custom window block that acts as a dimensional portal when activated
* Extends HorizontalBlock to support directional placement
*/
public class Window extends HorizontalBlock {
/**
* Constructor for Window block; forwards the properties to the parent constructor.
*/
public Window(Properties builder) {
super(builder);
}
// VoxelShapes for visually and physically shaping the block based on orientation.
// Each direction (N/E/S/W) has a custom composition of rectangular regions.
/** Shape for the block facing NORTH. */
// VoxelShapes define the physical shape of the block for each direction (NORTH, EAST, SOUTH, WEST)
// These shapes are made up of multiple cubic sections combined
private static final VoxelShape SHAPE_N = Stream.of(
Block.makeCuboidShape(5, 11, 5, 6, 13, 11), // Window frame elements (left, etc.)
Block.makeCuboidShape(4, 0, 4, 12, 1, 12), // Base of window
Block.makeCuboidShape(5, 1, 5, 11, 2, 11), // Lower window frame
Block.makeCuboidShape(6, 2, 6, 10, 10, 10), // Glass pane
Block.makeCuboidShape(5, 10, 4, 11, 11, 12), // Top frame
Block.makeCuboidShape(5, 11, 4, 11, 12, 5), // Decorative details
Block.makeCuboidShape(5, 11, 11, 11, 14, 12),// Upper right details
Block.makeCuboidShape(10, 11, 5, 11, 13, 11) // Right vertical side
Block.makeCuboidShape(5, 11, 5, 6, 13, 11), // Window frame pieces
Block.makeCuboidShape(4, 0, 4, 12, 1, 12), // Base
Block.makeCuboidShape(5, 1, 5, 11, 2, 11), // Lower frame
Block.makeCuboidShape(6, 2, 6, 10, 10, 10), // Main window pane
Block.makeCuboidShape(5, 10, 4, 11, 11, 12), // Upper frame
Block.makeCuboidShape(5, 11, 4, 11, 12, 5), // Top decorative elements
Block.makeCuboidShape(5, 11, 11, 11, 14, 12),
Block.makeCuboidShape(10, 11, 5, 11, 13, 11)
).reduce((v1, v2) -> VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR)).get();
/** Shape for the block facing EAST (rotated). */
// Similar shape definitions for other directions...
// (SHAPE_E, SHAPE_S, SHAPE_W follow the same pattern but rotated)
private static final VoxelShape SHAPE_E = Stream.of(
Block.makeCuboidShape(5, 11, 5, 11, 13, 6),
Block.makeCuboidShape(4, 0, 4, 12, 1, 12),
@ -66,7 +65,6 @@ public class Window extends HorizontalBlock {
Block.makeCuboidShape(5, 11, 10, 11, 13, 11)
).reduce((v1, v2) -> VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR)).get();
/** Shape for the block facing SOUTH. */
private static final VoxelShape SHAPE_S = Stream.of(
Block.makeCuboidShape(10, 11, 5, 11, 13, 11),
Block.makeCuboidShape(4, 0, 4, 12, 1, 12),
@ -78,7 +76,6 @@ public class Window extends HorizontalBlock {
Block.makeCuboidShape(5, 11, 5, 6, 13, 11)
).reduce((v1, v2) -> VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR)).get();
/** Shape for the block facing WEST. */
private static final VoxelShape SHAPE_W = Stream.of(
Block.makeCuboidShape(5, 11, 10, 11, 13, 11),
Block.makeCuboidShape(4, 0, 4, 12, 1, 12),
@ -91,45 +88,36 @@ public class Window extends HorizontalBlock {
).reduce((v1, v2) -> VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR)).get();
/**
* Handles when a player right-clicks/interacts with this block.
* Triggers portal teleportation if conditions are met.
* Handles player interaction with the window block
* @param state Current block state
* @param worldIn World instance
* @param pos Block position
* @param player Player who activated the block
* @param handIn Hand used for interaction
* @param hit Hit result information
* @return Result of the interaction
*/
@SuppressWarnings("deprecation")
@Override
public ActionResultType onBlockActivated(
BlockState state,
World worldIn,
BlockPos pos,
PlayerEntity player,
Hand handIn,
BlockRayTraceResult hit
) {
// Only process on the server side, avoid duplicating logic on client
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
if (worldIn.isRemote()) return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
// Do nothing if the player is crouching (commonly used for alternative interactions)
if (player.isCrouching()) return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
// Get the server instance safely
if (worldIn.getServer() == null) return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
MinecraftServer server = worldIn.getServer();
// Check if in custom dimension; if so, teleport to Overworld
if (worldIn.getDimensionKey() == ModDimensions.World1) {
ServerWorld overWorld = server.getWorld(World.OVERWORLD);
if (overWorld != null) {
player.changeDimension(overWorld, new SimpleTeleporter(pos, false));
}
}
// Set up for teleportation based on current dimension
ServerWorld targetWorld;
boolean goingToCustom = worldIn.getDimensionKey() != ModDimensions.World1;
if (goingToCustom) {
// Teleporting from Overworld to custom dimension
targetWorld = server.getWorld(ModDimensions.World1);
} else {
// From custom dimension, teleport to Overworld
ServerWorld world1 = server.getWorld(ModDimensions.World1);
if (world1 != null) {
player.changeDimension(world1, new SimpleTeleporter(pos, true));
@ -137,12 +125,10 @@ public class Window extends HorizontalBlock {
targetWorld = server.getWorld(World.OVERWORLD);
}
// Attempt teleport if a valid world was found
if (targetWorld != null) {
SimpleTeleporter teleporter = new SimpleTeleporter(pos, goingToCustom);
player.changeDimension(targetWorld, teleporter);
// Notify the player about the result
if (teleporter.wasSuccessful()) {
player.sendMessage(new StringTextComponent("Teleportation successful!"), player.getUniqueID());
} else {
@ -152,13 +138,12 @@ public class Window extends HorizontalBlock {
return ActionResultType.SUCCESS;
}
// Fall back to default processing if teleportation did not occur
return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
}
/**
* Returns the block's physical outline for rendering and collision.
* The shape depends on the current facing direction of the block.
* Returns the appropriate shape for the block based on its facing direction
*/
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
@ -177,8 +162,7 @@ public class Window extends HorizontalBlock {
}
/**
* Registers the horizontal facing property with the block state container,
* enabling the block to store which direction it is facing.
* Adds the horizontal-facing property to the block's state container
*/
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
@ -186,8 +170,7 @@ public class Window extends HorizontalBlock {
}
/**
* Determines the block's initial facing based on the placement context.
* The block will face opposite to the player's direction when placed.
* Determines the block's facing direction when placed
*/
@Nullable
@Override