use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.
the class ItemSpawn method rightClickBlock.
@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
Location location = against.getLocation().add(face.getModX(), face.getModY(), face.getModZ());
// TODO: change mob spawner when clicked by monster egg
if (holding.hasItemMeta() && holding.getItemMeta() instanceof GlowMetaSpawn) {
GlowMetaSpawn meta = (GlowMetaSpawn) holding.getItemMeta();
EntityType type = meta.getSpawnedType();
CompoundTag tag = meta.getEntityTag();
if (type != null) {
GlowEntity entity = against.getWorld().spawn(location.add(0.5, 0, 0.5), EntityRegistry.getEntity(type), SpawnReason.SPAWNER_EGG);
if (tag != null) {
EntityStorage.load(entity, tag);
}
if (player.getGameMode() != GameMode.CREATIVE) {
holding.setAmount(holding.getAmount() - 1);
}
}
}
}
use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.
the class SummonCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (sender instanceof ConsoleCommandSender) {
commandMessages.getGeneric(GenericMessage.NOT_PHYSICAL).send(sender);
return true;
}
Location location = CommandUtils.getLocation(sender);
if (args.length == 0) {
sendUsageMessage(sender, commandMessages);
return false;
}
if (args.length >= 4) {
location = CommandUtils.getLocation(location, args[1], args[2], args[3]);
}
location.setYaw(0.0f);
location.setPitch(0.0f);
CompoundTag tag = null;
if (args.length >= 5) {
String data = String.join(" ", new ArrayList<>(Arrays.asList(args)).subList(4, args.length));
try {
tag = Mojangson.parseCompound(data);
} catch (MojangsonParseException e) {
commandMessages.getGeneric(GenericMessage.INVALID_JSON).sendInColor(ChatColor.RED, sender, e.getMessage());
}
}
String entityName = args[0];
if (!checkSummon(sender, entityName, commandMessages)) {
return true;
}
GlowEntity entity;
if (EntityType.fromName(entityName) != null) {
entity = (GlowEntity) location.getWorld().spawnEntity(location, EntityType.fromName(entityName));
} else {
Class<? extends GlowEntity> clazz = EntityRegistry.getCustomEntityDescriptor(entityName).getEntityClass();
entity = ((GlowWorld) location.getWorld()).spawn(location, clazz, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
if (tag != null) {
EntityStorage.load(entity, tag);
}
new LocalizedStringImpl("summon.done", commandMessages.getResourceBundle()).send(sender);
return true;
}
use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.
the class GlowGuardian method setElder.
@Override
public void setElder(boolean elder) {
if (elder == isElder()) {
return;
}
Class<? extends GlowEntity> clazz = elder ? GlowElderGuardian.class : GlowGuardian.class;
GlowEntity copy = world.spawn(location, clazz);
CompoundTag tag = new CompoundTag();
// Copy attributes
EntityStorage.save(this, tag);
EntityStorage.load(copy, tag);
remove();
}
use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.
the class GlowFirework method pulsePhysics.
@Override
protected void pulsePhysics() {
// TODO: proper physics
if (this.boostedEntity == null) {
// Fireworks velocity is not affected by airdrag or gravity
// These values are static
velocity.setX(velocity.getX() * 1.15);
velocity.setY(velocity.getY() + 0.04);
velocity.setZ(velocity.getZ() * 1.15);
setVelocity(velocity);
} else {
Vector direction = boostedEntity.getLocation().getDirection();
Vector velocity = boostedEntity.getVelocity();
// close enough approximation of vanillas velocity for boosted entity
double dx = direction.getX() * 0.1 + (direction.getX() * 1.5 - velocity.getX()) * 0.5;
double dy = direction.getY() * 0.1 + (direction.getY() * 1.5 - velocity.getY()) * 0.5;
double dz = direction.getZ() * 0.1 + (direction.getZ() * 1.5 - velocity.getZ()) * 0.5;
velocity.setX(velocity.getX() + dx);
velocity.setY(velocity.getY() + dy);
velocity.setZ(velocity.getZ() + dz);
boostedEntity.setVelocity(velocity);
this.setVelocity(velocity);
Location location = boostedEntity.getLocation().add(velocity);
if (boostedEntity instanceof GlowEntity) {
((GlowEntity) boostedEntity).setRawLocation(location, false);
} else {
boostedEntity.teleport(location);
}
}
setRawLocation(this.location.add(velocity), false);
}
use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.
the class GlowEgg method randomHatchSpawning.
/**
* Handle spawning entities when the egg breaks.
*
* @param location The location the egg breaks
*/
private void randomHatchSpawning(Location location) {
ThreadLocalRandom random = ThreadLocalRandom.current();
// There is a 1/8 chance for egg to hatch and spawn at least 1 entity
boolean hatching = random.nextInt(8) == 0;
// ...and if the egg is hatching, there is now
// 1/32 chance to spawn 3 more entities.
byte amount;
if (hatching) {
amount = (byte) ((random.nextInt(32) == 0) ? 4 : 1);
} else {
amount = 0;
}
EntityType hatchingType = EntityType.CHICKEN;
final ProjectileSource shooter = getShooter();
if (shooter instanceof GlowPlayer) {
PlayerEggThrowEvent event = EventFactory.getInstance().callEvent(new PlayerEggThrowEvent((GlowPlayer) shooter, this, hatching, amount, hatchingType));
amount = event.getNumHatches();
hatching = event.isHatching();
hatchingType = event.getHatchingType();
}
if (hatching) {
for (int i = 0; i < amount; i++) {
GlowEntity entity = (GlowEntity) location.getWorld().spawnEntity(location.clone().add(0, 0.3, 0), hatchingType);
if (entity instanceof GlowAgeable) {
((GlowAgeable) entity).setBaby();
}
}
}
}
Aggregations