-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCombinedRedstoneInput.java
More file actions
37 lines (31 loc) · 1.34 KB
/
Copy pathCombinedRedstoneInput.java
File metadata and controls
37 lines (31 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.troblecodings.signals.blocks;
import java.util.Optional;
import com.troblecodings.signals.tileentitys.RedstoneIOTileEntity;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class CombinedRedstoneInput extends RedstoneInput {
@Override
public void neighborChanged(final IBlockState state, final World worldIn, final BlockPos pos,
final Block blockIn, final BlockPos fromPos) {
if (worldIn.isRemote)
return;
final boolean currentState = state.getValue(POWER);
final boolean hasNeighborSignal = worldIn.isBlockPowered(pos);
final RedstoneIOTileEntity tile = (RedstoneIOTileEntity) worldIn.getTileEntity(pos);
if (currentState && !hasNeighborSignal) {
worldIn.setBlockState(pos, state.withProperty(POWER, false));
tile.sendInputOff();
} else if (hasNeighborSignal && !currentState) {
worldIn.setBlockState(pos, state.withProperty(POWER, true));
tile.sendInputOn();
} else if (!hasNeighborSignal) {
worldIn.setBlockState(pos, state.withProperty(POWER, false));
}
}
@Override
public Optional<String> getSupplierWrapperName() {
return Optional.of("combiredstoneinput");
}
}