use of cavern.network.client.MirageSelectMessage in project Cavern2 by kegare.
the class BlockPortalMirageWorlds method onEntityCollidedWithBlock.
@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
if (world.isRemote || entity.isDead || entity.isRiding() || entity.isBeingRidden() || !(entity instanceof EntityPlayerMP)) {
return;
}
EntityPlayerMP player = (EntityPlayerMP) entity;
if (player.timeUntilPortal <= 0) {
player.timeUntilPortal = player.getPortalCooldown();
Set<DimensionType> types = Sets.newHashSet();
for (ItemStack stack : player.inventory.mainInventory) {
DimensionType type = getDimension(stack);
if (type != null) {
types.add(type);
}
}
for (ItemStack stack : player.getHeldEquipment()) {
DimensionType type = getDimension(stack);
if (type != null) {
types.add(type);
}
}
if (types.isEmpty()) {
player.sendStatusMessage(new TextComponentTranslation("cavern.message.portal.mirage"), true);
return;
}
MirageSelectMessage message = new MirageSelectMessage();
for (DimensionType type : types) {
if (player.capabilities.isCreativeMode) {
message.dimensions.add(type);
continue;
}
long teleportTime = PlayerData.get(player).getLastTeleportTime(type);
if (teleportTime <= 0L || teleportTime + 6000L < world.getTotalWorldTime()) {
message.dimensions.add(type);
}
}
if (message.dimensions.isEmpty()) {
player.sendStatusMessage(new TextComponentTranslation("cavern.message.portal.wait"), true);
return;
} else if (message.dimensions.size() == 1) {
for (DimensionType type : message.dimensions) {
double x = player.posX;
double y = player.posY + player.getEyeHeight();
double z = player.posZ;
player.getServerWorld().playSound(player, x, y, z, CaveSounds.CAVE_PORTAL, SoundCategory.BLOCKS, 0.5F, 1.0F);
CaveItems.MIRAGE_BOOK.transferTo(type, player);
return;
}
}
CaveNetworkRegistry.sendTo(message, player);
} else {
player.timeUntilPortal = player.getPortalCooldown();
}
}
Aggregations