Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic machine block with facing properties
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/java/info/u_team/u_mod/block/basic/BasicMachineBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package info.u_team.u_mod.block.basic; | ||
|
||
import info.u_team.u_mod.init.*; | ||
import info.u_team.u_team_core.block.UTileEntityBlock; | ||
import net.minecraft.block.*; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.BlockItemUseContext; | ||
import net.minecraft.state.DirectionProperty; | ||
import net.minecraft.state.StateContainer.Builder; | ||
import net.minecraft.state.properties.BlockStateProperties; | ||
import net.minecraft.util.*; | ||
import net.minecraft.util.math.*; | ||
import net.minecraft.world.World; | ||
|
||
public class BasicMachineBlock extends UTileEntityBlock { | ||
|
||
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; | ||
|
||
public BasicMachineBlock(String name) { | ||
super(name, UModItemGroups.GROUP, Properties.create(Material.IRON), () -> UModTileEntityTypes.ENERGY_FURNANCE); | ||
setDefaultState(getDefaultState().with(FACING, Direction.NORTH)); | ||
} | ||
|
||
@Override | ||
public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) { | ||
return openContainer(world, pos, player, true); | ||
} | ||
|
||
// Facing | ||
|
||
@Override | ||
public BlockState getStateForPlacement(BlockItemUseContext context) { | ||
return getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite()); | ||
} | ||
|
||
@Override | ||
protected void fillStateContainer(Builder<Block, BlockState> builder) { | ||
builder.add(FACING); | ||
} | ||
|
||
@Override | ||
public BlockState rotate(BlockState state, Rotation rotation) { | ||
return state.with(FACING, rotation.rotate(state.get(FACING))); | ||
} | ||
|
||
@Override | ||
public BlockState mirror(BlockState state, Mirror mirror) { | ||
return state.rotate(mirror.toRotation(state.get(FACING))); | ||
} | ||
|
||
} |