Search in sources :

Example 1 with BlockEntityComparator

use of cn.nukkit.blockentity.BlockEntityComparator in project Nukkit by Nukkit.

the class BlockRedstoneComparator method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (super.place(item, block, target, face, fx, fy, fz, player)) {
        CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.COMPARATOR).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
        new BlockEntityComparator(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
        onUpdate(Level.BLOCK_UPDATE_REDSTONE);
        return true;
    }
    return false;
}
Also used : BlockEntityComparator(cn.nukkit.blockentity.BlockEntityComparator) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 2 with BlockEntityComparator

use of cn.nukkit.blockentity.BlockEntityComparator in project Nukkit by Nukkit.

the class BlockRedstoneComparator method onChange.

private void onChange() {
    int output = this.calculateOutput();
    BlockEntity blockEntity = this.level.getBlockEntity(this);
    int currentOutput = 0;
    if (blockEntity instanceof BlockEntityComparator) {
        BlockEntityComparator blockEntityComparator = (BlockEntityComparator) blockEntity;
        currentOutput = blockEntityComparator.getOutputSignal();
        blockEntityComparator.setOutputSignal(output);
    }
    if (currentOutput != output || getMode() == Mode.COMPARE) {
        boolean shouldBePowered = this.shouldBePowered();
        boolean isPowered = this.isPowered();
        if (isPowered && !shouldBePowered) {
            this.level.setBlock(this, getUnpowered(), true, false);
        } else if (!isPowered && shouldBePowered) {
            this.level.setBlock(this, getPowered(), true, false);
        }
        this.level.updateAroundRedstone(this, null);
    }
}
Also used : BlockEntityComparator(cn.nukkit.blockentity.BlockEntityComparator) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Example 3 with BlockEntityComparator

use of cn.nukkit.blockentity.BlockEntityComparator in project Nukkit by Nukkit.

the class BlockRedstoneComparator method updateState.

@Override
public void updateState() {
    if (!this.level.isBlockTickPending(this, this)) {
        int output = this.calculateOutput();
        BlockEntity blockEntity = this.level.getBlockEntity(this);
        int power = blockEntity instanceof BlockEntityComparator ? ((BlockEntityComparator) blockEntity).getOutputSignal() : 0;
        if (output != power || this.isPowered() != this.shouldBePowered()) {
            /*if(isFacingTowardsRepeater()) {
                    this.level.scheduleUpdate(this, this, 2, -1);
                } else {
                    this.level.scheduleUpdate(this, this, 2, 0);
                }*/
            // System.out.println("schedule update 0");
            this.level.scheduleUpdate(this, this, 2);
        }
    }
}
Also used : BlockEntityComparator(cn.nukkit.blockentity.BlockEntityComparator) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Aggregations

BlockEntityComparator (cn.nukkit.blockentity.BlockEntityComparator)3 BlockEntity (cn.nukkit.blockentity.BlockEntity)2 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)1