use of net.minecraft.entity.passive.horse.LlamaEntity in project minecolonies by ldtteam.
the class ColonyPermissionEventHandler method on.
/**
* ExplosionEvent.Detonate handler.
*
* @param event ExplosionEvent.Detonate
*/
@SubscribeEvent
public void on(final ExplosionEvent.Detonate event) {
if (MineColonies.getConfig().getServer().turnOffExplosionsInColonies.get() == Explosions.DAMAGE_EVERYTHING) {
return;
}
final World eventWorld = event.getWorld();
final Predicate<BlockPos> getBlocksInColony = pos -> colony.isCoordInColony(eventWorld, pos);
Predicate<Entity> getEntitiesInColony = entity -> (!(entity instanceof IMob) || (entity instanceof LlamaEntity)) && colony.isCoordInColony(entity.getCommandSenderWorld(), new BlockPos(entity.position()));
switch(MineColonies.getConfig().getServer().turnOffExplosionsInColonies.get()) {
case DAMAGE_NOTHING:
// if any entity is in colony -> remove from list
getEntitiesInColony = entity -> colony.isCoordInColony(entity.getCommandSenderWorld(), new BlockPos(entity.position()));
// intentional fall-through to next case.
case DAMAGE_PLAYERS:
// if non-mob or llama entity is in colony -> remove from list
final List<Entity> entitiesToRemove = event.getAffectedEntities().stream().filter(getEntitiesInColony).filter(entity -> !(entity instanceof ServerPlayerEntity)).collect(Collectors.toList());
event.getAffectedEntities().removeAll(entitiesToRemove);
// intentional fall-through to next case.
case DAMAGE_ENTITIES:
// if block is in colony -> remove from list
final List<BlockPos> blocksToRemove = event.getAffectedBlocks().stream().filter(getBlocksInColony).collect(Collectors.toList());
event.getAffectedBlocks().removeAll(blocksToRemove);
break;
case DAMAGE_EVERYTHING:
default:
break;
}
}
use of net.minecraft.entity.passive.horse.LlamaEntity in project minecolonies by Minecolonies.
the class ItemScrollGuardHelp method onItemUseSuccess.
@Override
protected ItemStack onItemUseSuccess(final ItemStack itemStack, final World world, final ServerPlayerEntity player) {
final IColony colony = getColony(itemStack);
final BlockPos buildingPos = BlockPosUtil.read(itemStack.getTag(), TAG_BUILDING_POS);
final IBuilding building = colony.getBuildingManager().getBuilding(buildingPos);
if (!(building instanceof AbstractBuildingGuards)) {
MessageUtils.format(TOOL_GUARD_SCROLL_NO_GUARD_BUILDING).sendTo(player);
return itemStack;
}
itemStack.shrink(1);
final List<ICitizenData> guards = new ArrayList<>(building.getAllAssignedCitizen());
if (world.random.nextInt(10) == 0 || colony.getWorld() != world) {
// Fail
final LlamaEntity entity = EntityType.LLAMA.create(world);
entity.setPos(player.getX(), player.getY(), player.getZ());
world.addFreshEntity(entity);
player.displayClientMessage(new TranslationTextComponent("minecolonies.scroll.failed" + (world.random.nextInt(FAIL_RESPONSES_TOTAL) + 1)).setStyle(Style.EMPTY.withColor(TextFormatting.GOLD)), true);
SoundUtils.playSoundForPlayer(player, SoundEvents.EVOKER_CAST_SPELL, 0.5f, 1.0f);
return itemStack;
} else {
for (final ICitizenData citizenData : guards) {
final AbstractJobGuard job = citizenData.getJob(AbstractJobGuard.class);
if (job != null && job.getWorkerAI() != null && !((AbstractEntityAIGuard) job.getWorkerAI()).hasTool()) {
continue;
}
if (citizenData.getEntity().isPresent()) {
if (citizenData.getEntity().get().getCitizenDiseaseHandler().isSick()) {
continue;
}
citizenData.getEntity().get().remove();
}
colony.getCitizenManager().spawnOrCreateCivilian(citizenData, world, player.blockPosition(), true);
citizenData.setNextRespawnPosition(buildingPos);
((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.FOLLOW);
((AbstractBuildingGuards) building).setPlayerToFollow(player);
final FollowModeSetting grouping = ((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.FOLLOW_MODE);
if (grouping.getValue().equals(FollowModeSetting.LOOSE)) {
grouping.trigger();
}
citizenData.setSaturation(100);
colony.getPackageManager().addCloseSubscriber(player);
if (job != null && job.getWorkerAI() != null) {
final long spawnTime = world.getGameTime() + TICKS_SECOND * 900;
// Timed despawn
job.getWorkerAI().registerTarget(new AIOneTimeEventTarget(() -> {
if (world.getGameTime() - spawnTime > 0) {
((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.PATROL);
citizenData.getEntity().ifPresent(Entity::remove);
colony.getPackageManager().removeCloseSubscriber(player);
return true;
}
return false;
}, AIWorkerState.DECIDE));
}
}
SoundUtils.playSoundForPlayer(player, SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, 0.3f, 1.0f);
}
return itemStack;
}
use of net.minecraft.entity.passive.horse.LlamaEntity in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* ExplosionEvent.Detonate handler.
*
* @param event ExplosionEvent.Detonate
*/
@SubscribeEvent
public void on(final ExplosionEvent.Detonate event) {
if (MineColonies.getConfig().getServer().turnOffExplosionsInColonies.get() == Explosions.DAMAGE_EVERYTHING) {
return;
}
final World eventWorld = event.getWorld();
final Predicate<BlockPos> getBlocksInColony = pos -> colony.isCoordInColony(eventWorld, pos);
Predicate<Entity> getEntitiesInColony = entity -> (!(entity instanceof IMob) || (entity instanceof LlamaEntity)) && colony.isCoordInColony(entity.getCommandSenderWorld(), new BlockPos(entity.position()));
switch(MineColonies.getConfig().getServer().turnOffExplosionsInColonies.get()) {
case DAMAGE_NOTHING:
// if any entity is in colony -> remove from list
getEntitiesInColony = entity -> colony.isCoordInColony(entity.getCommandSenderWorld(), new BlockPos(entity.position()));
// intentional fall-through to next case.
case DAMAGE_PLAYERS:
// if non-mob or llama entity is in colony -> remove from list
final List<Entity> entitiesToRemove = event.getAffectedEntities().stream().filter(getEntitiesInColony).filter(entity -> !(entity instanceof ServerPlayerEntity)).collect(Collectors.toList());
event.getAffectedEntities().removeAll(entitiesToRemove);
// intentional fall-through to next case.
case DAMAGE_ENTITIES:
// if block is in colony -> remove from list
final List<BlockPos> blocksToRemove = event.getAffectedBlocks().stream().filter(getBlocksInColony).collect(Collectors.toList());
event.getAffectedBlocks().removeAll(blocksToRemove);
break;
case DAMAGE_EVERYTHING:
default:
break;
}
}
use of net.minecraft.entity.passive.horse.LlamaEntity in project minecolonies by ldtteam.
the class ItemScrollGuardHelp method onItemUseSuccess.
@Override
protected ItemStack onItemUseSuccess(final ItemStack itemStack, final World world, final ServerPlayerEntity player) {
final IColony colony = getColony(itemStack);
final BlockPos buildingPos = BlockPosUtil.read(itemStack.getTag(), TAG_BUILDING_POS);
final IBuilding building = colony.getBuildingManager().getBuilding(buildingPos);
if (!(building instanceof AbstractBuildingGuards)) {
LanguageHandler.sendPlayerMessage(player, "minecolonies.scroll.noguardbuilding");
return itemStack;
}
itemStack.shrink(1);
final List<ICitizenData> guards = new ArrayList<>(building.getAllAssignedCitizen());
if (world.random.nextInt(10) == 0 || colony.getWorld() != world) {
// Fail
final LlamaEntity entity = EntityType.LLAMA.create(world);
entity.setPos(player.getX(), player.getY(), player.getZ());
world.addFreshEntity(entity);
player.displayClientMessage(new TranslationTextComponent("minecolonies.scroll.failed" + (world.random.nextInt(FAIL_RESPONSES_TOTAL) + 1)).setStyle(Style.EMPTY.withColor(TextFormatting.GOLD)), true);
SoundUtils.playSoundForPlayer(player, SoundEvents.EVOKER_CAST_SPELL, 0.5f, 1.0f);
return itemStack;
} else {
for (final ICitizenData citizenData : guards) {
final AbstractJobGuard job = citizenData.getJob(AbstractJobGuard.class);
if (job != null && job.getWorkerAI() != null && !((AbstractEntityAIGuard) job.getWorkerAI()).hasTool()) {
continue;
}
if (citizenData.getEntity().isPresent()) {
if (citizenData.getEntity().get().getCitizenDiseaseHandler().isSick()) {
continue;
}
citizenData.getEntity().get().remove();
}
colony.getCitizenManager().spawnOrCreateCivilian(citizenData, world, player.blockPosition(), true);
citizenData.setNextRespawnPosition(buildingPos);
((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.FOLLOW);
((AbstractBuildingGuards) building).setPlayerToFollow(player);
final FollowModeSetting grouping = ((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.FOLLOW_MODE);
if (grouping.getValue().equals(FollowModeSetting.LOOSE)) {
grouping.trigger();
}
citizenData.setSaturation(100);
colony.getPackageManager().addCloseSubscriber(player);
if (job != null && job.getWorkerAI() != null) {
final long spawnTime = world.getGameTime() + TICKS_SECOND * 900;
// Timed despawn
job.getWorkerAI().registerTarget(new AIOneTimeEventTarget(() -> {
if (world.getGameTime() - spawnTime > 0) {
((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.PATROL);
citizenData.getEntity().ifPresent(Entity::remove);
colony.getPackageManager().removeCloseSubscriber(player);
return true;
}
return false;
}, AIWorkerState.DECIDE));
}
}
SoundUtils.playSoundForPlayer(player, SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, 0.3f, 1.0f);
}
return itemStack;
}
Aggregations