Search in sources :

Example 1 with AltarTileEntity

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");
}
Also used : AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity)

Example 2 with AltarTileEntity

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;
}
Also used : AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with AltarTileEntity

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);
}
Also used : AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with AltarTileEntity

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;
}
Also used : ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) BlockPos(net.minecraft.util.math.BlockPos) ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity)

Example 5 with AltarTileEntity

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;
}
Also used : AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

AltarTileEntity (com.favouriteless.enchanted.common.tileentity.AltarTileEntity)6 TileEntity (net.minecraft.tileentity.TileEntity)6 BlockPos (net.minecraft.util.math.BlockPos)4 ChalkGoldTileEntity (com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity)1 BlockStateChangeSet (hellfirepvp.observerlib.common.change.BlockStateChangeSet)1