Search in sources :

Example 1 with Direction

use of com.github.jikoo.planarwrappers.world.Direction in project Easterlyn by Easterlyn.

the class CompilationAmalgamator method ejectItem.

private void ejectItem(Location key, @Nullable ItemStack item, ConfigurationSection storage) {
    if (item == null) {
        return;
    }
    Direction facing = this.getDirection(storage).getRelativeDirection(Direction.SOUTH);
    BlockState blockState = key.clone().add(facing.getRelativeVector(new Vector(0, 0, 1))).getBlock().getState();
    if (blockState instanceof InventoryHolder) {
        // MACHINES InventoryMoveItemEvent
        if (((InventoryHolder) blockState).getInventory().addItem(item).size() == 0) {
            return;
        }
    }
    // Center block location
    key.add(facing.getRelativeVector(new Vector(0.5D, 0.5D, 1.5D)));
    BlockFace face = facing.toBlockFace();
    // See net.minecraft.server.DispenseBehaviorItem
    Random random = ThreadLocalRandom.current();
    double motionRandom = random.nextDouble() * 0.1D + 0.2D;
    // 0.007499999832361937D * 6
    double motX = face.getModX() * motionRandom + random.nextGaussian() * 0.044999998994171622D;
    double motY = 0.2000000029802322D + random.nextGaussian() * 0.044999998994171622D;
    double motZ = face.getModZ() * motionRandom + random.nextGaussian() * 0.044999998994171622D;
    // MACHINES BlockDispenseEvent
    if (key.getWorld() != null) {
        key.getWorld().dropItem(key, item).setVelocity(new Vector(motX, motY, motZ));
        key.getWorld().playSound(key, Sound.BLOCK_DISPENSER_DISPENSE, SoundCategory.BLOCKS, 1F, 1F);
        key.getWorld().playEffect(key, Effect.SMOKE, face);
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BlockFace(org.bukkit.block.BlockFace) Direction(com.github.jikoo.planarwrappers.world.Direction) Vector(org.bukkit.util.Vector) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 2 with Direction

use of com.github.jikoo.planarwrappers.world.Direction in project Easterlyn by Easterlyn.

the class Densificator method ejectItem.

private void ejectItem(Location key, ItemStack item, ConfigurationSection storage) {
    Direction facing = this.getDirection(storage).getRelativeDirection(Direction.SOUTH);
    BlockState blockState = key.clone().add(facing.getRelativeVector(new Vector(0, 0, 1))).getBlock().getState();
    if (blockState instanceof InventoryHolder) {
        // TODO InventoryMoveItemEvent? Currently prevents instant chaining.
        if (((InventoryHolder) blockState).getInventory().addItem(item).size() == 0) {
            return;
        }
    }
    // Center block location
    key.add(facing.getRelativeVector(new Vector(0.5D, 0.5D, 1.5D)));
    BlockFace face = facing.toBlockFace();
    // See net.minecraft.server.DispenseBehaviorItem
    Random random = ThreadLocalRandom.current();
    double motionRandom = random.nextDouble() * 0.1D + 0.2D;
    // 0.007499999832361937D * 6
    double motX = face.getModX() * motionRandom + random.nextGaussian() * 0.044999998994171622D;
    double motY = 0.2000000029802322D + random.nextGaussian() * 0.044999998994171622D;
    double motZ = face.getModZ() * motionRandom + random.nextGaussian() * 0.044999998994171622D;
    // TODO BlockDispenseEvent
    if (key.getWorld() != null) {
        key.getWorld().dropItem(key, item).setVelocity(new Vector(motX, motY, motZ));
        key.getWorld().playSound(key, Sound.BLOCK_DISPENSER_DISPENSE, SoundCategory.BLOCKS, 1F, 1F);
        key.getWorld().playEffect(key, Effect.SMOKE, face);
        key.getWorld().playEffect(key, Effect.SMOKE, face);
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BlockFace(org.bukkit.block.BlockFace) Direction(com.github.jikoo.planarwrappers.world.Direction) Vector(org.bukkit.util.Vector) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 3 with Direction

use of com.github.jikoo.planarwrappers.world.Direction in project Easterlyn by Easterlyn.

the class Machine method failedAssembly.

/**
 * Sets up the Machine Block configuration using a BlockPlaceEvent.
 *
 * @param storage the ConfigurationSection of data specific to the given Machine
 * @return false if assembly failed due to space requirements
 */
public boolean failedAssembly(@NotNull ConfigurationSection storage) {
    Location key = getKey(storage);
    Direction direction = getDirection(storage);
    for (Block block : shape.getBuildLocations(key.getBlock(), direction).keySet()) {
        if (!block.getLocation().equals(key) && (!block.isEmpty() || getMachines().isExplodedMachine(block)) || block.getY() > 255) {
            this.assemblyFailed(storage);
            return true;
        }
    }
    this.assemble(key.getBlock(), direction, storage);
    return false;
}
Also used : Block(org.bukkit.block.Block) Direction(com.github.jikoo.planarwrappers.world.Direction) Location(org.bukkit.Location)

Aggregations

Direction (com.github.jikoo.planarwrappers.world.Direction)3 Random (java.util.Random)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 BlockFace (org.bukkit.block.BlockFace)2 BlockState (org.bukkit.block.BlockState)2 InventoryHolder (org.bukkit.inventory.InventoryHolder)2 Vector (org.bukkit.util.Vector)2 Location (org.bukkit.Location)1 Block (org.bukkit.block.Block)1