Search in sources :

Example 1 with ItemMeta

use of cavern.util.ItemMeta 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 2 with ItemMeta

use of cavern.util.ItemMeta in project Cavern2 by kegare.

the class ConfigItems method refreshItems.

public void refreshItems() {
    items.clear();
    Arrays.stream(getValues()).filter(value -> !Strings.isNullOrEmpty(value)).forEach(value -> {
        value = value.trim();
        if (!value.contains(":")) {
            value = "minecraft:" + value;
        }
        ItemMeta itemMeta;
        if (value.indexOf(':') != value.lastIndexOf(':')) {
            int i = value.lastIndexOf(':');
            itemMeta = new ItemMeta(value.substring(0, i), NumberUtils.toInt(value.substring(i + 1)));
        } else {
            itemMeta = new ItemMeta(value, 0);
        }
        if (!itemMeta.isEmpty()) {
            items.add(itemMeta);
        }
    });
}
Also used : Strings(com.google.common.base.Strings) ItemStack(net.minecraft.item.ItemStack) Arrays(java.util.Arrays) ItemMeta(cavern.util.ItemMeta) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Set(java.util.Set) NonNullList(net.minecraft.util.NonNullList) Sets(com.google.common.collect.Sets) ItemMeta(cavern.util.ItemMeta)

Example 3 with ItemMeta

use of cavern.util.ItemMeta in project Cavern2 by kegare.

the class GuiSelectItem method drawScreen.

@Override
public void drawScreen(int mouseX, int mouseY, float ticks) {
    itemList.drawScreen(mouseX, mouseY, ticks);
    boolean single = nameField != null || metaField != null;
    String name = null;
    if (single) {
        name = I18n.format(Config.LANG_KEY + "select.item");
    } else {
        name = I18n.format(Config.LANG_KEY + "select.item.multiple");
    }
    if (!Strings.isNullOrEmpty(name)) {
        drawCenteredString(fontRenderer, name, width / 2, 15, 0xFFFFFF);
    }
    super.drawScreen(mouseX, mouseY, ticks);
    filterTextField.drawTextBox();
    if (detailHoverChecker.checkHover(mouseX, mouseY)) {
        drawHoveringText(fontRenderer.listFormattedStringToWidth(I18n.format(Config.LANG_KEY + "detail.hover"), 300), mouseX, mouseY);
    } else if (instantHoverChecker.checkHover(mouseX, mouseY)) {
        drawHoveringText(fontRenderer.listFormattedStringToWidth(I18n.format(Config.LANG_KEY + "instant.hover"), 300), mouseX, mouseY);
    }
    if (!single && !itemList.selected.isEmpty()) {
        if (mouseX <= 100 && mouseY <= 20) {
            drawString(fontRenderer, I18n.format(Config.LANG_KEY + "select.item.selected", itemList.selected.size()), 5, 5, 0xEFEFEF);
        }
        if (selectedHoverChecker.checkHover(mouseX, mouseY)) {
            List<String> texts = Lists.newArrayList();
            for (ItemMeta itemMeta : itemList.selected) {
                name = itemList.getItemMetaTypeName(itemMeta);
                if (!Strings.isNullOrEmpty(name)) {
                    texts.add(name);
                }
            }
            drawHoveringText(texts, mouseX, mouseY);
        }
    }
}
Also used : ItemMeta(cavern.util.ItemMeta)

Aggregations

ItemMeta (cavern.util.ItemMeta)3 ItemStack (net.minecraft.item.ItemStack)2 IPortalCache (cavern.api.IPortalCache)1 BlockPortalCavern (cavern.block.BlockPortalCavern)1 ConfigCaveborn (cavern.config.property.ConfigCaveborn)1 Strings (com.google.common.base.Strings)1 Sets (com.google.common.collect.Sets)1 Arrays (java.util.Arrays)1 Set (java.util.Set)1 PatternHelper (net.minecraft.block.state.pattern.BlockPattern.PatternHelper)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 NonNullList (net.minecraft.util.NonNullList)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3d (net.minecraft.util.math.Vec3d)1 DimensionType (net.minecraft.world.DimensionType)1 WorldServer (net.minecraft.world.WorldServer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 NumberUtils (org.apache.commons.lang3.math.NumberUtils)1