ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java

61 lines
2.2 KiB
Java
Raw Normal View History

2016-05-05 17:29:39 +02:00
package de.ellpeck.actuallyadditions.mod.tile;
2019-05-02 09:10:29 +02:00
import java.util.Arrays;
2016-05-05 17:29:39 +02:00
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
2016-05-05 17:29:39 +02:00
2019-05-02 09:10:29 +02:00
public class TileEntityPhantomRedstoneface extends TileEntityPhantomface {
2016-05-05 17:29:39 +02:00
2016-05-19 20:05:12 +02:00
public final int[] providesStrong = new int[EnumFacing.values().length];
public final int[] providesWeak = new int[EnumFacing.values().length];
2016-05-05 17:29:39 +02:00
2016-05-19 20:05:12 +02:00
private final int[] lastProvidesStrong = new int[this.providesStrong.length];
private final int[] lastProvidesWeak = new int[this.providesWeak.length];
2016-05-05 17:29:39 +02:00
2019-05-02 09:10:29 +02:00
public TileEntityPhantomRedstoneface() {
2016-05-05 17:29:39 +02:00
super("redstoneface");
}
@Override
2019-05-02 09:10:29 +02:00
public void updateEntity() {
if (!this.world.isRemote) {
if (this.isBoundThingInRange()) {
2016-11-26 21:32:27 +01:00
IBlockState boundState = this.world.getBlockState(this.boundPosition);
2019-05-02 09:10:29 +02:00
if (boundState != null) {
2016-05-05 17:29:39 +02:00
Block boundBlock = boundState.getBlock();
2019-05-02 09:10:29 +02:00
if (boundBlock != null) {
for (int i = 0; i < EnumFacing.values().length; i++) {
2016-05-05 17:29:39 +02:00
EnumFacing facing = EnumFacing.values()[i];
this.providesWeak[i] = boundState.getWeakPower(this.world, this.boundPosition, facing);
this.providesStrong[i] = boundState.getStrongPower(this.world, this.boundPosition, facing);
2016-05-05 17:29:39 +02:00
}
}
}
}
}
2016-05-05 17:29:39 +02:00
super.updateEntity();
}
2016-05-05 17:29:39 +02:00
@Override
2019-05-02 09:10:29 +02:00
protected boolean doesNeedUpdateSend() {
return super.doesNeedUpdateSend() || !Arrays.equals(this.providesStrong, this.lastProvidesStrong) || !Arrays.equals(this.providesWeak, this.lastProvidesWeak);
}
@Override
2019-05-02 09:10:29 +02:00
protected void onUpdateSent() {
System.arraycopy(this.providesWeak, 0, this.lastProvidesWeak, 0, this.providesWeak.length);
System.arraycopy(this.providesStrong, 0, this.lastProvidesStrong, 0, this.providesStrong.length);
super.onUpdateSent();
2016-05-05 17:29:39 +02:00
}
@Override
2019-05-02 09:10:29 +02:00
protected boolean isCapabilitySupported(Capability<?> capability) {
return false;
}
2016-05-05 17:29:39 +02:00
}