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

71 lines
2.6 KiB
Java
Raw Normal View History

2016-05-16 22:52:27 +02:00
/*
* This file ("TileEntityPhantomRedstoneface.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2016-05-16 22:52:27 +02:00
*/
2016-05-05 17:29:39 +02:00
package de.ellpeck.actuallyadditions.mod.tile;
import net.minecraft.block.Block;
2021-02-27 16:33:00 +01:00
import net.minecraft.block.BlockState;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
2016-05-05 17:29:39 +02:00
2021-02-27 16:33:00 +01:00
import java.util.Arrays;
2019-05-02 09:10:29 +02:00
public class TileEntityPhantomRedstoneface extends TileEntityPhantomface {
2016-05-05 17:29:39 +02:00
public final int[] providesStrong = new int[Direction.values().length];
public final int[] providesWeak = new int[Direction.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() {
2021-02-27 16:33:00 +01:00
super(ActuallyTiles.PHANTOMREDSTONEFACE_TILE.get());
2016-05-05 17:29:39 +02:00
}
@Override
2019-05-02 09:10:29 +02:00
public void updateEntity() {
if (!this.world.isRemote) {
if (this.isBoundThingInRange()) {
2021-02-26 22:15:48 +01:00
BlockState 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 < Direction.values().length; i++) {
Direction facing = Direction.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
}