Search in sources :

Example 1 with BlockPortalCavern

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);
        }
    }
}
Also used : Item(net.minecraft.item.Item) EnumActionResult(net.minecraft.util.EnumActionResult) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockPortalCavern(cavern.block.BlockPortalCavern) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with BlockPortalCavern

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);
    }
}
Also used : DimensionType(net.minecraft.world.DimensionType) PatternHelper(net.minecraft.block.state.pattern.BlockPattern.PatternHelper) ConfigCaveborn(cavern.config.property.ConfigCaveborn) WorldServer(net.minecraft.world.WorldServer) Vec3d(net.minecraft.util.math.Vec3d) IPortalCache(cavern.api.IPortalCache) BlockPortalCavern(cavern.block.BlockPortalCavern) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemMeta(cavern.util.ItemMeta) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with BlockPortalCavern

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);
}
Also used : ConfigCaveborn(cavern.config.property.ConfigCaveborn) BlockPortalCavern(cavern.block.BlockPortalCavern) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with BlockPortalCavern

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;
}
Also used : BlockPortalCavern(cavern.block.BlockPortalCavern) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BlockPortalCavern (cavern.block.BlockPortalCavern)4 ItemStack (net.minecraft.item.ItemStack)3 BlockPos (net.minecraft.util.math.BlockPos)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 ConfigCaveborn (cavern.config.property.ConfigCaveborn)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Vec3d (net.minecraft.util.math.Vec3d)2 IPortalCache (cavern.api.IPortalCache)1 ItemMeta (cavern.util.ItemMeta)1 IBlockState (net.minecraft.block.state.IBlockState)1 PatternHelper (net.minecraft.block.state.pattern.BlockPattern.PatternHelper)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 Item (net.minecraft.item.Item)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 EnumFacing (net.minecraft.util.EnumFacing)1 DimensionType (net.minecraft.world.DimensionType)1 World (net.minecraft.world.World)1 WorldServer (net.minecraft.world.WorldServer)1