-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
- Move redstone methods out of the IAPIEnvironment, and into a new RedstoneAccess. We similarly move the implementation from Environment into a new RedstoneState class. The interface is possibly a little redundant (interfaces with a single implementation are always a little suspect), but it's nice to keep the consumer/producer interfaces separate. - Abstract most redstone API methods into a separate shared class, that can be used by both the rs API and the new redstone relay. - Add the new redstone relay block. The docs are probably a little lacking here, but I really struggled to write anything which wasn't just "look, it's the same as the redstone API".
- Loading branch information
There are no files selected for viewing
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.
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-FileCopyrightText: 2024 The CC: Tweaked Developers | ||
// | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package dan200.computercraft.shared.peripheral.redstone; | ||
|
||
import dan200.computercraft.shared.common.IBundledRedstoneBlock; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.BlockGetter; | ||
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.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.StateDefinition; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* The block for redstone relays. This mostly just forwards method calls to the {@linkplain RedstoneRelayBlockEntity | ||
* block entity}. | ||
*/ | ||
public final class RedstoneRelayBlock extends HorizontalDirectionalBlock implements EntityBlock, IBundledRedstoneBlock { | ||
public RedstoneRelayBlock(Properties properties) { | ||
super(properties); | ||
registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH)); | ||
} | ||
|
||
@Override | ||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> properties) { | ||
properties.add(FACING); | ||
} | ||
|
||
@Override | ||
public BlockState getStateForPlacement(BlockPlaceContext placement) { | ||
return defaultBlockState().setValue(FACING, placement.getHorizontalDirection()); | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { | ||
super.tick(state, level, pos, random); | ||
|
||
if (level.getBlockEntity(pos) instanceof RedstoneRelayBlockEntity relay) relay.update(); | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public boolean isSignalSource(@Nonnull BlockState state) { | ||
return true; | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public int getDirectSignal(@Nonnull BlockState state, BlockGetter level, @Nonnull BlockPos pos, @Nonnull Direction incomingSide) { | ||
return level.getBlockEntity(pos) instanceof RedstoneRelayBlockEntity relay ? relay.getRedstoneOutput(incomingSide.getOpposite()) : 0; | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { | ||
return getDirectSignal(state, level, pos, direction); | ||
} | ||
|
||
@Override | ||
public int getBundledRedstoneOutput(Level level, BlockPos pos, Direction side) { | ||
return level.getBlockEntity(pos) instanceof RedstoneRelayBlockEntity relay ? relay.getBundledRedstoneOutput(side) : 0; | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public void neighborChanged(@Nonnull BlockState state, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Block neighbourBlock, @Nonnull BlockPos neighbourPos, boolean isMoving) { | ||
if (world.getBlockEntity(pos) instanceof RedstoneRelayBlockEntity relay) relay.neighborChanged(neighbourPos); | ||
} | ||
|
||
@Override | ||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { | ||
return new RedstoneRelayBlockEntity(pos, state); | ||
} | ||
} |