Search in sources :

Example 1 with PlayerExtendedProperties

use of mcjty.rftools.playerprops.PlayerExtendedProperties in project RFTools by McJty.

the class ChargedPorterItem method startTeleport.

private void startTeleport(ItemStack stack, EntityPlayer player, World world) {
    NBTTagCompound tagCompound = stack.getTagCompound();
    if (tagCompound == null || (!tagCompound.hasKey("target")) || tagCompound.getInteger("target") == -1) {
        if (world.isRemote) {
            Logging.message(player, EnumChatFormatting.RED + "The charged porter has no target.");
        }
        return;
    }
    if (!world.isRemote) {
        IExtendedEntityProperties properties = player.getExtendedProperties(PlayerExtendedProperties.ID);
        PlayerExtendedProperties playerExtendedProperties = (PlayerExtendedProperties) properties;
        if (playerExtendedProperties.getPorterProperties().isTeleporting()) {
            Logging.message(player, EnumChatFormatting.RED + "Already teleporting!");
            return;
        }
        int target = tagCompound.getInteger("target");
        TeleportDestinations destinations = TeleportDestinations.getDestinations(world);
        GlobalCoordinate coordinate = destinations.getCoordinateForId(target);
        if (coordinate == null) {
            Logging.message(player, EnumChatFormatting.RED + "Something went wrong! The target has disappeared!");
            TeleportationTools.applyEffectForSeverity(player, 3, false);
            return;
        }
        TeleportDestination destination = destinations.getDestination(coordinate);
        if (!TeleportationTools.checkValidTeleport(player, world.provider.dimensionId, destination.getDimension())) {
            return;
        }
        Coordinate playerCoordinate = new Coordinate((int) player.posX, (int) player.posY, (int) player.posZ);
        int cost = TeleportationTools.calculateRFCost(world, playerCoordinate, destination);
        cost *= 1.5f;
        int energy = getEnergyStored(stack);
        if (cost > energy) {
            Logging.message(player, EnumChatFormatting.RED + "Not enough energy to start the teleportation!");
            return;
        }
        extractEnergyNoMax(stack, cost, false);
        int ticks = TeleportationTools.calculateTime(world, playerCoordinate, destination);
        ticks /= getSpeedBonus();
        playerExtendedProperties.getPorterProperties().startTeleport(target, ticks);
        Logging.message(player, EnumChatFormatting.YELLOW + "Start teleportation!");
    }
}
Also used : PlayerExtendedProperties(mcjty.rftools.playerprops.PlayerExtendedProperties) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IExtendedEntityProperties(net.minecraftforge.common.IExtendedEntityProperties) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Example 2 with PlayerExtendedProperties

use of mcjty.rftools.playerprops.PlayerExtendedProperties in project RFTools by McJty.

the class TeleportDestinations method getValidDestinations.

// Server side only
public Collection<TeleportDestinationClientInfo> getValidDestinations(World worldObj, String playerName) {
    PlayerExtendedProperties properties = null;
    if (playerName != null) {
        List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
        for (Object player : list) {
            EntityPlayerMP entityplayermp = (EntityPlayerMP) player;
            if (playerName.equals(entityplayermp.getDisplayName())) {
                properties = PlayerExtendedProperties.getProperties(entityplayermp);
                break;
            }
        }
    }
    List<TeleportDestinationClientInfo> result = new ArrayList<TeleportDestinationClientInfo>();
    for (TeleportDestination destination : destinations.values()) {
        TeleportDestinationClientInfo destinationClientInfo = new TeleportDestinationClientInfo(destination);
        Coordinate c = destination.getCoordinate();
        World world = DimensionManager.getWorld(destination.getDimension());
        String dimName = null;
        if (world != null) {
            dimName = DimensionManager.getProvider(destination.getDimension()).getDimensionName();
        }
        DimensionInformation information = RfToolsDimensionManager.getDimensionManager(worldObj).getDimensionInformation(destination.getDimension());
        if (information != null) {
            dimName = information.getName();
        }
        if (dimName == null || dimName.trim().isEmpty()) {
            dimName = "Id " + destination.getDimension();
        } else {
            dimName = dimName + " (" + destination.getDimension() + ")";
        }
        destinationClientInfo.setDimensionName(dimName);
        if (world != null) {
            TileEntity te = world.getTileEntity(c.getX(), c.getY(), c.getZ());
            if (te instanceof MatterReceiverTileEntity) {
                MatterReceiverTileEntity matterReceiverTileEntity = (MatterReceiverTileEntity) te;
                if (playerName != null && !matterReceiverTileEntity.checkAccess(playerName)) {
                    // No access.
                    continue;
                }
            }
        }
        if (properties != null) {
            destinationClientInfo.setFavorite(properties.getFavoriteDestinationsProperties().isDestinationFavorite(new GlobalCoordinate(c, destination.getDimension())));
        }
        result.add(destinationClientInfo);
    }
    Collections.sort(result);
    return result;
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) PlayerExtendedProperties(mcjty.rftools.playerprops.PlayerExtendedProperties) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) NBTTagList(net.minecraft.nbt.NBTTagList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DimensionInformation(mcjty.rftools.dimension.DimensionInformation)

Example 3 with PlayerExtendedProperties

use of mcjty.rftools.playerprops.PlayerExtendedProperties in project RFTools by McJty.

the class FMLEventHandlers method onPlayerTickEvent.

@SubscribeEvent
public void onPlayerTickEvent(TickEvent.PlayerTickEvent event) {
    if (event.phase == TickEvent.Phase.START && !event.player.worldObj.isRemote) {
        IExtendedEntityProperties properties = event.player.getExtendedProperties(PlayerExtendedProperties.ID);
        if (properties instanceof PlayerExtendedProperties) {
            PlayerExtendedProperties playerExtendedProperties = (PlayerExtendedProperties) properties;
            playerExtendedProperties.tick();
        }
        properties = event.player.getExtendedProperties(PlayerPreferencesProperties.ID);
        if (properties instanceof PlayerPreferencesProperties) {
            PlayerPreferencesProperties preferencesProperties = (PlayerPreferencesProperties) properties;
            preferencesProperties.tick(RFToolsMessages.INSTANCE);
        }
    }
}
Also used : PlayerExtendedProperties(mcjty.rftools.playerprops.PlayerExtendedProperties) IExtendedEntityProperties(net.minecraftforge.common.IExtendedEntityProperties) PlayerPreferencesProperties(mcjty.lib.preferences.PlayerPreferencesProperties) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 4 with PlayerExtendedProperties

use of mcjty.rftools.playerprops.PlayerExtendedProperties in project RFTools by McJty.

the class ForgeEventHandlers method onLivingFallEvent.

@SubscribeEvent
public void onLivingFallEvent(LivingFallEvent event) {
    if (event.entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.entity;
        PlayerExtendedProperties playerExtendedProperties = PlayerExtendedProperties.getProperties(player);
        if (!player.worldObj.isRemote) {
            if (playerExtendedProperties.getBuffProperties().hasBuff(PlayerBuff.BUFF_FEATHERFALLING)) {
                event.distance /= 2.0f;
            } else if (playerExtendedProperties.getBuffProperties().hasBuff(PlayerBuff.BUFF_FEATHERFALLINGPLUS)) {
                event.distance /= 8.0f;
            }
        }
    }
}
Also used : PlayerExtendedProperties(mcjty.rftools.playerprops.PlayerExtendedProperties) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 5 with PlayerExtendedProperties

use of mcjty.rftools.playerprops.PlayerExtendedProperties in project RFTools by McJty.

the class ForgeEventHandlers method onEntityConstructingEvent.

@SubscribeEvent
public void onEntityConstructingEvent(EntityEvent.EntityConstructing event) {
    if (event.entity instanceof EntityPlayer) {
        PlayerExtendedProperties properties = new PlayerExtendedProperties();
        event.entity.registerExtendedProperties(PlayerExtendedProperties.ID, properties);
        PlayerPreferencesProperties preferencesProperties = (PlayerPreferencesProperties) event.entity.getExtendedProperties(PlayerPreferencesProperties.ID);
        if (preferencesProperties == null) {
            preferencesProperties = new PlayerPreferencesProperties();
            event.entity.registerExtendedProperties(PlayerPreferencesProperties.ID, preferencesProperties);
        }
    }
}
Also used : PlayerExtendedProperties(mcjty.rftools.playerprops.PlayerExtendedProperties) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PlayerPreferencesProperties(mcjty.lib.preferences.PlayerPreferencesProperties) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

PlayerExtendedProperties (mcjty.rftools.playerprops.PlayerExtendedProperties)6 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)3 PlayerPreferencesProperties (mcjty.lib.preferences.PlayerPreferencesProperties)2 Coordinate (mcjty.lib.varia.Coordinate)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 IExtendedEntityProperties (net.minecraftforge.common.IExtendedEntityProperties)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DimensionInformation (mcjty.rftools.dimension.DimensionInformation)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TileEntity (net.minecraft.tileentity.TileEntity)1 World (net.minecraft.world.World)1