Skip to content

Instantly share code, notes, and snippets.

@RedNesto
Created August 31, 2018 14:16
Show Gist options
  • Save RedNesto/6fdd0d1e8ce66a52374432e1544c43ba to your computer and use it in GitHub Desktop.
Save RedNesto/6fdd0d1e8ce66a52374432e1544c43ba to your computer and use it in GitHub Desktop.
private boolean cancelImpacts;
@Listener
public void onInit(GameInitializationEvent event) {
Sponge.getCommandManager().register(this, CommandSpec.builder().executor((src, args) -> {
((Player) src).getNearbyEntities(20).forEach(entity -> {
if (entity instanceof ShulkerBullet) {
entity.offer(Keys.TARGETED_ENTITY, Optional.empty());
}
});
return CommandResult.success();
}).build(), "untarget");
Sponge.getCommandManager().register(this, CommandSpec.builder().executor((src, args) -> {
this.cancelImpacts = !this.cancelImpacts;
return CommandResult.success();
}).build(), "toggle_impacts");
Sponge.getCommandManager().register(this, CommandSpec.builder().executor((src, args) -> {
Iterator<Entity> iterator = ((Player) src).getNearbyEntities(entity -> entity instanceof Shulker).iterator();
if (iterator.hasNext()) {
Shulker shulker = (Shulker) iterator.next();
World world = shulker.getWorld();
Random random = new Random();
// Creates the zombie in a random location within a 10x5x10 zone around the bullet
Entity zombie = world.createEntity(EntityTypes.ZOMBIE, shulker.getLocation().add(
random.nextInt(20) - 10,
random.nextInt(5),
random.nextInt(20) - 10).getPosition());
zombie.offer(Keys.POTION_EFFECTS, Arrays.asList(PotionEffect.of(PotionEffectTypes.FIRE_RESISTANCE, 255, 9999)));
world.spawnEntity(zombie);
shulker.launchWithTarget(ShulkerBullet.class, zombie);
}
return CommandResult.success();
}).build(), "launch");
}
@Listener
public void onEntitySpawn(SpawnEntityEvent event) {
event.getEntities().forEach(entity -> {
if (entity instanceof Shulker) {
Collection<DyeColor> dyeColors = Sponge.getRegistry().getAllOf(DyeColor.class);
DyeColor dyeColor = dyeColors.toArray(new DyeColor[]{})[new Random().nextInt(dyeColors.size())];
entity.offer(Keys.DYE_COLOR, dyeColor);
}
});
}
@Listener
public void onBlockImpact(CollideBlockEvent.Impact event) {
if (this.cancelImpacts)
event.setCancelled(true);
}
@Listener
public void onEntityImpact(CollideEntityEvent.Impact event) {
if (this.cancelImpacts)
event.setCancelled(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment