You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.4 KiB
Java
72 lines
2.4 KiB
Java
package net.brokenmoon.tiles;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.sound.SoundEvents;
|
|
import net.minecraft.state.StateManager;
|
|
import net.minecraft.state.property.BooleanProperty;
|
|
import net.minecraft.util.ActionResult;
|
|
import net.minecraft.util.Hand;
|
|
import net.minecraft.util.hit.BlockHitResult;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.Direction;
|
|
import net.minecraft.world.BlockView;
|
|
import net.minecraft.world.World;
|
|
|
|
public class RedstoneLink extends Block {
|
|
public RedstoneLink(Settings settings) {
|
|
super(settings);
|
|
setDefaultState(getDefaultState().with(POWERED, false));
|
|
}
|
|
|
|
public static final BooleanProperty POWERED = BooleanProperty.of("powered");
|
|
|
|
@Override
|
|
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
|
builder.add(POWERED);
|
|
}
|
|
|
|
@Override
|
|
public boolean emitsRedstonePower(BlockState state) {
|
|
return state.get(POWERED);
|
|
}
|
|
|
|
@Override
|
|
public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
|
|
if (state.get(POWERED))
|
|
return 15;
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
|
|
if (state.get(POWERED))
|
|
return 15;
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
|
|
for (Direction direction : Direction.values()) {
|
|
world.updateNeighborsAlways(pos.offset(direction), this);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
|
|
if (moved) {
|
|
return;
|
|
}
|
|
for (Direction direction : Direction.values()) {
|
|
world.updateNeighborsAlways(pos.offset(direction), this);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
|
player.playSound(SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON, 1, 1);
|
|
world.setBlockState(pos, state.with(POWERED, !state.get(POWERED)));
|
|
return ActionResult.SUCCESS;
|
|
}
|
|
} |