use of net.minecraft.world.DimensionType 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();
}
}
use of net.minecraft.world.DimensionType in project Cavern2 by kegare.
the class CavebornEventHooks method onPlayerLoggedIn.
@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
if (!(event.player instanceof EntityPlayerMP)) {
return;
}
EntityPlayerMP player = (EntityPlayerMP) event.player;
if (!FIRST_PLAYERS.contains(player.getCachedUniqueIdString())) {
return;
}
WorldServer world = player.getServerWorld();
ConfigCaveborn.Type caveborn = GeneralConfig.caveborn.getType();
BlockPortalCavern portal = caveborn.getPortalBlock();
BlockPos pos = player.getPosition();
IPortalCache cache = PortalCache.get(player);
PatternHelper pattern = portal.createPatternHelper(world, pos);
double d0 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? (double) pattern.getFrontTopLeft().getZ() : (double) pattern.getFrontTopLeft().getX();
double d1 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? player.posZ : player.posX;
d1 = Math.abs(MathHelper.pct(d1 - (pattern.getForwards().rotateY().getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? 1 : 0), d0, d0 - pattern.getWidth()));
double d2 = MathHelper.pct(player.posY - 1.0D, pattern.getFrontTopLeft().getY(), pattern.getFrontTopLeft().getY() - pattern.getHeight());
cache.setLastPortalVec(new Vec3d(d1, d2, 0.0D));
cache.setTeleportDirection(pattern.getForwards());
player.timeUntilPortal = player.getPortalCooldown();
portal.getTeleporter(world).placeInPortal(player, player.rotationYaw);
FIRST_PLAYERS.remove(event.player.getCachedUniqueIdString());
DimensionType type = portal.getDimension();
if (type == CaveDimensions.CAVERN) {
PlayerHelper.grantCriterion(player, "root", "entered_cavern");
} else {
String name = type.getName();
PlayerHelper.grantCriterion(player, "enter_the_" + name, "entered_" + name);
}
pos = player.getPosition();
for (BlockPos blockpos : BlockPos.getAllInBoxMutable(pos.add(-1, -1, -1), pos.add(1, 1, 1))) {
if (world.getBlockState(blockpos).getBlock() == portal) {
world.setBlockToAir(blockpos);
break;
}
}
double x = player.posX;
double y = player.posY + 0.25D;
double z = player.posZ;
world.playSound(null, x, y, z, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.BLOCKS, 1.0F, 0.65F);
for (ItemMeta itemMeta : GeneralConfig.cavebornBonusItems.getItems()) {
ItemStack stack = itemMeta.getItemStack();
if (stack.isStackable()) {
stack = itemMeta.getItemStack(MathHelper.getInt(CaveEventHooks.RANDOM, 4, 16));
}
InventoryHelper.spawnItemStack(world, x, y, z, stack);
}
}
use of net.minecraft.world.DimensionType in project Cavern2 by kegare.
the class ItemMagicBook method addInformation.
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
switch(EnumType.byItemStack(stack)) {
case STORAGE:
IInventory inventory = InventoryMagicStorage.get(stack).getInventory();
if (inventory == null) {
break;
}
int count = 0;
Set<String> names = Sets.newTreeSet();
for (int i = 0; i < inventory.getSizeInventory() && count < 5; ++i) {
ItemStack item = inventory.getStackInSlot(i);
if (!item.isEmpty() && names.add(item.getDisplayName())) {
++count;
}
}
for (String name : names) {
tooltip.add(TextFormatting.ITALIC + name + TextFormatting.RESET);
}
break;
case WARP:
Pair<BlockPos, DimensionType> warpPoint = MagicWarp.getWarpPoint(stack);
if (warpPoint == null) {
break;
}
BlockPos pos = warpPoint.getLeft();
DimensionType type = warpPoint.getRight();
tooltip.add(String.format("%s: %d, %d, %d", type.getName(), pos.getX(), pos.getY(), pos.getZ()));
break;
default:
}
}
use of net.minecraft.world.DimensionType in project Cavern2 by kegare.
the class MagicWarp method getWarpPoint.
@Nullable
public static Pair<BlockPos, DimensionType> getWarpPoint(ItemStack stack) {
if (!hasWarpPoint(stack)) {
return null;
}
NBTTagCompound nbt = stack.getTagCompound();
NBTTagCompound compound = nbt.getCompoundTag("WarpPoint");
BlockPos pos = NBTUtil.getPosFromTag(compound);
DimensionType type;
try {
type = DimensionType.getById(compound.getInteger("Dim"));
} catch (IllegalArgumentException e) {
nbt.removeTag("WarpPoint");
return null;
}
return Pair.of(pos, type);
}
use of net.minecraft.world.DimensionType in project Cavern2 by kegare.
the class ItemMirageBook method transferTo.
public boolean transferTo(@Nullable DimensionType dimNew, EntityPlayer entityPlayer) {
if (entityPlayer == null || !(entityPlayer instanceof EntityPlayerMP)) {
return false;
}
EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
ResourceLocation key = CaveUtils.getKey("mirage_worlds");
IPortalCache cache = PortalCache.get(player);
DimensionType dimOld = player.world.provider.getDimensionType();
if (dimNew == null) {
dimNew = cache.getLastDim(key, null);
}
if (dimNew == null || dimOld == dimNew) {
return false;
}
if (CavernAPI.dimension.isMirageWorlds(dimNew)) {
cache.setLastDim(key, dimOld);
}
cache.setLastPos(key, dimOld, player.getPosition());
player.timeUntilPortal = player.getPortalCooldown();
player.changeDimension(dimNew.getId(), this);
if (player.getBedLocation(dimNew.getId()) == null) {
player.setSpawnChunk(player.getPosition(), true, dimNew.getId());
}
return true;
}
Aggregations