use of com.favouriteless.enchanted.common.tileentity.AltarTileEntity in project Enchanted by Favouriteless.
the class AltarContainer method getTileEntity.
private static AltarTileEntity getTileEntity(final PlayerInventory playerInventory, final PacketBuffer data) {
Objects.requireNonNull(playerInventory, "Player inventory cannot be null");
Objects.requireNonNull(data, "SimpleColouredData cannot be null");
final TileEntity tileEntity = playerInventory.player.level.getBlockEntity(data.readBlockPos());
if (tileEntity instanceof AltarTileEntity) {
return (AltarTileEntity) tileEntity;
}
throw new IllegalStateException("TileEntity at " + data.readBlockPos() + " is not correct");
}
use of com.favouriteless.enchanted.common.tileentity.AltarTileEntity in project Enchanted by Favouriteless.
the class AltarBlock method use.
@Override
public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
if (state.getValue(FORMED) != AltarPartIndex.UNFORMED) {
if (!world.isClientSide) {
BlockPos cornerPos = AltarMultiBlock.INSTANCE.getBottomLowerLeft(world, pos, state);
BlockState cornerState = world.getBlockState(cornerPos);
if (cornerState.getValue(FORMED) == AltarPartIndex.P000) {
TileEntity tileEntity = world.getBlockEntity(cornerPos);
if (tileEntity instanceof AltarTileEntity) {
NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getBlockPos());
}
}
return ActionResultType.CONSUME;
}
return ActionResultType.SUCCESS;
}
return ActionResultType.FAIL;
}
use of com.favouriteless.enchanted.common.tileentity.AltarTileEntity in project Enchanted by Favouriteless.
the class AltarBlock method neighborChanged.
@Override
public void neighborChanged(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) {
if (fromPos == pos.above() && state.getValue(FORMED) != AltarPartIndex.UNFORMED) {
BlockPos cornerPos = AltarMultiBlock.INSTANCE.getBottomLowerLeft(world, pos, state);
TileEntity tileEntity = world.getBlockEntity(cornerPos);
if (tileEntity instanceof AltarTileEntity) {
AltarTileEntity altar = (AltarTileEntity) tileEntity;
// if(world.getBlockState(fromPos).getBlock()) {
//
// }
}
}
super.neighborChanged(state, world, pos, block, fromPos, isMoving);
}
use of com.favouriteless.enchanted.common.tileentity.AltarTileEntity in project Enchanted by Favouriteless.
the class AbstractRite method tryConsumePower.
protected boolean tryConsumePower(int amount) {
if (world != null) {
if (amount > 0) {
TileEntity te = world.getBlockEntity(pos);
if (te instanceof ChalkGoldTileEntity) {
List<BlockPos> potentialAltars = ((ChalkGoldTileEntity) te).getAltarPositions();
AltarTileEntity altar = AltarPowerHelper.tryGetAltar(world, potentialAltars);
if (altar != null) {
if (altar.currentPower >= amount) {
altar.currentPower -= amount;
return true;
}
}
}
} else {
return true;
}
}
return false;
}
use of com.favouriteless.enchanted.common.tileentity.AltarTileEntity in project Enchanted by Favouriteless.
the class AltarPowerHelper method tryGetAltar.
public static AltarTileEntity tryGetAltar(World world, List<BlockPos> potentialAltars) {
while (!potentialAltars.isEmpty()) {
if (world != null) {
BlockPos altarPos = potentialAltars.get(0);
TileEntity te = world.getBlockEntity(altarPos);
if (te instanceof AltarTileEntity) {
return (AltarTileEntity) te;
} else {
potentialAltars.remove(altarPos);
}
}
}
return null;
}
Aggregations