Search in sources :

Example 1 with ChalkGoldTileEntity

use of com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity in project Enchanted by Favouriteless.

the class AbstractRite method detatchFromChalk.

protected void detatchFromChalk() {
    TileEntity te = world.getBlockEntity(pos);
    if (te instanceof ChalkGoldTileEntity) {
        ChalkGoldTileEntity chalk = (ChalkGoldTileEntity) te;
        if (chalk.getRite() == this)
            chalk.clearRite();
    }
    isAttached = false;
}
Also used : ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity)

Example 2 with ChalkGoldTileEntity

use of com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity in project Enchanted by Favouriteless.

the class AbstractRite method cancel.

public void cancel() {
    isStarting = false;
    RiteManager.removeRite(this);
    while (!itemsConsumed.isEmpty()) {
        ItemStack stack = itemsConsumed.get(0);
        ItemEntity entity = new ItemEntity(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, stack);
        world.addFreshEntity(entity);
        itemsConsumed.remove(stack);
    }
    world.playSound(null, pos, SoundEvents.NOTE_BLOCK_SNARE, SoundCategory.MASTER, 1.0F, 1.0F);
    PlayerEntity player = world.getPlayerByUUID(casterUUID);
    if (player != null)
        player.displayClientMessage(new StringTextComponent("Rite failed.").withStyle(TextFormatting.RED), false);
    for (int i = 0; i < 25; i++) {
        double dx = pos.getX() + Math.random();
        double dy = pos.getY() + Math.random();
        double dz = pos.getZ() + Math.random();
        world.sendParticles(new RedstoneParticleData(254 / 255F, 94 / 255F, 94 / 255F, 1.0F), dx, dy, dz, 1, 0.0F, 0.0F, 0.0F, 0.0F);
    }
    TileEntity te = world.getBlockEntity(pos);
    if (te instanceof ChalkGoldTileEntity) {
        ((ChalkGoldTileEntity) te).clearRite();
    }
}
Also used : ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) RedstoneParticleData(net.minecraft.particles.RedstoneParticleData) ItemEntity(net.minecraft.entity.item.ItemEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity)

Example 3 with ChalkGoldTileEntity

use of com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity in project Enchanted by Favouriteless.

the class AbstractRite method stopExecuting.

/**
 * Call this when the rite is finished
 */
public void stopExecuting() {
    detatchFromChalk();
    this.isStarting = false;
    TileEntity te = world.getBlockEntity(pos);
    if (te instanceof ChalkGoldTileEntity) {
        ((ChalkGoldTileEntity) te).clearRite();
    }
    RiteManager.removeRite(this);
}
Also used : ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity)

Example 4 with ChalkGoldTileEntity

use of com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity 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 ChalkGoldTileEntity

use of com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity in project Enchanted by Favouriteless.

the class AbstractRite method tick.

public void tick() {
    if (world != null && !world.isClientSide) {
        if (isAttached && chalk == null) {
            TileEntity te = world.getBlockEntity(pos);
            if (te instanceof ChalkGoldTileEntity) {
                setChalk((ChalkGoldTileEntity) te);
                chalk.setRite(this);
            }
        }
        ticks++;
        if (isStarting) {
            if (ticks % 20 == 0) {
                List<Entity> allEntities = world.getEntities(null, new AxisAlignedBB(pos.offset(-7, 0, -7), pos.offset(7, 1, 7)));
                boolean hasItem = false;
                for (Entity entity : allEntities) {
                    if (entity instanceof ItemEntity) {
                        ItemEntity itemEntity = (ItemEntity) entity;
                        if (ITEMS_REQUIRED.containsKey(itemEntity.getItem().getItem())) {
                            consumeItem(itemEntity);
                            hasItem = true;
                            break;
                        }
                    }
                }
                boolean hasEntity = false;
                if (!hasItem) {
                    if (ITEMS_REQUIRED.isEmpty()) {
                        for (Entity entity : allEntities) {
                            if (ENTITIES_REQUIRED.containsKey(entity.getType())) {
                                hasEntity = true;
                                consumeEntity(entity);
                                break;
                            }
                        }
                    } else {
                        cancel();
                        return;
                    }
                    if (!hasEntity) {
                        if (ENTITIES_REQUIRED.isEmpty()) {
                            startExecuting();
                        } else {
                            cancel();
                        }
                    }
                }
            }
        } else if (!isRemoved) {
            if (tryConsumePower(POWER_TICK))
                onTick();
            else
                stopExecuting();
        }
    }
}
Also used : ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity) AltarTileEntity(com.favouriteless.enchanted.common.tileentity.AltarTileEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) ChalkGoldTileEntity(com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity)

Aggregations

ChalkGoldTileEntity (com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity)6 AltarTileEntity (com.favouriteless.enchanted.common.tileentity.AltarTileEntity)5 TileEntity (net.minecraft.tileentity.TileEntity)5 ItemEntity (net.minecraft.entity.item.ItemEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 Entity (net.minecraft.entity.Entity)1 ItemStack (net.minecraft.item.ItemStack)1 RedstoneParticleData (net.minecraft.particles.RedstoneParticleData)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1