Search in sources :

Example 66 with Vector3

use of micdoodle8.mods.galacticraft.api.vector.Vector3 in project Galacticraft by micdoodle8.

the class GuiNewSpaceRace method drawScreen.

@Override
public void drawScreen(int par1, int par2, float par3) {
    this.drawDefaultBackground();
    if (this.initialized) {
        this.buttonFlag_hover = this.canEdit && this.currentState == EnumSpaceRaceGui.MAIN && par1 >= this.buttonFlag_xPosition && par2 >= this.buttonFlag_yPosition && par1 < this.buttonFlag_xPosition + this.buttonFlag_width && par2 < this.buttonFlag_yPosition + this.buttonFlag_height;
        this.buttonTeamColor_hover = this.canEdit && this.currentState == EnumSpaceRaceGui.MAIN && par1 >= this.buttonTeamColor_xPosition && par2 >= this.buttonTeamColor_yPosition && par1 < this.buttonTeamColor_xPosition + this.buttonTeamColor_width && par2 < this.buttonTeamColor_yPosition + this.buttonTeamColor_height;
        switch(this.currentState) {
            case MAIN:
                this.drawCenteredString(this.fontRendererObj, GCCoreUtil.translate("gui.space_race.create.title.name"), this.width / 2, this.height / 2 - this.height / 3 - 15, 16777215);
                this.drawFlagButton();
                this.drawColorButton();
                GuiElementGradientButton serverStats = (GuiElementGradientButton) this.buttonList.get(this.canEdit ? 4 : 2);
                GuiElementGradientButton localStats = (GuiElementGradientButton) this.buttonList.get(this.canEdit ? 5 : 3);
                if (par1 > serverStats.xPosition && par1 < serverStats.xPosition + serverStats.width && par2 > serverStats.yPosition && par2 < serverStats.yPosition + serverStats.height) {
                    serverStats.displayString = GCCoreUtil.translate("gui.space_race.coming_soon");
                } else {
                    serverStats.displayString = GCCoreUtil.translate("gui.space_race.create.server_stats.name");
                }
                if (par1 > localStats.xPosition && par1 < localStats.xPosition + localStats.width && par2 > localStats.yPosition && par2 < localStats.yPosition + localStats.height) {
                    localStats.displayString = GCCoreUtil.translate("gui.space_race.coming_soon");
                } else {
                    localStats.displayString = GCCoreUtil.translate("gui.space_race.create.global_stats.name");
                }
                break;
            case ADD_PLAYER:
                this.drawCenteredString(this.fontRendererObj, GCCoreUtil.translate("gui.space_race.create.invite_player.name"), this.width / 2, this.height / 2 - this.height / 3 - 15, 16777215);
                this.drawCenteredString(this.fontRendererObj, GCCoreUtil.translate("gui.space_race.create.player_radius.name"), this.width / 2, this.height / 2 + this.height / 3 + 3, ColorUtil.to32BitColor(255, 180, 40, 40));
                break;
            case REMOVE_PLAYER:
                this.drawCenteredString(this.fontRendererObj, GCCoreUtil.translate("gui.space_race.create.remove_player.name"), this.width / 2, this.height / 2 - this.height / 3 - 15, 16777215);
                break;
            case DESIGN_FLAG:
                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                GL11.glDisable(GL11.GL_TEXTURE_2D);
                GL11.glEnable(GL11.GL_BLEND);
                GL11.glDisable(GL11.GL_ALPHA_TEST);
                OpenGlHelper.glBlendFunc(770, 771, 1, 0);
                GL11.glShadeModel(GL11.GL_SMOOTH);
                Tessellator tessellator = Tessellator.getInstance();
                WorldRenderer worldRenderer = tessellator.getWorldRenderer();
                for (int x = 0; x < this.spaceRaceData.getFlagData().getWidth(); x++) {
                    for (int y = 0; y < this.spaceRaceData.getFlagData().getHeight(); y++) {
                        Vector3 color = this.spaceRaceData.getFlagData().getColorAt(x, y);
                        GL11.glColor4f(color.floatX(), color.floatY(), color.floatZ(), 1.0F);
                        worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
                        worldRenderer.pos(this.flagDesignerMinX + x * this.flagDesignerScale.x, this.flagDesignerMinY + y * this.flagDesignerScale.y + 1 * this.flagDesignerScale.y, 0.0D).endVertex();
                        worldRenderer.pos(this.flagDesignerMinX + x * this.flagDesignerScale.x + 1 * this.flagDesignerScale.x, this.flagDesignerMinY + y * this.flagDesignerScale.y + 1 * this.flagDesignerScale.y, 0.0D).endVertex();
                        worldRenderer.pos(this.flagDesignerMinX + x * this.flagDesignerScale.x + 1 * this.flagDesignerScale.x, this.flagDesignerMinY + y * this.flagDesignerScale.y, 0.0D).endVertex();
                        worldRenderer.pos(this.flagDesignerMinX + x * this.flagDesignerScale.x, this.flagDesignerMinY + y * this.flagDesignerScale.y, 0.0D).endVertex();
                        tessellator.draw();
                    }
                }
                if (this.checkboxShowGrid != null && this.checkboxShowGrid.isSelected != null && this.checkboxShowGrid.isSelected) {
                    for (int x = 0; x <= this.spaceRaceData.getFlagData().getWidth(); x++) {
                        worldRenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
                        worldRenderer.pos(this.flagDesignerMinX + x * this.flagDesignerScale.x, this.flagDesignerMinY, this.zLevel).color(0.0F, 0.0F, 0.0F, 1.0F).endVertex();
                        worldRenderer.pos(this.flagDesignerMinX + x * this.flagDesignerScale.x, this.flagDesignerMinY + this.flagDesignerHeight, this.zLevel).color(0.0F, 0.0F, 0.0F, 1.0F).endVertex();
                        tessellator.draw();
                    }
                    for (int y = 0; y <= this.spaceRaceData.getFlagData().getHeight(); y++) {
                        worldRenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
                        worldRenderer.pos(this.flagDesignerMinX, this.flagDesignerMinY + y * this.flagDesignerScale.y, this.zLevel).color(0.0F, 0.0F, 0.0F, 1.0F).endVertex();
                        worldRenderer.pos(this.flagDesignerMinX + this.flagDesignerWidth, this.flagDesignerMinY + y * this.flagDesignerScale.y, this.zLevel).color(0.0F, 0.0F, 0.0F, 1.0F).endVertex();
                        tessellator.draw();
                    }
                }
                if (!(this.lastMousePressed && this.checkboxSelector.isSelected != null && this.checkboxSelector.isSelected) && this.selectionMaxX - this.selectionMinX > 0 && this.selectionMaxY - this.selectionMinY > 0) {
                    worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR);
                    float col = (float) (Math.sin(this.ticksPassed * 0.3) * 0.4 + 0.1);
                    worldRenderer.pos(this.flagDesignerMinX + this.selectionMinX * this.flagDesignerScale.x, this.flagDesignerMinY + this.selectionMinY * this.flagDesignerScale.y, this.zLevel).color(col, col, col, 1.0F).endVertex();
                    worldRenderer.pos(this.flagDesignerMinX + this.selectionMaxX * this.flagDesignerScale.x, this.flagDesignerMinY + this.selectionMinY * this.flagDesignerScale.y, this.zLevel).color(col, col, col, 1.0F).endVertex();
                    worldRenderer.pos(this.flagDesignerMinX + this.selectionMaxX * this.flagDesignerScale.x, this.flagDesignerMinY + this.selectionMaxY * this.flagDesignerScale.y, this.zLevel).color(col, col, col, 1.0F).endVertex();
                    worldRenderer.pos(this.flagDesignerMinX + this.selectionMinX * this.flagDesignerScale.x, this.flagDesignerMinY + this.selectionMaxY * this.flagDesignerScale.y, this.zLevel).color(col, col, col, 1.0F).endVertex();
                    worldRenderer.pos(this.flagDesignerMinX + this.selectionMinX * this.flagDesignerScale.x, this.flagDesignerMinY + this.selectionMinY * this.flagDesignerScale.y, this.zLevel).color(col, col, col, 1.0F).endVertex();
                    tessellator.draw();
                }
                int guiRight = this.width / 2 + this.width / 3;
                int guiBottom = this.height / 2 + this.height / 4;
                float x1 = this.sliderColorR.xPosition;
                float x2 = guiRight - 10;
                float y1 = guiBottom - 10 - (x2 - x1);
                float y2 = guiBottom - 10;
                worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
                worldRenderer.pos(x2, y1, this.zLevel).color(0, 0, 0, 1.0F).endVertex();
                worldRenderer.pos(x1, y1, this.zLevel).color(0, 0, 0, 1.0F).endVertex();
                worldRenderer.pos(x1, y2, this.zLevel).color(0, 0, 0, 1.0F).endVertex();
                worldRenderer.pos(x2, y2, this.zLevel).color(0, 0, 0, 1.0F).endVertex();
                tessellator.draw();
                worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
                worldRenderer.pos((double) x2 - 1, (double) y1 + 1, this.zLevel).color(this.sliderColorR.getNormalizedValue(), this.sliderColorG.getNormalizedValue(), this.sliderColorB.getNormalizedValue(), 1.0F).endVertex();
                worldRenderer.pos((double) x1 + 1, (double) y1 + 1, this.zLevel).color(this.sliderColorR.getNormalizedValue(), this.sliderColorG.getNormalizedValue(), this.sliderColorB.getNormalizedValue(), 1.0F).endVertex();
                worldRenderer.pos((double) x1 + 1, (double) y2 - 1, this.zLevel).color(this.sliderColorR.getNormalizedValue(), this.sliderColorG.getNormalizedValue(), this.sliderColorB.getNormalizedValue(), 1.0F).endVertex();
                worldRenderer.pos((double) x2 - 1, (double) y2 - 1, this.zLevel).color(this.sliderColorR.getNormalizedValue(), this.sliderColorG.getNormalizedValue(), this.sliderColorB.getNormalizedValue(), 1.0F).endVertex();
                tessellator.draw();
                GL11.glShadeModel(GL11.GL_FLAT);
                GL11.glDisable(GL11.GL_BLEND);
                GL11.glEnable(GL11.GL_ALPHA_TEST);
                GL11.glEnable(GL11.GL_TEXTURE_2D);
                break;
            case CHANGE_TEAM_COLOR:
                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                GL11.glDisable(GL11.GL_TEXTURE_2D);
                GL11.glEnable(GL11.GL_BLEND);
                GL11.glDisable(GL11.GL_ALPHA_TEST);
                OpenGlHelper.glBlendFunc(770, 771, 1, 0);
                GL11.glShadeModel(GL11.GL_SMOOTH);
                x1 = this.sliderColorG.xPosition;
                x2 = this.sliderColorG.xPosition + this.sliderColorG.getButtonWidth();
                y1 = this.height / 2 - this.height / 3 + 5;
                y2 = this.sliderColorG.yPosition - 5;
                float xDiff = x2 - x1;
                float yDiff = y2 - y1;
                if (xDiff > yDiff) {
                    x1 = this.sliderColorG.xPosition + this.sliderColorG.getButtonWidth() / 2 - yDiff / 2;
                    x2 = this.sliderColorG.xPosition + this.sliderColorG.getButtonWidth() / 2 + yDiff / 2;
                } else {
                    y2 = y1 + xDiff;
                }
                tessellator = Tessellator.getInstance();
                worldRenderer = tessellator.getWorldRenderer();
                worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
                worldRenderer.pos((double) x2 - 1, (double) y1 + 1, this.zLevel).color(this.sliderColorR.getNormalizedValue(), this.sliderColorG.getNormalizedValue(), this.sliderColorB.getNormalizedValue(), 1.0F).endVertex();
                worldRenderer.pos((double) x1 + 1, (double) y1 + 1, this.zLevel).color(this.sliderColorR.getNormalizedValue(), this.sliderColorG.getNormalizedValue(), this.sliderColorB.getNormalizedValue(), 1.0F).endVertex();
                worldRenderer.pos((double) x1 + 1, (double) y2 - 1, this.zLevel).color(this.sliderColorR.getNormalizedValue(), this.sliderColorG.getNormalizedValue(), this.sliderColorB.getNormalizedValue(), 1.0F).endVertex();
                worldRenderer.pos((double) x2 - 1, (double) y2 - 1, this.zLevel).color(this.sliderColorR.getNormalizedValue(), this.sliderColorG.getNormalizedValue(), this.sliderColorB.getNormalizedValue(), 1.0F).endVertex();
                tessellator.draw();
                this.spaceRaceData.setTeamColor(new Vector3(this.sliderColorR.getNormalizedValue(), this.sliderColorG.getNormalizedValue(), this.sliderColorB.getNormalizedValue()));
                GL11.glShadeModel(GL11.GL_FLAT);
                GL11.glDisable(GL11.GL_BLEND);
                GL11.glEnable(GL11.GL_ALPHA_TEST);
                GL11.glEnable(GL11.GL_TEXTURE_2D);
                break;
        }
    }
    super.drawScreen(par1, par2, par3);
    if (this.currentState == EnumSpaceRaceGui.ADD_PLAYER && this.gradientListAddPlayers != null) {
        this.gradientListAddPlayers.draw(par1, par2);
    }
    if (this.currentState == EnumSpaceRaceGui.REMOVE_PLAYER && this.gradientListRemovePlayers != null) {
        this.gradientListRemovePlayers.draw(par1, par2);
    }
    for (GuiButton button : this.buttonList) {
        if (button instanceof GuiElementSlider) {
            ((GuiElementSlider) button).drawHoveringText();
        }
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) GuiButton(net.minecraft.client.gui.GuiButton) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) WorldRenderer(net.minecraft.client.renderer.WorldRenderer)

Example 67 with Vector3

use of micdoodle8.mods.galacticraft.api.vector.Vector3 in project Galacticraft by micdoodle8.

the class GuiNewSpaceRace method updateScreen.

@Override
public void updateScreen() {
    super.updateScreen();
    if (this.ticksPassed % 100 == 0) {
        if (this.isDirty || this.ticksPassed == 0) {
            this.sendSpaceRaceData();
            this.isDirty = false;
        } else {
            this.updateSpaceRaceData();
        }
    }
    ++this.ticksPassed;
    for (Entry<String, Integer> e : new HashSet<Entry<String, Integer>>(this.recentlyInvited.entrySet())) {
        int timeLeft = e.getValue();
        if (--timeLeft < 0) {
            this.recentlyInvited.remove(e.getKey());
        } else {
            this.recentlyInvited.put(e.getKey(), timeLeft);
        }
    }
    if (this.currentState == EnumSpaceRaceGui.ADD_PLAYER && this.gradientListAddPlayers != null && this.ticksPassed % 20 == 0) {
        List<ListElement> playerNames = new ArrayList<ListElement>();
        for (int i = 0; i < this.thePlayer.worldObj.playerEntities.size(); i++) {
            EntityPlayer player = (EntityPlayer) this.thePlayer.worldObj.playerEntities.get(i);
            if (player.getDistanceSqToEntity(this.thePlayer) <= 25 * 25) {
                String username = PlayerUtil.getName(player);
                if (!this.spaceRaceData.getPlayerNames().contains(username)) {
                    playerNames.add(new ListElement(username, this.recentlyInvited.containsKey(username) ? ColorUtil.to32BitColor(255, 250, 120, 0) : ColorUtil.to32BitColor(255, 190, 190, 190)));
                }
            }
        }
        this.gradientListAddPlayers.updateListContents(playerNames);
        if (this.buttonList.size() >= 2) {
            ((GuiElementGradientButton) this.buttonList.get(1)).enabled = this.gradientListAddPlayers.getSelectedElement() != null;
        }
    }
    if (this.currentState == EnumSpaceRaceGui.REMOVE_PLAYER && this.gradientListRemovePlayers != null && this.ticksPassed % 20 == 0) {
        List<ListElement> playerNames = new ArrayList<ListElement>();
        for (int i = 1; i < this.spaceRaceData.getPlayerNames().size(); i++) {
            String playerName = this.spaceRaceData.getPlayerNames().get(i);
            playerNames.add(new ListElement(playerName, ColorUtil.to32BitColor(255, 190, 190, 190)));
        }
        this.gradientListRemovePlayers.updateListContents(playerNames);
        if (this.buttonList.size() >= 2) {
            ((GuiElementGradientButton) this.buttonList.get(1)).enabled = this.gradientListRemovePlayers.getSelectedElement() != null;
        }
    }
    if (this.currentState == EnumSpaceRaceGui.ADD_PLAYER && this.gradientListAddPlayers != null) {
        this.gradientListAddPlayers.update();
    }
    if (this.currentState == EnumSpaceRaceGui.REMOVE_PLAYER && this.gradientListRemovePlayers != null) {
        this.gradientListRemovePlayers.update();
    }
    if (!this.initialized) {
        return;
    }
    if (this.currentState == EnumSpaceRaceGui.DESIGN_FLAG) {
        int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
        int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
        if (this.canEdit && x >= this.flagDesignerMinX && y >= this.flagDesignerMinY && x <= this.flagDesignerMinX + this.flagDesignerWidth && y <= this.flagDesignerMinY + this.flagDesignerHeight) {
            int unScaledX = (int) Math.floor((x - this.flagDesignerMinX) / this.flagDesignerScale.x);
            int unScaledY = (int) Math.floor((y - this.flagDesignerMinY) / this.flagDesignerScale.y);
            if (Mouse.isButtonDown(0)) {
                if (this.checkboxEraser.isSelected != null && this.checkboxEraser.isSelected) {
                    this.setColorWithBrushSize(unScaledX, unScaledY, new Vector3(255, 255, 255), (int) Math.floor(this.sliderEraserSize.getNormalizedValue() * 10) + 1);
                } else if (this.checkboxColorSelector.isSelected != null && this.checkboxColorSelector.isSelected) {
                    Vector3 colorAt = this.spaceRaceData.getFlagData().getColorAt(unScaledX, unScaledY);
                    this.sliderColorR.setSliderPos(colorAt.floatX());
                    this.sliderColorG.setSliderPos(colorAt.floatY());
                    this.sliderColorB.setSliderPos(colorAt.floatZ());
                } else if (this.checkboxPaintbrush.isSelected != null && this.checkboxPaintbrush.isSelected) {
                    this.setColorWithBrushSize(unScaledX, unScaledY, new Vector3(this.sliderColorR.getColorValueD(), this.sliderColorG.getColorValueD(), this.sliderColorB.getColorValueD()), (int) Math.floor(this.sliderBrushSize.getNormalizedValue() * 10) + 1);
                }
            }
        }
        if (this.checkboxSelector != null) {
            if (!this.lastMousePressed && Mouse.isButtonDown(0) && this.checkboxSelector.isSelected != null && this.checkboxSelector.isSelected) {
                if (x >= this.flagDesignerMinX && y >= this.flagDesignerMinY && x <= this.flagDesignerMinX + this.flagDesignerWidth && y <= this.flagDesignerMinY + this.flagDesignerHeight) {
                    int unScaledX = (int) Math.floor((x - this.flagDesignerMinX) / this.flagDesignerScale.x);
                    int unScaledY = (int) Math.floor((y - this.flagDesignerMinY) / this.flagDesignerScale.y);
                    this.selectionMinX = unScaledX;
                    this.selectionMinY = unScaledY;
                } else {
                    this.selectionMinX = this.selectionMinY = -1;
                }
            } else if (this.lastMousePressed && !Mouse.isButtonDown(0) && this.checkboxSelector.isSelected != null && this.checkboxSelector.isSelected) {
                if (this.selectionMinX != -1 && this.selectionMinY != -1 && x >= this.flagDesignerMinX && y >= this.flagDesignerMinY && x <= this.flagDesignerMinX + this.flagDesignerWidth && y <= this.flagDesignerMinY + this.flagDesignerHeight) {
                    int unScaledX = (int) Math.floor((x - this.flagDesignerMinX) / this.flagDesignerScale.x);
                    int unScaledY = (int) Math.floor((y - this.flagDesignerMinY) / this.flagDesignerScale.y);
                    this.selectionMaxX = Math.min(unScaledX + 1, this.spaceRaceData.getFlagData().getWidth());
                    this.selectionMaxY = Math.min(unScaledY + 1, this.spaceRaceData.getFlagData().getHeight());
                    if (this.selectionMinX > this.selectionMaxX) {
                        int temp = this.selectionMaxX - 1;
                        this.selectionMaxX = this.selectionMinX + 1;
                        this.selectionMinX = temp;
                    }
                    if (this.selectionMinY > this.selectionMaxY) {
                        int temp = this.selectionMaxY - 1;
                        this.selectionMaxY = this.selectionMinY + 1;
                        this.selectionMinY = temp;
                    }
                } else {
                    this.selectionMaxX = this.selectionMaxY = -1;
                }
            }
        }
        if (this.sliderBrushSize != null && this.sliderBrushSize.visible) {
            this.sliderBrushSize.displayString = GCCoreUtil.translate("gui.space_race.create.brush_radius.name") + ": " + ((int) Math.floor(this.sliderBrushSize.getNormalizedValue() * 10) + 1);
        }
        if (this.sliderEraserSize != null && this.sliderEraserSize.visible) {
            this.sliderEraserSize.displayString = GCCoreUtil.translate("gui.space_race.create.eraser_radius.name") + ": " + ((int) Math.floor(this.sliderEraserSize.getNormalizedValue() * 10) + 1);
        }
        if (this.sliderColorR != null && this.sliderColorR.visible) {
            this.sliderColorR.displayString = String.valueOf((int) Math.floor(this.sliderColorR.getColorValueD()));
        }
        if (this.sliderColorG != null && this.sliderColorG.visible) {
            this.sliderColorG.displayString = String.valueOf((int) Math.floor(this.sliderColorG.getColorValueD()));
        }
        if (this.sliderColorB != null && this.sliderColorB.visible) {
            this.sliderColorB.displayString = String.valueOf((int) Math.floor(this.sliderColorB.getColorValueD()));
        }
    } else if (this.currentState == EnumSpaceRaceGui.MAIN) {
        if (this.lastMousePressed && !Mouse.isButtonDown(0)) {
            if (this.buttonFlag_hover) {
                this.currentState = EnumSpaceRaceGui.DESIGN_FLAG;
                this.initGui();
            }
            if (this.buttonTeamColor_hover) {
                this.currentState = EnumSpaceRaceGui.CHANGE_TEAM_COLOR;
                this.initGui();
            }
        }
    }
    this.lastMousePressed = Mouse.isButtonDown(0);
}
Also used : ListElement(micdoodle8.mods.galacticraft.core.client.gui.element.GuiElementGradientList.ListElement) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3)

Example 68 with Vector3

use of micdoodle8.mods.galacticraft.api.vector.Vector3 in project Galacticraft by micdoodle8.

the class WorldUtil method getFootprintPosition.

public static Vector3 getFootprintPosition(World world, float rotation, Vector3 startPosition, BlockVec3 playerCenter) {
    Vector3 position = startPosition.clone();
    float footprintScale = 0.375F;
    int mainPosX = position.intX();
    int mainPosY = position.intY();
    int mainPosZ = position.intZ();
    BlockPos posMain = new BlockPos(mainPosX, mainPosY, mainPosZ);
    // If the footprint is hovering over air...
    if (world.getBlockState(posMain).getBlock().isAir(world, posMain)) {
        position.x += (playerCenter.x - mainPosX);
        position.z += (playerCenter.z - mainPosZ);
        BlockPos pos1 = new BlockPos(position.intX(), position.intY(), position.intZ());
        // If the footprint is still over air....
        Block b2 = world.getBlockState(pos1).getBlock();
        if (b2 != null && b2.isAir(world, pos1)) {
            for (EnumFacing direction : EnumFacing.VALUES) {
                BlockPos offsetPos = posMain.offset(direction);
                if (direction != EnumFacing.DOWN && direction != EnumFacing.UP) {
                    if (!world.getBlockState(offsetPos).getBlock().isAir(world, offsetPos)) {
                        position.x += direction.getFrontOffsetX();
                        position.z += direction.getFrontOffsetZ();
                        break;
                    }
                }
            }
        }
    }
    mainPosX = position.intX();
    mainPosZ = position.intZ();
    double x0 = (Math.sin((45 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.x;
    double x1 = (Math.sin((135 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.x;
    double x2 = (Math.sin((225 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.x;
    double x3 = (Math.sin((315 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.x;
    double z0 = (Math.cos((45 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.z;
    double z1 = (Math.cos((135 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.z;
    double z2 = (Math.cos((225 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.z;
    double z3 = (Math.cos((315 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.z;
    double xMin = Math.min(Math.min(x0, x1), Math.min(x2, x3));
    double xMax = Math.max(Math.max(x0, x1), Math.max(x2, x3));
    double zMin = Math.min(Math.min(z0, z1), Math.min(z2, z3));
    double zMax = Math.max(Math.max(z0, z1), Math.max(z2, z3));
    if (xMin < mainPosX) {
        position.x += mainPosX - xMin;
    }
    if (xMax > mainPosX + 1) {
        position.x -= xMax - (mainPosX + 1);
    }
    if (zMin < mainPosZ) {
        position.z += mainPosZ - zMin;
    }
    if (zMax > mainPosZ + 1) {
        position.z -= zMax - (mainPosZ + 1);
    }
    return position;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) BlockPos(net.minecraft.util.BlockPos)

Example 69 with Vector3

use of micdoodle8.mods.galacticraft.api.vector.Vector3 in project Galacticraft by micdoodle8.

the class EntitySlimeling method spawnBabyAnimal.

public EntitySlimeling spawnBabyAnimal(EntityAgeable par1EntityAgeable) {
    if (par1EntityAgeable instanceof EntitySlimeling) {
        EntitySlimeling otherSlimeling = (EntitySlimeling) par1EntityAgeable;
        Vector3 colorParentA = new Vector3(this.getColorRed(), this.getColorGreen(), this.getColorBlue());
        Vector3 colorParentB = new Vector3(otherSlimeling.getColorRed(), otherSlimeling.getColorGreen(), otherSlimeling.getColorBlue());
        Vector3 newColor = ColorUtil.addColorsRealistically(colorParentA, colorParentB);
        newColor.x = Math.max(Math.min(newColor.x, 1.0F), 0);
        newColor.y = Math.max(Math.min(newColor.y, 1.0F), 0);
        newColor.z = Math.max(Math.min(newColor.z, 1.0F), 0);
        EntitySlimeling newSlimeling = new EntitySlimeling(this.worldObj, (float) newColor.x, (float) newColor.y, (float) newColor.z);
        String s = this.getOwnerId();
        if (s != null && s.trim().length() > 0) {
            newSlimeling.setOwnerId(s);
            newSlimeling.setTamed(true);
        }
        return newSlimeling;
    }
    return null;
}
Also used : Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3)

Example 70 with Vector3

use of micdoodle8.mods.galacticraft.api.vector.Vector3 in project Galacticraft by micdoodle8.

the class TeleportTypeMars method getPlayerSpawnLocation.

@Override
public Vector3 getPlayerSpawnLocation(WorldServer world, EntityPlayerMP player) {
    if (player != null) {
        GCPlayerStats stats = GCPlayerStats.get(player);
        double x = stats.getCoordsTeleportedFromX();
        double z = stats.getCoordsTeleportedFromZ();
        int limit = ConfigManagerCore.otherPlanetWorldBorders - 2;
        if (limit > 20) {
            if (x > limit) {
                z *= limit / x;
                x = limit;
            } else if (x < -limit) {
                z *= -limit / x;
                x = -limit;
            }
            if (z > limit) {
                x *= limit / z;
                z = limit;
            } else if (z < -limit) {
                x *= -limit / z;
                z = -limit;
            }
        }
        return new Vector3(x, ConfigManagerCore.disableLander ? 250.0 : 900.0, z);
    }
    return null;
}
Also used : GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3)

Aggregations

Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)74 BlockPos (net.minecraft.util.BlockPos)13 Entity (net.minecraft.entity.Entity)12 TileEntity (net.minecraft.tileentity.TileEntity)11 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)8 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)6 IBlockState (net.minecraft.block.state.IBlockState)6 EntityLivingBase (net.minecraft.entity.EntityLivingBase)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 ItemStack (net.minecraft.item.ItemStack)6 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)4 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)4 FlagData (micdoodle8.mods.galacticraft.core.wrappers.FlagData)4 WorldServer (net.minecraft.world.WorldServer)4 GameProfile (com.mojang.authlib.GameProfile)3