Search in sources :

Example 1 with BlockType

use of net.glowstone.block.blocktype.BlockType in project Dragonet-Legacy by DragonetMC.

the class TestItemTypes method hasAllMaterials.

@Test
public void hasAllMaterials() {
    ItemType type = table.getItem(material);
    // special cases
    if (material == Material.AIR) {
        assertNull("ItemType exists for air: " + type, type);
        return;
    }
    // check that it exists
    assertNotNull("ItemType does not exist for " + material, type);
    // check that its block status is correct
    assertTrue("Block status mismatch between " + material + "(" + material.isBlock() + ") and " + type, (type instanceof BlockType) == material.isBlock());
    // check that material returned matches
    assertEquals("ItemType returned wrong material", material, type.getMaterial());
    // check that max stack size matches
    assertEquals("Maximum stack size was incorrect", material.getMaxStackSize(), type.getMaxStackSize());
}
Also used : BlockType(net.glowstone.block.blocktype.BlockType) ItemType(net.glowstone.block.itemtype.ItemType) Test(org.junit.Test)

Example 2 with BlockType

use of net.glowstone.block.blocktype.BlockType in project Glowstone by GlowstoneMC.

the class PulseTask method run.

@Override
public void run() {
    Block block = location.getBlock();
    if (block == null) {
        cancel();
        return;
    }
    if (!location.getChunk().isLoaded()) {
        return;
    }
    if (block.getType() != originalMaterial) {
        cancel();
        return;
    }
    ItemTable table = ItemTable.instance();
    BlockType type = table.getBlock(originalMaterial);
    if (type != null) {
        type.receivePulse((GlowBlock) block);
    }
}
Also used : ItemTable(net.glowstone.block.ItemTable) BlockType(net.glowstone.block.blocktype.BlockType) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block)

Example 3 with BlockType

use of net.glowstone.block.blocktype.BlockType in project Glowstone by GlowstoneMC.

the class GlowLivingEntity method pulse.

////////////////////////////////////////////////////////////////////////////
// Internals
@Override
public void pulse() {
    super.pulse();
    if (isDead()) {
        deathTicks++;
        if (deathTicks >= 20 && getClass() != GlowPlayer.class) {
            remove();
        }
    }
    // invulnerability
    if (noDamageTicks > 0) {
        --noDamageTicks;
    }
    Material mat = getEyeLocation().getBlock().getType();
    // breathing
    if (mat == Material.WATER || mat == Material.STATIONARY_WATER) {
        if (canTakeDamage(DamageCause.DROWNING)) {
            --airTicks;
            if (airTicks <= -20) {
                airTicks = 0;
                damage(1, DamageCause.DROWNING);
            }
        }
    } else {
        airTicks = maximumAir;
    }
    if (isTouchingMaterial(Material.CACTUS)) {
        damage(1, DamageCause.CONTACT);
    }
    if (location.getY() < -64) {
        // no canTakeDamage call - pierces through game modes
        damage(4, DamageCause.VOID);
    }
    if (isWithinSolidBlock())
        damage(1, DamageCause.SUFFOCATION);
    if (getLocation().getBlock().getType() == Material.LAVA || getLocation().getBlock().getType() == Material.STATIONARY_LAVA) {
        damage(4, DamageCause.LAVA);
        if (swamInLava) {
            setFireTicks(getFireTicks() + 2);
        } else {
            setFireTicks(getFireTicks() + 300);
            swamInLava = true;
        }
    } else {
        swamInLava = false;
        if (getLocation().getBlock().getType() == Material.WATER || getLocation().getBlock().getType() == Material.STATIONARY_WATER) {
            setFireTicks(0);
        }
    }
    // potion effects
    List<PotionEffect> effects = new ArrayList<>(potionEffects.values());
    for (PotionEffect effect : effects) {
        // pulse effect
        PotionEffectType type = effect.getType();
        GlowPotionEffect glowType = GlowPotionEffect.getEffect(type);
        if (glowType != null) {
            glowType.pulse(this, effect);
        }
        if (effect.getDuration() > 0) {
            // reduce duration and re-add
            addPotionEffect(new PotionEffect(type, effect.getDuration() - 1, effect.getAmplifier(), effect.isAmbient()), true);
        } else {
            // remove
            removePotionEffect(type);
        }
    }
    if (getFireTicks() > 0 && getFireTicks() % 20 == 0) {
        damage(1, DamageCause.FIRE_TICK);
    }
    GlowBlock under = (GlowBlock) getLocation().getBlock().getRelative(BlockFace.DOWN);
    BlockType type = ItemTable.instance().getBlock(under.getType());
    if (type != null) {
        type.onEntityStep(under, this);
    }
    nextAmbientTime--;
    if (!isDead() && getAmbientSound() != null && nextAmbientTime == 0 && !isSilent()) {
        double v = ThreadLocalRandom.current().nextDouble();
        if (v <= 0.2) {
            world.playSound(getLocation(), getAmbientSound(), getSoundVolume(), getSoundPitch());
        }
    }
    if (nextAmbientTime == 0) {
        nextAmbientTime = getAmbientDelay();
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowPotionEffect(net.glowstone.constants.GlowPotionEffect) PotionEffect(org.bukkit.potion.PotionEffect) BlockType(net.glowstone.block.blocktype.BlockType) PotionEffectType(org.bukkit.potion.PotionEffectType) GlowPotionEffect(net.glowstone.constants.GlowPotionEffect)

Example 4 with BlockType

use of net.glowstone.block.blocktype.BlockType in project Glowstone by GlowstoneMC.

the class GlowWorld method pulseTickMap.

private void pulseTickMap() {
    ItemTable itemTable = ItemTable.instance();
    for (Location location : getTickMap()) {
        if (!location.getChunk().isLoaded()) {
            continue;
        }
        BlockType type = itemTable.getBlock(Material.getMaterial(getBlockTypeIdAt(location)));
        if (type == null) {
            cancelPulse(location);
            continue;
        }
        GlowBlock block = (GlowBlock) location.getBlock();
        Integer speed = type.getPulseTickSpeed(block);
        boolean once = type.isPulseOnce(block);
        if (speed == 0) {
            continue;
        }
        if (worldAge % speed == 0) {
            type.receivePulse(block);
            if (once) {
                cancelPulse(location);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) ItemTable(net.glowstone.block.ItemTable) BlockType(net.glowstone.block.blocktype.BlockType)

Example 5 with BlockType

use of net.glowstone.block.blocktype.BlockType in project Glowstone by GlowstoneMC.

the class GlowBlock method applyPhysics.

/////////////////////////////////////////////////////////////////////////////
// Physics
/**
     * Notify this block and its surrounding blocks that this block has changed
     * type and data.
     *
     * @param oldType   the old block type
     * @param newTypeId the new block type
     * @param oldData   the old data
     * @param newData   the new data
     */
public void applyPhysics(Material oldType, int newTypeId, byte oldData, byte newData) {
    // notify the surrounding blocks that this block has changed
    ItemTable itemTable = ItemTable.instance();
    Material newType = Material.getMaterial(newTypeId);
    for (int y = -1; y <= 1; y++) {
        for (BlockFace face : LAYER) {
            if (y == 0 && face == BlockFace.SELF) {
                continue;
            }
            GlowBlock notify = getRelative(face.getModX(), face.getModY() + y, face.getModZ());
            BlockFace blockFace;
            if (y == 0) {
                blockFace = face.getOppositeFace();
            } else if (y == -1 && face == BlockFace.SELF) {
                blockFace = BlockFace.UP;
            } else if (y == 1 && face == BlockFace.SELF) {
                blockFace = BlockFace.DOWN;
            } else {
                blockFace = null;
            }
            BlockType notifyType = itemTable.getBlock(notify.getTypeId());
            if (notifyType != null) {
                notifyType.onNearBlockChanged(notify, blockFace, this, oldType, oldData, newType, newData);
            }
        }
    }
    BlockType type = itemTable.getBlock(oldType);
    if (type != null) {
        type.onBlockChanged(this, oldType, oldData, newType, newData);
    }
}
Also used : BlockType(net.glowstone.block.blocktype.BlockType) BlockFace(org.bukkit.block.BlockFace) Material(org.bukkit.Material)

Aggregations

BlockType (net.glowstone.block.blocktype.BlockType)17 GlowBlock (net.glowstone.block.GlowBlock)8 Material (org.bukkit.Material)5 ItemType (net.glowstone.block.itemtype.ItemType)4 BlockFace (org.bukkit.block.BlockFace)4 Block (org.bukkit.block.Block)3 ItemStack (org.bukkit.inventory.ItemStack)3 GlowWorld (net.glowstone.GlowWorld)2 GlowBlockState (net.glowstone.block.GlowBlockState)2 ItemTable (net.glowstone.block.ItemTable)2 BlockLiquid (net.glowstone.block.blocktype.BlockLiquid)2 BlockEntity (net.glowstone.block.entity.BlockEntity)2 GlowPlayer (net.glowstone.entity.GlowPlayer)2 Action (org.bukkit.event.block.Action)2 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)2 Test (org.junit.Test)2 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 BlockContainer (net.glowstone.block.blocktype.BlockContainer)1 ItemTimedUsage (net.glowstone.block.itemtype.ItemTimedUsage)1