Skip to content

Commit

Permalink
Add basic machine block with facing properties
Browse files Browse the repository at this point in the history
  • Loading branch information
HyCraftHD committed Nov 15, 2019
1 parent 451bca4 commit 88c9196
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/main/java/info/u_team/u_mod/block/basic/BasicMachineBlock.java
@@ -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)));
}

}

0 comments on commit 88c9196

Please sign in to comment.