Search in sources :

Example 16 with WorldProvider

use of net.minecraft.world.WorldProvider in project Galacticraft by micdoodle8.

the class FreefallHandler method testFreefall.

@SideOnly(Side.CLIENT)
private boolean testFreefall(EntityPlayerSP p, boolean flag) {
    World world = p.worldObj;
    WorldProvider worldProvider = world.provider;
    if (!(worldProvider instanceof IZeroGDimension)) {
        return false;
    }
    ZeroGravityEvent zeroGEvent = new ZeroGravityEvent.InFreefall(p);
    MinecraftForge.EVENT_BUS.post(zeroGEvent);
    if (zeroGEvent.isCanceled()) {
        return false;
    }
    if (this.pjumpticks > 0 || (stats.isSsOnGroundLast() && p.movementInput.jump)) {
        return false;
    }
    if (p.ridingEntity != null) {
        Entity e = p.ridingEntity;
        if (e instanceof EntitySpaceshipBase) {
            return ((EntitySpaceshipBase) e).getLaunched();
        }
        if (e instanceof EntityLanderBase) {
            return false;
        }
    // TODO: should check whether lander has landed (whatever that means)
    // TODO: could check other ridden entities - every entity should have its own freefall check :(
    }
    // This is an "on the ground" check
    if (!flag) {
        return false;
    } else {
        float rY = p.rotationYaw % 360F;
        double zreach = 0D;
        double xreach = 0D;
        if (rY < 80F || rY > 280F) {
            zreach = 0.2D;
        }
        if (rY < 170F && rY > 10F) {
            xreach = 0.2D;
        }
        if (rY < 260F && rY > 100F) {
            zreach = -0.2D;
        }
        if (rY < 350F && rY > 190F) {
            xreach = -0.2D;
        }
        AxisAlignedBB playerReach = p.getEntityBoundingBox().addCoord(xreach, 0, zreach);
        boolean checkBlockWithinReach;
        if (worldProvider instanceof WorldProviderSpaceStation) {
            SpinManager spinManager = ((WorldProviderSpaceStation) worldProvider).getSpinManager();
            checkBlockWithinReach = playerReach.maxX >= spinManager.ssBoundsMinX && playerReach.minX <= spinManager.ssBoundsMaxX && playerReach.maxY >= spinManager.ssBoundsMinY && playerReach.minY <= spinManager.ssBoundsMaxY && playerReach.maxZ >= spinManager.ssBoundsMinZ && playerReach.minZ <= spinManager.ssBoundsMaxZ;
        // Player is somewhere within the space station boundaries
        } else {
            checkBlockWithinReach = true;
        }
        if (checkBlockWithinReach) {
            // Check if the player's bounding box is in the same block coordinates as any non-vacuum block (including torches etc)
            // If so, it's assumed the player has something close enough to grab onto, so is not in freefall
            // Note: breatheable air here means the player is definitely not in freefall
            int xm = MathHelper.floor_double(playerReach.minX);
            int xx = MathHelper.floor_double(playerReach.maxX);
            int ym = MathHelper.floor_double(playerReach.minY);
            int yy = MathHelper.floor_double(playerReach.maxY);
            int zm = MathHelper.floor_double(playerReach.minZ);
            int zz = MathHelper.floor_double(playerReach.maxZ);
            for (int x = xm; x <= xx; x++) {
                for (int y = ym; y <= yy; y++) {
                    for (int z = zm; z <= zz; z++) {
                        // Blocks.air is hard vacuum - we want to check for that, here
                        Block b = world.getBlockState(new BlockPos(x, y, z)).getBlock();
                        if (Blocks.air != b && GCBlocks.brightAir != b) {
                            this.onWall = true;
                            return false;
                        }
                    }
                }
            }
        }
    }
    /*
        if (freefall)
        {
            //If that check didn't produce a result, see if the player is inside the walls
            //TODO: could apply special weightless movement here like Coriolis force - the player is inside the walls,  not touching them, and in a vacuum
            int quadrant = 0;
            double xd = p.posX - this.spinCentreX;
            double zd = p.posZ - this.spinCentreZ;
            if (xd<0)
            {
                if (xd<-Math.abs(zd))
                {
                    quadrant = 2;
                } else
                    quadrant = (zd<0) ? 3 : 1;
            } else
                if (xd>Math.abs(zd))
                {
                    quadrant = 0;
                } else
                    quadrant = (zd<0) ? 3 : 1;

            int ymin = MathHelper.floor_double(p.boundingBox.minY)-1;
            int ymax = MathHelper.floor_double(p.boundingBox.maxY);
            int xmin, xmax, zmin, zmax;

            switch (quadrant)
            {
            case 0:
                xmin = MathHelper.floor_double(p.boundingBox.maxX);
                xmax = this.ssBoundsMaxX - 1;
                zmin = MathHelper.floor_double(p.boundingBox.minZ)-1;
                zmax = MathHelper.floor_double(p.boundingBox.maxZ)+1;
                break;
            case 1:
                xmin = MathHelper.floor_double(p.boundingBox.minX)-1;
                xmax = MathHelper.floor_double(p.boundingBox.maxX)+1;
                zmin = MathHelper.floor_double(p.boundingBox.maxZ);
                zmax = this.ssBoundsMaxZ - 1;
                break;
            case 2:
                zmin = MathHelper.floor_double(p.boundingBox.minZ)-1;
                zmax = MathHelper.floor_double(p.boundingBox.maxZ)+1;
                xmin = this.ssBoundsMinX;
                xmax = MathHelper.floor_double(p.boundingBox.minX);
                break;
            case 3:
            default:
                xmin = MathHelper.floor_double(p.boundingBox.minX)-1;
                xmax = MathHelper.floor_double(p.boundingBox.maxX)+1;
                zmin = this.ssBoundsMinZ;
                zmax = MathHelper.floor_double(p.boundingBox.minZ);
                break;
            }

            //This block search could cost a lot of CPU (but client side) - maybe optimise later
            BLOCKCHECK0:
            for(int x = xmin; x <= xmax; x++)
                for (int z = zmin; z <= zmax; z++)
                    for (int y = ymin; y <= ymax; y++)
                        if (Blocks.air != this.worldProvider.worldObj.getBlock(x, y, z))
                        {
                            freefall = false;
                            break BLOCKCHECK0;
                        }
        }*/
    this.onWall = false;
    return true;
}
Also used : ZeroGravityEvent(micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent) EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) SpinManager(micdoodle8.mods.galacticraft.core.dimension.SpinManager) EntityLanderBase(micdoodle8.mods.galacticraft.core.entities.EntityLanderBase) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) WorldProvider(net.minecraft.world.WorldProvider) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.BlockPos) IZeroGDimension(micdoodle8.mods.galacticraft.api.world.IZeroGDimension) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 17 with WorldProvider

use of net.minecraft.world.WorldProvider in project DynamicSurroundings by OreCruncher.

the class RenderWeather method onWorldLoad.

/**
 * Hook the weather renderer for the loading world.
 */
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onWorldLoad(@Nonnull final WorldEvent.Load e) {
    if (DSurround.proxy().effectiveSide() == Side.SERVER || !ModOptions.asm.enableWeatherASM)
        return;
    // Only want to hook if the provider doesn't have special
    // weather handling.
    final WorldProvider provider = e.getWorld().provider;
    final String dimName = provider.getDimensionType().getName();
    final IRenderHandler renderer = provider.getWeatherRenderer();
    if (renderer == null) {
        DSurround.log().info("Setting weather renderer for dimension [%s]", dimName);
        provider.setWeatherRenderer(new RenderWeather());
    } else {
        DSurround.log().info("Not hooking weather renderer for dimension [%s] (%s)", dimName, renderer.getClass());
    }
}
Also used : IRenderHandler(net.minecraftforge.client.IRenderHandler) WorldProvider(net.minecraft.world.WorldProvider) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 18 with WorldProvider

use of net.minecraft.world.WorldProvider in project MorePlanets by SteveKunG.

the class GuiCelestialSelection method drawScreen.

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    List<String> infoList = new LinkedList<>();
    if (this.selectionList != null) {
        this.selectionList.drawScreen(mouseX, mouseY, partialTicks);
        this.drawCenteredString(this.fontRenderer, "Select Celestial", this.width / 2, 12, 16777215);
        this.drawCenteredString(this.fontRenderer, LangUtils.translate("fml.menu.mods.search"), this.width / 2 - 173, this.height - 21, 16777215);
        for (int i = 0; i < this.selectionList.getSize(); ++i) {
            if (this.selectionList.isSelected(i)) {
                CelestialBody celestial = this.selectionList.getSelectedCelestial().getCelestialBody();
                infoList.add(ColorUtils.stringToRGB("149, 200, 237").toColoredFont() + "Basic Information:");
                try {
                    if (celestial.getDimensionID() != -1) {
                        WorldProvider provider = WorldUtil.getProviderForDimensionClient(celestial.getDimensionID());
                        if (provider instanceof WorldProviderSpace) {
                            WorldProviderSpace space = (WorldProviderSpace) provider;
                            String thermal = "";
                            try {
                                thermal = String.valueOf(String.format("%.2f", 1.8F * space.getThermalLevelModifier() * 32)) + "\u2103";
                            } catch (Exception e) {
                                thermal = TextFormatting.RED + "Unknown";
                            }
                            if (space.getDayLength() <= 0) {
                                infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Day-night Cycle:", "No day-night cycle"));
                            } else {
                                double dayDouble = space.getDayLength() / 24000;
                                if (dayDouble % 1 == 0) {
                                    int dayInt = (int) (space.getDayLength() / 24000);
                                    infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Day-night Cycle:", dayInt + (dayInt == 1 ? " Day" : " Days") + " / " + dayInt * 24 + " hours"));
                                } else {
                                    infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Day-night Cycle:", dayDouble + (dayDouble <= 1 ? " Day" : " Days") + " / " + dayDouble * 24 + " hours"));
                                }
                            }
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Gravity:", String.valueOf(space.getGravity()) + "g"));
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Wind:", String.valueOf(String.format("%.1f", space.getWindLevel() * 100.0F)) + "%"));
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Thermal:", thermal));
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Breathable Atmosphere:", space.hasBreathableAtmosphere()));
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Corrode Armor:", space.shouldCorrodeArmor()));
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Sound Reduction:", String.valueOf(space.getSoundVolReductionAmount() / 1.0F) + "%"));
                        }
                        if (provider instanceof ISolarLevel) {
                            ISolarLevel solar = (ISolarLevel) provider;
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Solar Level:", String.valueOf(String.format("%.1f", solar.getSolarEnergyMultiplier() * 100.0D)) + "%"));
                        }
                        if (provider instanceof IDarkEnergyProvider) {
                            IDarkEnergyProvider space = (IDarkEnergyProvider) provider;
                            String darkEnergy = "";
                            try {
                                darkEnergy = String.valueOf(space.getDarkEnergyMultiplier(null, null)) + "%";
                            } catch (Exception e) {
                                darkEnergy = TextFormatting.RED + "Unstable Dark Energy";
                            }
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Dark Energy Level:", darkEnergy));
                        }
                        if (celestial instanceof Planet) {
                            Planet planet = (Planet) celestial;
                            if (!planet.atmosphere.composition.isEmpty()) {
                                infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Gas:", String.valueOf(planet.atmosphere.composition)));
                            }
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Solar System:", planet.getParentSolarSystem().getLocalizedName()));
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Galaxy:", planet.getParentSolarSystem().getLocalizedParentGalaxyName()));
                            if (!GalaxyRegistry.getMoonsForPlanet(planet).isEmpty()) {
                                infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Number of Moons:", String.valueOf(GalaxyRegistry.getMoonsForPlanet(planet).size())));
                            }
                        } else if (celestial instanceof Moon) {
                            Moon moon = (Moon) celestial;
                            if (!moon.atmosphere.composition.isEmpty()) {
                                infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Gas:", String.valueOf(moon.atmosphere.composition)));
                            }
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Solar System:", moon.getParentPlanet().getParentSolarSystem().getLocalizedName()));
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Galaxy:", moon.getParentPlanet().getParentSolarSystem().getLocalizedParentGalaxyName()));
                            infoList.add(this.format(ColorUtils.stringToRGB("135, 242, 230").toColoredFont() + "Parent Planet:", moon.getParentPlanet().getLocalizedName()));
                        }
                    } else {
                        infoList.add(TextFormatting.RED + "No Basic Celestial Info");
                    }
                } catch (Exception e) {
                }
                for (int textSize = 0; textSize < infoList.size(); textSize++) {
                    String text = infoList.get(textSize);
                    int fontHeight = this.fontRenderer.FONT_HEIGHT + 2;
                    int y = 54 + fontHeight * textSize;
                    this.fontRenderer.drawString(text, this.width / 2 - 24, y, 16777215);
                }
            }
        }
    }
    this.searchField.drawTextBox();
    super.drawScreen(mouseX, mouseY, partialTicks);
}
Also used : Moon(micdoodle8.mods.galacticraft.api.galaxies.Moon) LinkedList(java.util.LinkedList) IOException(java.io.IOException) CelestialBody(micdoodle8.mods.galacticraft.api.galaxies.CelestialBody) WorldProvider(net.minecraft.world.WorldProvider) ISolarLevel(micdoodle8.mods.galacticraft.api.world.ISolarLevel) IDarkEnergyProvider(stevekung.mods.moreplanets.utils.dimension.IDarkEnergyProvider) Planet(micdoodle8.mods.galacticraft.api.galaxies.Planet) WorldProviderSpace(micdoodle8.mods.galacticraft.api.prefab.world.gen.WorldProviderSpace)

Example 19 with WorldProvider

use of net.minecraft.world.WorldProvider in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onReplaceBiomeBlocks.

@SubscribeEvent
public void onReplaceBiomeBlocks(ChunkGeneratorEvent.ReplaceBiomeBlocks event) {
    World world = event.getWorld();
    if (world == null) {
        return;
    }
    WorldProvider provider = world.provider;
    if (!(provider instanceof GenericWorldProvider))
        return;
    DimensionInformation information = ((GenericWorldProvider) provider).getDimensionInformation();
    if (information.hasFeatureType(FeatureType.FEATURE_CLEAN)) {
        event.setResult(Event.Result.DENY);
    }
}
Also used : GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) WorldProvider(net.minecraft.world.WorldProvider) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 20 with WorldProvider

use of net.minecraft.world.WorldProvider in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onPlayerRightClickEvent.

@SubscribeEvent
public void onPlayerRightClickEvent(PlayerInteractEvent.RightClickBlock event) {
    World world = event.getWorld();
    if (world.isRemote)
        return;
    BlockPos pos = event.getPos();
    WorldProvider provider = world.provider;
    if (!(world.getBlockState(pos).getBlock() instanceof BlockBed && provider instanceof GenericWorldProvider))
        return;
    // We are in an RFTools dimension.
    switch(GeneralConfiguration.bedBehaviour) {
        case 0:
            event.setCanceled(true);
            Logging.message(event.getEntityPlayer(), "You cannot sleep in this dimension!");
            break;
        // In case 1, just do the usual thing (this typically mean explosion).
        case 2:
            event.setCanceled(true);
            event.getEntityPlayer().setSpawnChunk(pos, true, provider.getDimension());
            Logging.message(event.getEntityPlayer(), "Spawn point set!");
    }
}
Also used : GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) WorldProvider(net.minecraft.world.WorldProvider) BlockBed(net.minecraft.block.BlockBed) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

WorldProvider (net.minecraft.world.WorldProvider)30 WorldServer (net.minecraft.world.WorldServer)7 World (net.minecraft.world.World)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)4 IOException (java.io.IOException)3 GenericWorldProvider (mcjty.rftoolsdim.dimensions.world.GenericWorldProvider)3 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)3 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)3 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)3 Entity (net.minecraft.entity.Entity)3 BlockPos (net.minecraft.util.math.BlockPos)3 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)3 Path (java.nio.file.Path)2 LinkedList (java.util.LinkedList)2 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)2 ZeroGravityEvent (micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent)2 CelestialBody (micdoodle8.mods.galacticraft.api.galaxies.CelestialBody)2 WorldProviderSpace (micdoodle8.mods.galacticraft.api.prefab.world.gen.WorldProviderSpace)2 IZeroGDimension (micdoodle8.mods.galacticraft.api.world.IZeroGDimension)2