-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8899d3
commit 27c1861
Showing
5 changed files
with
570 additions
and
0 deletions.
There are no files selected for viewing
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
61 changes: 61 additions & 0 deletions
61
src/main/java/li/cil/oc2/common/block/NetworkSwitchBlock.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,61 @@ | ||
package li.cil.oc2.common.block; | ||
|
||
import li.cil.oc2.common.blockentity.BlockEntities; | ||
import li.cil.oc2.common.blockentity.NetworkHubBlockEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.EntityBlock; | ||
import net.minecraft.world.level.block.HorizontalDirectionalBlock; | ||
import net.minecraft.world.level.block.SoundType; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.StateDefinition; | ||
import net.minecraft.world.level.material.Material; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public final class NetworkSwitchBlock extends HorizontalDirectionalBlock implements EntityBlock { | ||
public NetworkSwitchBlock() { | ||
super(Properties | ||
.of(Material.METAL) | ||
.sound(SoundType.METAL) | ||
.strength(1.5f, 6.0f)); | ||
registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.NORTH)); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////// | ||
|
||
@Override | ||
public BlockState getStateForPlacement(final BlockPlaceContext context) { | ||
return super.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
public void neighborChanged(final BlockState state, final Level level, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) { | ||
final BlockEntity blockEntity = level.getBlockEntity(pos); | ||
if (blockEntity instanceof final NetworkHubBlockEntity networkHub) { | ||
networkHub.handleNeighborChanged(); | ||
} | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////// | ||
// EntityBlock | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { | ||
return BlockEntities.NETWORK_HUB.get().create(pos, state); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////// | ||
|
||
@Override | ||
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) { | ||
super.createBlockStateDefinition(builder); | ||
builder.add(FACING); | ||
} | ||
} |
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
Oops, something went wrong.