Search in sources :

Example 11 with GlowWorld

use of net.glowstone.GlowWorld in project Dragonet-Legacy by DragonetMC.

the class RemoveBlockPacketTranslator method handleSpecific.

@Override
public Message[] handleSpecific(RemoveBlockPacket packet) {
    if (!(this.getSession().getPlayer() instanceof Player)) {
        return null;
    }
    if (getSession().getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
        final GlowPlayer player = getSession().getPlayer();
        GlowWorld world = player.getWorld();
        GlowBlock block = world.getBlockAt(packet.x, packet.y, packet.z);
        PlayerInteractEvent interactEvent = EventFactory.onPlayerInteract(player, Action.LEFT_CLICK_BLOCK, block, BlockFace.UP);
        if (interactEvent.isCancelled()) {
            player.sendBlockChange(block.getLocation(), block.getType(), block.getData());
            return null;
        }
        block.setType(Material.AIR);
    } else {
        //Not Creative
        DiggingMessage msgFinishBreak = new DiggingMessage(DiggingMessage.FINISH_DIGGING, packet.x, packet.y, packet.z, 1);
        return new Message[] { msgFinishBreak };
    }
    return null;
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) GlowBlock(net.glowstone.block.GlowBlock) DiggingMessage(net.glowstone.net.message.play.player.DiggingMessage) Message(com.flowpowered.networking.Message) DiggingMessage(net.glowstone.net.message.play.player.DiggingMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) GlowWorld(net.glowstone.GlowWorld)

Example 12 with GlowWorld

use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.

the class GlowArmorStand method kill.

private void kill(boolean dropArmorStand) {
    active = false;
    ((GlowWorld) location.getWorld()).showParticle(location.clone().add(0, 1.317, 0), Effect.TILE_DUST, Material.WOOD.getId(), 0, 0.125f, 0.494f, 0.125f, 0.1f, 10, 10);
    for (ItemStack stack : equipment) {
        if (stack == null || stack.getType() == Material.AIR)
            continue;
        getWorld().dropItemNaturally(location, stack);
    }
    if (dropArmorStand) {
        getWorld().dropItemNaturally(location, new ItemStack(Material.ARMOR_STAND));
    }
}
Also used : GlowWorld(net.glowstone.GlowWorld) ItemStack(org.bukkit.inventory.ItemStack)

Example 13 with GlowWorld

use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.

the class GlowEntity method pulsePhysics.

protected void pulsePhysics() {
    if (velocity.lengthSquared() > 0.01) {
        double dx = 0;
        double dy = 0;
        double dz = 0;
        double ndx = 0;
        double ndy = 0;
        double ndz = 0;
        double x = location.getX();
        double y = location.getY();
        double z = location.getZ();
        Vector inc = velocity.clone().normalize();
        BoundingBox test;
        boolean bbRelevant = (boundingBox == null ? 0 : boundingBox.getSize().lengthSquared()) >= 1;
        if (velocity.getY() < 0d) {
            if (!location.clone().add(new Vector(0, -1, 0)).getBlock().getType().isSolid()) {
                block: while (dy >= velocity.getY()) {
                    ndy += inc.getY();
                    if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) x, (int) (y + ndy), (int) z)).isSolid()) {
                        break;
                    }
                    if (bbRelevant) {
                        test = BoundingBox.fromPositionAndSize(new Vector((int) x, (int) (y + ndy), (int) z), boundingBox.getSize());
                        Vector min = test.minCorner, max = test.maxCorner;
                        for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
                            for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
                                for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
                                    if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
                                        break block;
                                    }
                                }
                            }
                        }
                    }
                    dy = ndy;
                }
            }
        } else if (velocity.getY() > 0d) {
            block: while (dy <= velocity.getY()) {
                ndy += inc.getY();
                if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) x, (int) (y + ndy), (int) z)).isSolid()) {
                    break;
                }
                if (bbRelevant) {
                    test = BoundingBox.fromPositionAndSize(new Vector((int) x, (int) (y + ndy), (int) z), boundingBox.getSize());
                    Vector min = test.minCorner, max = test.maxCorner;
                    for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
                        for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
                            for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
                                if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
                                    break block;
                                }
                            }
                        }
                    }
                }
                dy = ndy;
            }
        }
        velocity.setY(dy);
        if (velocity.getX() < 0d) {
            block: while (dx >= velocity.getX()) {
                ndx += inc.getX();
                if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) (x + ndx), (int) (y + dy), (int) z)).isSolid()) {
                    break;
                }
                if (bbRelevant) {
                    test = BoundingBox.fromPositionAndSize(new Vector((int) (x + ndx), (int) (y + dy), (int) z), boundingBox.getSize());
                    Vector min = test.minCorner, max = test.maxCorner;
                    for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
                        for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
                            for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
                                if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
                                    break block;
                                }
                            }
                        }
                    }
                }
                dx = ndx;
            }
        } else if (velocity.getX() > 0d) {
            block: while (dx <= velocity.getX()) {
                ndx += inc.getX();
                if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) (x + ndx), (int) (y + dy), (int) z)).isSolid()) {
                    break;
                }
                if (bbRelevant) {
                    test = BoundingBox.fromPositionAndSize(new Vector((int) (x + ndx), (int) (y + dy), (int) z), boundingBox.getSize());
                    Vector min = test.minCorner, max = test.maxCorner;
                    for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
                        for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
                            for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
                                if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
                                    break block;
                                }
                            }
                        }
                    }
                }
                dx = ndx;
            }
        }
        velocity.setX(dx);
        if (velocity.getZ() < 0d) {
            block: while (dz >= velocity.getZ()) {
                ndz += inc.getZ();
                if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) (x + dx), (int) (y + dy), (int) (z + ndz))).isSolid()) {
                    break;
                }
                if (bbRelevant) {
                    test = BoundingBox.fromPositionAndSize(new Vector((int) (x + dx), (int) (y + dy), (int) (z + ndz)), boundingBox.getSize());
                    Vector min = test.minCorner, max = test.maxCorner;
                    for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
                        for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
                            for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
                                if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
                                    break block;
                                }
                            }
                        }
                    }
                }
                dz = ndz;
            }
        } else if (velocity.getZ() > 0d) {
            block: while (dz <= velocity.getZ()) {
                ndz += inc.getZ();
                if (Material.getMaterial(((GlowWorld) location.getWorld()).getBlockTypeIdAt((int) (x + dx), (int) (y + dy), (int) (z + ndz))).isSolid()) {
                    break;
                }
                if (bbRelevant) {
                    test = BoundingBox.fromPositionAndSize(new Vector((int) (x + dx), (int) (y + dy), (int) (z + ndz)), boundingBox.getSize());
                    Vector min = test.minCorner, max = test.maxCorner;
                    for (int bbx = min.getBlockX(); bbx <= max.getBlockX(); ++bbx) {
                        for (int bby = min.getBlockY(); bby <= max.getBlockY(); ++bby) {
                            for (int bbz = min.getBlockZ(); bbz <= max.getBlockZ(); ++bbz) {
                                if (Material.getMaterial(world.getBlockTypeIdAt(bbx, bby, bbz)).isSolid()) {
                                    break block;
                                }
                            }
                        }
                    }
                }
                dz = ndz;
            }
        }
        velocity.setZ(dz);
        setRawLocation(location.clone().add(velocity));
    }
    // apply friction and gravity
    if (location.getBlock().getType() == Material.WATER) {
        velocity.multiply(liquidDrag);
        velocity.setY(velocity.getY() + getGravityAccel().getY() / 4d);
    } else if (location.getBlock().getType() == Material.LAVA) {
        velocity.multiply(liquidDrag - 0.3);
        velocity.setY(velocity.getY() + getGravityAccel().getY() / 4d);
    } else {
        velocity.setY(airDrag * (velocity.getY() + getGravityAccel().getY()));
        if (isOnGround()) {
            velocity.setX(velocity.getX() * slipMultiplier);
            velocity.setZ(velocity.getZ() * slipMultiplier);
        } else {
            velocity.setX(velocity.getX() * 0.91);
            velocity.setZ(velocity.getZ() * 0.91);
        }
    }
}
Also used : BoundingBox(net.glowstone.entity.physics.BoundingBox) EntityBoundingBox(net.glowstone.entity.physics.EntityBoundingBox) GlowWorld(net.glowstone.GlowWorld) Vector(org.bukkit.util.Vector)

Example 14 with GlowWorld

use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.

the class BlockVine method hasNearVineBlocks.

private boolean hasNearVineBlocks(GlowBlock block) {
    GlowWorld world = block.getWorld();
    int vineCount = 0;
    for (int x = 0; x < 9; x++) {
        for (int z = 0; z < 9; z++) {
            for (int y = 0; y < 3; y++) {
                if (world.getBlockAt(block.getLocation().add(x - 4, y - 1, z - 4)).getType() == Material.VINE) {
                    if (++vineCount >= 5) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : GlowWorld(net.glowstone.GlowWorld)

Example 15 with GlowWorld

use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.

the class ItemArmorStand method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
    BlockType type = ItemTable.instance().getBlock(target.getType());
    GlowBlock newTarget = type.canAbsorb(target, face, holding) ? target : target.getRelative(face);
    type = ItemTable.instance().getBlock(newTarget.getType());
    GlowBlock upper = newTarget.getRelative(BlockFace.UP);
    BlockType up = ItemTable.instance().getBlock(upper.getType());
    Location loc = newTarget.getLocation().add(0.5, 0, 0.5);
    if ((newTarget.isEmpty() || type == null || type.canAbsorb(target, face, holding)) && (upper.isEmpty() || up == null || up.canAbsorb(target, face, holding)) && loc.getWorld().getNearbyEntities(loc.clone().add(0, 0.5, 0), 0.5, 0.5, 0.5).isEmpty() && loc.getWorld().getNearbyEntities(loc.clone().add(0, 1.5, 0), 0.5, 0.5, 0.5).isEmpty()) {
        newTarget.setType(Material.AIR);
        upper.setType(Material.AIR);
        float yaw = player.getLocation().getYaw();
        float finalYaw = Math.round(yaw / 22.5f / 2) * 45;
        loc.setYaw(finalYaw - 180);
        ((GlowWorld) loc.getWorld()).spawn(loc, GlowArmorStand.class, CreatureSpawnEvent.SpawnReason.DEFAULT);
        if (player.getGameMode() != GameMode.CREATIVE) {
            holding.setAmount(holding.getAmount() - 1);
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockType(net.glowstone.block.blocktype.BlockType) GlowWorld(net.glowstone.GlowWorld) Location(org.bukkit.Location)

Aggregations

GlowWorld (net.glowstone.GlowWorld)23 GlowBlock (net.glowstone.block.GlowBlock)14 GlowBlockState (net.glowstone.block.GlowBlockState)10 GlowPlayer (net.glowstone.entity.GlowPlayer)3 Location (org.bukkit.Location)3 BlockSpreadEvent (org.bukkit.event.block.BlockSpreadEvent)3 Entry (java.util.Map.Entry)2 BlockType (net.glowstone.block.blocktype.BlockType)2 Material (org.bukkit.Material)2 BlockFace (org.bukkit.block.BlockFace)2 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)2 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)2 ItemStack (org.bukkit.inventory.ItemStack)2 MaterialData (org.bukkit.material.MaterialData)2 Vector (org.bukkit.util.Vector)2 Message (com.flowpowered.networking.Message)1 Arrays (java.util.Arrays)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 BlockContainer (net.glowstone.block.blocktype.BlockContainer)1 ItemTimedUsage (net.glowstone.block.itemtype.ItemTimedUsage)1