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!");
}
}
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;
}
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);
}
}
}
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;
}
}
}
}
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);
}
}
}
Aggregations