use of com.minecolonies.api.blocks.AbstractBlockMinecoloniesRack in project minecolonies by ldtteam.
the class TileEntityRack method updateBlockState.
@Override
public void updateBlockState() {
if (level != null && level.getBlockState(worldPosition).getBlock() instanceof AbstractBlockMinecoloniesRack) {
if (!main && !single && getOtherChest() != null && !getOtherChest().isMain()) {
setMain(true);
}
if (main || single) {
final BlockState typeHere;
final BlockState typeNeighbor;
if (content.isEmpty() && (getOtherChest() == null || getOtherChest().isEmpty())) {
if (getOtherChest() != null && level.getBlockState(this.worldPosition.subtract(relativeNeighbor)).getBlock() instanceof AbstractBlockMinecoloniesRack) {
final Direction dirToNeighbour = BlockPosUtil.getFacing(worldPosition, this.worldPosition.subtract(relativeNeighbor));
typeHere = level.getBlockState(worldPosition).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.EMPTYAIR).setValue(AbstractBlockMinecoloniesRack.FACING, dirToNeighbour);
typeNeighbor = level.getBlockState(this.worldPosition.subtract(relativeNeighbor)).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.DEFAULTDOUBLE).setValue(AbstractBlockMinecoloniesRack.FACING, dirToNeighbour.getOpposite());
} else {
typeHere = level.getBlockState(worldPosition).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.DEFAULT);
typeNeighbor = null;
}
} else {
if (getOtherChest() != null && level.getBlockState(this.worldPosition.subtract(relativeNeighbor)).getBlock() instanceof AbstractBlockMinecoloniesRack) {
final Direction dirToNeighbour = BlockPosUtil.getFacing(worldPosition, this.worldPosition.subtract(relativeNeighbor));
typeHere = level.getBlockState(worldPosition).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.EMPTYAIR).setValue(AbstractBlockMinecoloniesRack.FACING, dirToNeighbour);
;
typeNeighbor = level.getBlockState(this.worldPosition.subtract(relativeNeighbor)).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.FULLDOUBLE).setValue(AbstractBlockMinecoloniesRack.FACING, dirToNeighbour.getOpposite());
} else {
typeHere = level.getBlockState(worldPosition).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.FULL);
typeNeighbor = null;
}
}
// This here avoids that two racks can be main at the same time.
if (this.isMain() && getOtherChest() != null && getOtherChest().isMain()) {
getOtherChest().setMain(false);
}
if (!level.getBlockState(worldPosition).equals(typeHere)) {
level.setBlockAndUpdate(worldPosition, typeHere);
}
if (typeNeighbor != null) {
if (!level.getBlockState(this.worldPosition.subtract(relativeNeighbor)).equals(typeNeighbor)) {
level.setBlockAndUpdate(this.worldPosition.subtract(relativeNeighbor), typeNeighbor);
}
}
} else {
getOtherChest().updateBlockState();
}
}
}
use of com.minecolonies.api.blocks.AbstractBlockMinecoloniesRack in project minecolonies by Minecolonies.
the class TileEntityRack method updateBlockState.
@Override
public void updateBlockState() {
if (level != null && level.getBlockState(worldPosition).getBlock() instanceof AbstractBlockMinecoloniesRack) {
if (!main && !single && getOtherChest() != null && !getOtherChest().isMain()) {
setMain(true);
}
if (main || single) {
final BlockState typeHere;
final BlockState typeNeighbor;
if (content.isEmpty() && (getOtherChest() == null || getOtherChest().isEmpty())) {
if (getOtherChest() != null && level.getBlockState(this.worldPosition.subtract(relativeNeighbor)).getBlock() instanceof AbstractBlockMinecoloniesRack) {
final Direction dirToNeighbour = BlockPosUtil.getFacing(worldPosition, this.worldPosition.subtract(relativeNeighbor));
typeHere = level.getBlockState(worldPosition).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.EMPTYAIR).setValue(AbstractBlockMinecoloniesRack.FACING, dirToNeighbour);
typeNeighbor = level.getBlockState(this.worldPosition.subtract(relativeNeighbor)).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.DEFAULTDOUBLE).setValue(AbstractBlockMinecoloniesRack.FACING, dirToNeighbour.getOpposite());
} else {
typeHere = level.getBlockState(worldPosition).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.DEFAULT);
typeNeighbor = null;
}
} else {
if (getOtherChest() != null && level.getBlockState(this.worldPosition.subtract(relativeNeighbor)).getBlock() instanceof AbstractBlockMinecoloniesRack) {
final Direction dirToNeighbour = BlockPosUtil.getFacing(worldPosition, this.worldPosition.subtract(relativeNeighbor));
typeHere = level.getBlockState(worldPosition).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.EMPTYAIR).setValue(AbstractBlockMinecoloniesRack.FACING, dirToNeighbour);
typeNeighbor = level.getBlockState(this.worldPosition.subtract(relativeNeighbor)).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.FULLDOUBLE).setValue(AbstractBlockMinecoloniesRack.FACING, dirToNeighbour.getOpposite());
} else {
typeHere = level.getBlockState(worldPosition).setValue(AbstractBlockMinecoloniesRack.VARIANT, RackType.FULL);
typeNeighbor = null;
}
}
// This here avoids that two racks can be main at the same time.
if (this.isMain() && getOtherChest() != null && getOtherChest().isMain()) {
getOtherChest().setMain(false);
}
if (!level.getBlockState(worldPosition).equals(typeHere)) {
level.setBlockAndUpdate(worldPosition, typeHere);
}
if (typeNeighbor != null) {
if (!level.getBlockState(this.worldPosition.subtract(relativeNeighbor)).equals(typeNeighbor)) {
level.setBlockAndUpdate(this.worldPosition.subtract(relativeNeighbor), typeNeighbor);
}
}
} else {
getOtherChest().updateBlockState();
}
}
}
use of com.minecolonies.api.blocks.AbstractBlockMinecoloniesRack in project minecolonies by Minecolonies.
the class AbstractTileEntityRack method neighborChanged.
/**
* On neighbor changed this will be called from the block.
*
* @param newNeighbor the blockPos which has changed.
*/
public void neighborChanged(final BlockPos newNeighbor) {
final TileEntity entity = level.getBlockEntity(newNeighbor);
if (relativeNeighbor == null && level.getBlockState(newNeighbor).getBlock() instanceof AbstractBlockMinecoloniesRack && !(entity instanceof AbstractTileEntityRack && ((AbstractTileEntityRack) entity).getOtherChest() != null)) {
if (!setNeighbor(newNeighbor)) {
return;
}
setSingle(false);
if (entity instanceof AbstractTileEntityRack) {
if (!((AbstractTileEntityRack) entity).isMain()) {
this.main = true;
((AbstractTileEntityRack) entity).setMain(false);
}
((AbstractTileEntityRack) entity).setNeighbor(this.getBlockPos());
entity.setChanged();
}
updateItemStorage();
this.setChanged();
updateBlockState();
} else if (relativeNeighbor != null && this.worldPosition.subtract(relativeNeighbor).equals(newNeighbor) && level.getBlockState(newNeighbor).getBlock() != ModBlocks.blockRack) {
this.relativeNeighbor = null;
setSingle(true);
this.main = false;
updateItemStorage();
updateBlockState();
}
}
use of com.minecolonies.api.blocks.AbstractBlockMinecoloniesRack in project minecolonies by ldtteam.
the class AbstractTileEntityRack method neighborChanged.
/**
* On neighbor changed this will be called from the block.
*
* @param newNeighbor the blockPos which has changed.
*/
public void neighborChanged(final BlockPos newNeighbor) {
final TileEntity entity = level.getBlockEntity(newNeighbor);
if (relativeNeighbor == null && level.getBlockState(newNeighbor).getBlock() instanceof AbstractBlockMinecoloniesRack && !(entity instanceof AbstractTileEntityRack && ((AbstractTileEntityRack) entity).getOtherChest() != null)) {
if (!setNeighbor(newNeighbor)) {
return;
}
setSingle(false);
if (entity instanceof AbstractTileEntityRack) {
if (!((AbstractTileEntityRack) entity).isMain()) {
this.main = true;
((AbstractTileEntityRack) entity).setMain(false);
}
((AbstractTileEntityRack) entity).setNeighbor(this.getBlockPos());
entity.setChanged();
}
updateItemStorage();
this.setChanged();
updateBlockState();
} else if (relativeNeighbor != null && this.worldPosition.subtract(relativeNeighbor).equals(newNeighbor) && level.getBlockState(newNeighbor).getBlock() != ModBlocks.blockRack) {
this.relativeNeighbor = null;
setSingle(true);
this.main = false;
updateItemStorage();
updateBlockState();
}
}
Aggregations