use of cavern.block.BlockPortalCavern in project Cavern2 by kegare.
the class CaveEventHooks method onPlayerRightClickBlock.
@SubscribeEvent
public void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
ItemStack stack = event.getItemStack();
if (stack.isEmpty()) {
return;
}
World world = event.getWorld();
BlockPos pos = event.getPos();
IBlockState state = world.getBlockState(pos);
if (state.getBlock() != Blocks.MOSSY_COBBLESTONE && (state.getBlock() != Blocks.STONEBRICK || state.getBlock().getMetaFromState(state) != BlockStoneBrick.MOSSY_META)) {
return;
}
EntityPlayer player = event.getEntityPlayer();
Set<BlockPortalCavern> portals = Sets.newHashSet();
portals.add(CaveBlocks.CAVERN_PORTAL);
portals.add(CaveBlocks.HUGE_CAVERN_PORTAL);
portals.add(CaveBlocks.AQUA_CAVERN_PORTAL);
portals.add(CaveBlocks.MIRAGE_PORTAL);
Item portalItem = Items.AIR;
for (BlockPortalCavern portal : portals) {
if (portal.isTriggerItem(stack)) {
portalItem = Item.getItemFromBlock(portal);
break;
}
}
if (portalItem != Items.AIR) {
EnumFacing facing = ObjectUtils.defaultIfNull(event.getFace(), EnumFacing.UP);
Vec3d hit = event.getHitVec();
EnumActionResult result = portalItem.onItemUse(player, world, pos, event.getHand(), facing, (float) hit.x, (float) hit.y, (float) hit.z);
if (result == EnumActionResult.SUCCESS) {
event.setCancellationResult(result);
event.setCanceled(true);
}
}
}
use of cavern.block.BlockPortalCavern 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 cavern.block.BlockPortalCavern in project Cavern2 by kegare.
the class CavebornEventHooks method onPlayerLoadFromFile.
@SubscribeEvent
public void onPlayerLoadFromFile(PlayerEvent.LoadFromFile event) {
String uuid = event.getPlayerUUID();
for (String str : event.getPlayerDirectory().list()) {
if (str.startsWith(uuid)) {
return;
}
}
ConfigCaveborn.Type caveborn = GeneralConfig.caveborn.getType();
if (caveborn == ConfigCaveborn.Type.DISABLED) {
return;
}
BlockPortalCavern portal = caveborn.getPortalBlock();
if (portal == null || portal.getDimension() == null) {
return;
}
EntityPlayer player = event.getEntityPlayer();
player.dimension = portal.getDimension().getId();
FIRST_PLAYERS.add(uuid);
}
use of cavern.block.BlockPortalCavern in project Cavern2 by kegare.
the class ItemPortalCave method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
BlockPos offset = pos.offset(side);
ItemStack held = player.getHeldItem(hand);
BlockPortalCavern portal = (BlockPortalCavern) block;
if (portal.trySpawnPortal(world, offset)) {
world.playSound(null, offset.getX() + 0.5D, offset.getY() + 0.5D, offset.getZ() + 0.5D, SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 1.0F, 2.0F);
if (!player.capabilities.isCreativeMode && portal != CaveBlocks.MIRAGE_PORTAL) {
held.shrink(1);
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
Aggregations