Search in sources :

Example 1 with LlamaEntity

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;
    }
}
Also used : Permissions(com.minecolonies.coremod.colony.permissions.Permissions) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) AirBlock(net.minecraft.block.AirBlock) LlamaEntity(net.minecraft.entity.passive.horse.LlamaEntity) PermissionEvent(com.minecolonies.api.colony.permissions.PermissionEvent) Block(net.minecraft.block.Block) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) Map(java.util.Map) Event(net.minecraftforge.eventbus.api.Event) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) EntityUtils(com.minecolonies.api.util.EntityUtils) BlockState(net.minecraft.block.BlockState) Constants(com.minecolonies.api.util.constant.Constants) ItemScanTool(com.ldtteam.structurize.items.ItemScanTool) BlockEvent(net.minecraftforge.event.world.BlockEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Predicate(java.util.function.Predicate) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) List(java.util.List) MineColonies(com.minecolonies.coremod.MineColonies) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PotionItem(net.minecraft.item.PotionItem) BlockHutTownHall(com.minecolonies.coremod.blocks.huts.BlockHutTownHall) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IWorld(net.minecraft.world.IWorld) HashMap(java.util.HashMap) ModBlocks(com.minecolonies.api.blocks.ModBlocks) Action(com.minecolonies.api.colony.permissions.Action) Explosions(com.minecolonies.api.colony.permissions.Explosions) ItemStack(net.minecraft.item.ItemStack) ItemTossEvent(net.minecraftforge.event.entity.item.ItemTossEvent) MobEntity(net.minecraft.entity.MobEntity) ExplosionEvent(net.minecraftforge.event.world.ExplosionEvent) ContainerBlock(net.minecraft.block.ContainerBlock) Entity(net.minecraft.entity.Entity) ModTags(com.minecolonies.api.items.ModTags) Colony(com.minecolonies.coremod.colony.Colony) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) BlockPos(net.minecraft.util.math.BlockPos) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) net.minecraftforge.event.entity.player(net.minecraftforge.event.entity.player) LivingHurtEvent(net.minecraftforge.event.entity.living.LivingHurtEvent) IMob(net.minecraft.entity.monster.IMob) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) EntityDamageSource(net.minecraft.util.EntityDamageSource) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) FakePlayer(net.minecraftforge.common.util.FakePlayer) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) LlamaEntity(net.minecraft.entity.passive.horse.LlamaEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) IMob(net.minecraft.entity.monster.IMob) LlamaEntity(net.minecraft.entity.passive.horse.LlamaEntity) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) IWorld(net.minecraft.world.IWorld) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with LlamaEntity

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;
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ArrayList(java.util.ArrayList) AIOneTimeEventTarget(com.minecolonies.api.entity.ai.statemachine.AIOneTimeEventTarget) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) LlamaEntity(net.minecraft.entity.passive.horse.LlamaEntity) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) BlockPos(net.minecraft.util.math.BlockPos) FollowModeSetting(com.minecolonies.coremod.colony.buildings.modules.settings.FollowModeSetting)

Example 3 with LlamaEntity

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;
    }
}
Also used : Permissions(com.minecolonies.coremod.colony.permissions.Permissions) AirBlock(net.minecraft.block.AirBlock) LlamaEntity(net.minecraft.entity.passive.horse.LlamaEntity) PermissionEvent(com.minecolonies.api.colony.permissions.PermissionEvent) PERMISSION_DENIED(com.minecolonies.api.util.constant.TranslationConstants.PERMISSION_DENIED) Block(net.minecraft.block.Block) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) Map(java.util.Map) Event(net.minecraftforge.eventbus.api.Event) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) EntityUtils(com.minecolonies.api.util.EntityUtils) BlockState(net.minecraft.block.BlockState) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) Constants(com.minecolonies.api.util.constant.Constants) ItemScanTool(com.ldtteam.structurize.items.ItemScanTool) BlockEvent(net.minecraftforge.event.world.BlockEvent) MessageUtils(com.minecolonies.api.util.MessageUtils) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Predicate(java.util.function.Predicate) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) List(java.util.List) MineColonies(com.minecolonies.coremod.MineColonies) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PotionItem(net.minecraft.item.PotionItem) BlockHutTownHall(com.minecolonies.coremod.blocks.huts.BlockHutTownHall) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IWorld(net.minecraft.world.IWorld) HashMap(java.util.HashMap) ModBlocks(com.minecolonies.api.blocks.ModBlocks) Action(com.minecolonies.api.colony.permissions.Action) Explosions(com.minecolonies.api.colony.permissions.Explosions) ItemStack(net.minecraft.item.ItemStack) ItemTossEvent(net.minecraftforge.event.entity.item.ItemTossEvent) MobEntity(net.minecraft.entity.MobEntity) ExplosionEvent(net.minecraftforge.event.world.ExplosionEvent) ContainerBlock(net.minecraft.block.ContainerBlock) Entity(net.minecraft.entity.Entity) ModTags(com.minecolonies.api.items.ModTags) Colony(com.minecolonies.coremod.colony.Colony) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) BlockPos(net.minecraft.util.math.BlockPos) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) net.minecraftforge.event.entity.player(net.minecraftforge.event.entity.player) LivingHurtEvent(net.minecraftforge.event.entity.living.LivingHurtEvent) IMob(net.minecraft.entity.monster.IMob) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) EntityDamageSource(net.minecraft.util.EntityDamageSource) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) FakePlayer(net.minecraftforge.common.util.FakePlayer) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) LlamaEntity(net.minecraft.entity.passive.horse.LlamaEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) IMob(net.minecraft.entity.monster.IMob) LlamaEntity(net.minecraft.entity.passive.horse.LlamaEntity) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) IWorld(net.minecraft.world.IWorld) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with LlamaEntity

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;
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ArrayList(java.util.ArrayList) AIOneTimeEventTarget(com.minecolonies.api.entity.ai.statemachine.AIOneTimeEventTarget) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) LlamaEntity(net.minecraft.entity.passive.horse.LlamaEntity) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) BlockPos(net.minecraft.util.math.BlockPos) FollowModeSetting(com.minecolonies.coremod.colony.buildings.modules.settings.FollowModeSetting)

Aggregations

IBuilding (com.minecolonies.api.colony.buildings.IBuilding)4 AbstractJobGuard (com.minecolonies.coremod.colony.jobs.AbstractJobGuard)4 LlamaEntity (net.minecraft.entity.passive.horse.LlamaEntity)4 BlockPos (net.minecraft.util.math.BlockPos)4 ItemScanTool (com.ldtteam.structurize.items.ItemScanTool)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 ModBlocks (com.minecolonies.api.blocks.ModBlocks)2 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IColony (com.minecolonies.api.colony.IColony)2 IColonyManager (com.minecolonies.api.colony.IColonyManager)2 Action (com.minecolonies.api.colony.permissions.Action)2 Explosions (com.minecolonies.api.colony.permissions.Explosions)2 PermissionEvent (com.minecolonies.api.colony.permissions.PermissionEvent)2 AIOneTimeEventTarget (com.minecolonies.api.entity.ai.statemachine.AIOneTimeEventTarget)2 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 ModTags (com.minecolonies.api.items.ModTags)2 EntityUtils (com.minecolonies.api.util.EntityUtils)2 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)2 Constants (com.minecolonies.api.util.constant.Constants)2 MineColonies (com.minecolonies.coremod.MineColonies)2