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());
}
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);
}
}
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();
}
}
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);
}
}
}
}
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);
}
}
Aggregations