2014-06-13 16:22:26 +02:00
|
|
|
package resonantinduction.atomic.blocks;
|
2014-05-14 18:10:15 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-06-13 19:18:51 +02:00
|
|
|
import net.minecraft.world.World;
|
2014-07-14 20:46:49 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import resonant.content.spatial.block.SpatialBlock;
|
2014-05-14 18:10:15 +02:00
|
|
|
import resonantinduction.core.Reference;
|
|
|
|
import universalelectricity.api.UniversalElectricity;
|
2014-07-14 20:46:49 +02:00
|
|
|
import universalelectricity.core.transform.vector.Vector3;
|
2014-05-14 18:10:15 +02:00
|
|
|
|
|
|
|
/** Siren block */
|
2014-07-14 20:46:49 +02:00
|
|
|
public class TileSiren extends SpatialBlock
|
2014-05-14 18:10:15 +02:00
|
|
|
{
|
|
|
|
public TileSiren()
|
|
|
|
{
|
|
|
|
super(UniversalElectricity.machine);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onWorldJoin()
|
|
|
|
{
|
|
|
|
scheduelTick(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNeighborChanged()
|
|
|
|
{
|
|
|
|
scheduelTick(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity()
|
|
|
|
{
|
2014-06-13 19:18:51 +02:00
|
|
|
World world = worldObj;
|
|
|
|
if (world != null)
|
2014-05-14 18:10:15 +02:00
|
|
|
{
|
2014-06-13 19:18:51 +02:00
|
|
|
int metadata = world.getBlockMetadata(x(), y(), z());
|
2014-05-14 18:10:15 +02:00
|
|
|
|
2014-06-13 19:18:51 +02:00
|
|
|
if (world.getBlockPowerInput(x(), y(), z()) > 0)
|
2014-05-14 18:10:15 +02:00
|
|
|
{
|
2014-06-13 19:18:51 +02:00
|
|
|
float volume = 0.5f;
|
|
|
|
for (int i = 0; i < 6; i++)
|
2014-05-14 18:10:15 +02:00
|
|
|
{
|
2014-07-14 20:46:49 +02:00
|
|
|
Vector3 check = position().add(ForgeDirection.getOrientation(i));
|
|
|
|
if (check.getBlock(world) == blockID())
|
2014-06-13 19:18:51 +02:00
|
|
|
{
|
|
|
|
volume *= 1.5f;
|
|
|
|
}
|
2014-05-14 18:10:15 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 19:18:51 +02:00
|
|
|
world.playSoundEffect(x(), y(), z(), Reference.PREFIX + "alarm", volume, 1f - 0.18f * (metadata / 15f));
|
|
|
|
scheduelTick(30);
|
|
|
|
}
|
2014-05-14 18:10:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean configure(EntityPlayer player, int side, Vector3 hit)
|
|
|
|
{
|
|
|
|
int metadata = world().getBlockMetadata(x(), y(), z());
|
|
|
|
|
|
|
|
if (player.isSneaking())
|
|
|
|
{
|
|
|
|
metadata -= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
metadata += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata = Math.max(metadata % 16, 0);
|
|
|
|
|
|
|
|
world().setBlockMetadataWithNotify(x(), y(), z(), metadata, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|