Search in sources :

Example 66 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Magma by magmafoundation.

the class CraftItemFrame method update.

private void update() {
    EntityItemFrame old = this.getHandle();
    WorldServer world = ((CraftWorld) getWorld()).getHandle();
    BlockPos position = old.getPosition();
    EnumFacing direction = old.getHorizontalFacing();
    ItemStack item = old.getDisplayedItem() != null ? old.getDisplayedItem().copy() : null;
    old.setDead();
    EntityItemFrame frame = new EntityItemFrame(world, position, direction);
    frame.setDisplayedItem(item);
    world.spawnEntity(frame);
    this.entity = frame;
}
Also used : EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) EnumFacing(net.minecraft.util.EnumFacing) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.item.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 67 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Magma by magmafoundation.

the class CraftChest method getInventory.

@Override
public Inventory getInventory() {
    CraftInventory inventory = (CraftInventory) this.getBlockInventory();
    if (!isPlaced()) {
        return inventory;
    }
    // The logic here is basically identical to the logic in BlockChest.interact
    int x = this.getX();
    int y = this.getY();
    int z = this.getZ();
    CraftWorld world = (CraftWorld) this.getWorld();
    int id;
    if (world.getBlockTypeIdAt(x, y, z) == Material.CHEST.getId()) {
        id = Material.CHEST.getId();
    } else if (world.getBlockTypeIdAt(x, y, z) == Material.TRAPPED_CHEST.getId()) {
        id = Material.TRAPPED_CHEST.getId();
    } else {
        throw new IllegalStateException("CraftChest is not a chest but is instead " + world.getBlockAt(x, y, z));
    }
    if (world.getBlockTypeIdAt(x - 1, y, z) == id) {
        CraftInventory left = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x - 1, y, z)));
        inventory = new CraftInventoryDoubleChest(left, inventory);
    }
    if (world.getBlockTypeIdAt(x + 1, y, z) == id) {
        CraftInventory right = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x + 1, y, z)));
        inventory = new CraftInventoryDoubleChest(inventory, right);
    }
    if (world.getBlockTypeIdAt(x, y, z - 1) == id) {
        CraftInventory left = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x, y, z - 1)));
        inventory = new CraftInventoryDoubleChest(left, inventory);
    }
    if (world.getBlockTypeIdAt(x, y, z + 1) == id) {
        CraftInventory right = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x, y, z + 1)));
        inventory = new CraftInventoryDoubleChest(inventory, right);
    }
    return inventory;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory) BlockPos(net.minecraft.util.math.BlockPos) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryDoubleChest) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 68 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Magma by magmafoundation.

the class CraftJukebox method update.

@Override
public boolean update(boolean force, boolean applyPhysics) {
    boolean result = super.update(force, applyPhysics);
    if (result && this.isPlaced() && this.getType() == Material.JUKEBOX) {
        CraftWorld world = (CraftWorld) this.getWorld();
        Material record = this.getPlaying();
        if (record == Material.AIR) {
            world.getHandle().setBlockState(new BlockPos(this.getX(), this.getY(), this.getZ()), Blocks.JUKEBOX.getDefaultState().withProperty(BlockJukebox.HAS_RECORD, false), 3);
        } else {
            world.getHandle().setBlockState(new BlockPos(this.getX(), this.getY(), this.getZ()), Blocks.JUKEBOX.getDefaultState().withProperty(BlockJukebox.HAS_RECORD, true), 3);
        }
        world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record.getId());
    }
    return result;
}
Also used : Material(org.bukkit.Material) BlockPos(net.minecraft.util.math.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 69 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Magma by magmafoundation.

the class CraftNoteBlock method play.

@Override
public boolean play() {
    Block block = getBlock();
    if (block.getType() == Material.NOTE_BLOCK) {
        TileEntityNote note = (TileEntityNote) this.getTileEntityFromWorld();
        CraftWorld world = (CraftWorld) this.getWorld();
        note.triggerNote(world.getHandle(), new BlockPos(getX(), getY(), getZ()));
        return true;
    } else {
        return false;
    }
}
Also used : Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.NoteBlock) TileEntityNote(net.minecraft.tileentity.TileEntityNote) BlockPos(net.minecraft.util.math.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 70 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Magma by magmafoundation.

the class CraftNoteBlock method play.

@Override
public boolean play(Instrument instrument, Note note) {
    Block block = getBlock();
    if (block.getType() == Material.NOTE_BLOCK) {
        CraftWorld world = (CraftWorld) this.getWorld();
        world.getHandle().addBlockEvent(new BlockPos(getX(), getY(), getZ()), CraftMagicNumbers.getBlock(block), instrument.getType(), note.getId());
        return true;
    } else {
        return false;
    }
}
Also used : Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.NoteBlock) BlockPos(net.minecraft.util.math.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)147 Location (org.bukkit.Location)131 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)111 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)103 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)95 BlockPos (net.minecraft.core.BlockPos)83 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)74 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)66 ItemStack (org.bukkit.inventory.ItemStack)61 Block (org.bukkit.block.Block)57 LivingEntity (org.bukkit.entity.LivingEntity)54 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)53 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)47 ArrayList (java.util.ArrayList)43 World (org.bukkit.World)41 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)39 Entity (org.bukkit.entity.Entity)39 Level (net.minecraft.world.level.Level)38 List (java.util.List)34 GameProfile (com.mojang.authlib.GameProfile)32