Skip to content

Commit

Permalink
Allow windows to be placed vertically, like ED used to have
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSunrize committed Jun 8, 2024
1 parent 9ffa0f3 commit d5b7dee
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -323,21 +324,21 @@ protected void registerStatesAndModels()
ModelFile windowModel = models()
.withExistingParent("treated_window", modLoc("block/window_thick"))
.texture("frame", "immersiveengineering:block/wooden_decoration/treated_wood_vertical");
createHorizontalRotatedBlock(WoodenDecoration.WINDOW, windowModel);
createRotatedBlock(WoodenDecoration.WINDOW, windowModel, IEProperties.FACING_ALL, List.of(), 0, 180);
itemModel(WoodenDecoration.WINDOW, windowModel);
}
{
ModelFile windowModel = models()
.withExistingParent("steel_window", modLoc("block/window_thin"))
.texture("frame", "immersiveengineering:block/metal/storage_steel");
createHorizontalRotatedBlock(MetalDecoration.STEEL_WINDOW, windowModel);
createRotatedBlock(MetalDecoration.STEEL_WINDOW, windowModel, IEProperties.FACING_ALL, List.of(), 0, 180);
itemModel(MetalDecoration.STEEL_WINDOW, windowModel);
}
{
ModelFile windowModel = models()
.withExistingParent("alu_window", modLoc("block/window_thin"))
.texture("frame", "immersiveengineering:block/metal/storage_aluminum");
createHorizontalRotatedBlock(MetalDecoration.ALU_WINDOW, windowModel);
createRotatedBlock(MetalDecoration.ALU_WINDOW, windowModel, IEProperties.FACING_ALL, List.of(), 0, 180);
itemModel(MetalDecoration.ALU_WINDOW, windowModel);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,61 @@
package blusunrize.immersiveengineering.common.blocks.generic;

import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.common.blocks.IEBaseBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition.Builder;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public class WindowBlock extends HorizontalFacingBlock
public class WindowBlock extends IEBaseBlock
{
private static final VoxelShape X_FACING = Block.box(6.75, 0, 0, 9.25, 16, 16);
private static final VoxelShape Y_FACING = Block.box(0, 6.75, 0, 16, 9.25, 16);
private static final VoxelShape Z_FACING = Block.box(0, 0, 6.75, 16, 16, 9.25);

public WindowBlock(Properties blockProps)
{
super(blockProps);
lightOpacity = 0;
}

@Override
protected void createBlockStateDefinition(Builder<Block, BlockState> builder)
{
super.createBlockStateDefinition(builder);
builder.add(IEProperties.FACING_ALL);
}

protected Direction getDefaultFacing()
{
return Direction.NORTH;
}

@Override
protected BlockState getInitDefaultState()
{
BlockState ret = super.getInitDefaultState();
return ret.setValue(IEProperties.FACING_ALL, getDefaultFacing());
}

public BlockState getStateForPlacement(BlockPlaceContext pContext)
{
return this.defaultBlockState().setValue(IEProperties.FACING_ALL, pContext.getNearestLookingDirection());
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context)
{
Direction facing = state.getValue(IEProperties.FACING_HORIZONTAL);
if(facing.getAxis()==Axis.X)
return X_FACING;
return Z_FACING;
Direction facing = state.getValue(IEProperties.FACING_ALL);
return switch(facing.getAxis())
{
case X -> X_FACING;
case Y -> Y_FACING;
case Z -> Z_FACING;
};
}
}

0 comments on commit d5b7dee

Please sign in to comment.