diff --git a/src/api/java/elucent/albedo/lighting/ILightProvider.java b/src/api/java/elucent/albedo/lighting/ILightProvider.java new file mode 100644 index 000000000..3d57592d5 --- /dev/null +++ b/src/api/java/elucent/albedo/lighting/ILightProvider.java @@ -0,0 +1,36 @@ +/* + * The MIT License + * + * Copyright (c) 2017 Elucent, William Thompson (unascribed), and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package elucent.albedo.lighting; + +import javax.annotation.Nullable; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface ILightProvider { + @SideOnly(Side.CLIENT) + @Nullable + public Light provideLight(); +} \ No newline at end of file diff --git a/src/api/java/elucent/albedo/lighting/Light.java b/src/api/java/elucent/albedo/lighting/Light.java new file mode 100644 index 000000000..116da7396 --- /dev/null +++ b/src/api/java/elucent/albedo/lighting/Light.java @@ -0,0 +1,136 @@ +/* + * The MIT License + * + * Copyright (c) 2017 Elucent, William Thompson (unascribed), and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package elucent.albedo.lighting; + +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; + +public class Light { + + public float x; + public float y; + public float z; + + public float r; + public float g; + public float b; + public float a; + + public float radius; + + @Deprecated + public Light(float x, float y, float z, float r, float g, float b, float a, float radius) { + this.x = x; + this.y = y; + this.z = z; + this.r = r; + this.g = g; + this.b = b; + this.a = a; + this.radius = radius; + } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + private float x = Float.NaN; + private float y = Float.NaN; + private float z = Float.NaN; + + private float r = Float.NaN; + private float g = Float.NaN; + private float b = Float.NaN; + private float a = Float.NaN; + + private float radius = Float.NaN; + + + public Builder pos(BlockPos pos) { + return pos(pos.getX()+0.5f, pos.getY()+0.5f, pos.getZ()+0.5f); + } + + public Builder pos(Vec3d pos) { + return pos(pos.x, pos.y, pos.z); + } + + public Builder pos(Entity e) { + return pos(e.posX, e.posY, e.posZ); + } + + public Builder pos(double x, double y, double z) { + return pos((float)x, (float)y, (float)z); + } + + public Builder pos(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + return this; + } + + + public Builder color(int c, boolean hasAlpha) { + return color(extract(c, 2), extract(c, 1), extract(c, 0), hasAlpha ? extract(c, 3) : 1); + } + + private float extract(int i, int idx) { + return ((i >> (idx*8)) & 0xFF)/255f; + } + + public Builder color(float r, float g, float b) { + return color(r, g, b, 1); + } + + public Builder color(float r, float g, float b, float a) { + this.r = r; + this.g = g; + this.b = b; + this.a = a; + return this; + } + + + public Builder radius(float radius) { + this.radius = radius; + return this; + } + + + public Light build() { + if (Float.isFinite(x) && Float.isFinite(y) && Float.isFinite(z) && + Float.isFinite(r) && Float.isFinite(g) && Float.isFinite(b) && Float.isFinite(a) && + Float.isFinite(radius)) { + return new Light(x, y, z, r, g, b, a, radius); + } else { + throw new IllegalArgumentException("Position, color, and radius must be set, and cannot be infinite"); + } + } + + } + +} \ No newline at end of file diff --git a/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java b/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java index 6f0abe72f..f02b06d87 100644 --- a/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java +++ b/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java @@ -13,6 +13,8 @@ package vazkii.botania.client.core.helper; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.resources.SimpleReloadableResourceManager; +import net.minecraftforge.fml.common.Loader; + import org.lwjgl.opengl.ARBFragmentShader; import org.lwjgl.opengl.ARBShaderObjects; import org.lwjgl.opengl.ARBVertexShader; @@ -44,6 +46,9 @@ public final class ShaderHelper { public static int gold = 0; public static int categoryButton = 0; public static int alpha = 0; + + private static boolean hasIncompatibleMods = false; + private static boolean checkedIncompatibility = false; private static void deleteShader(int id) { if (id != 0) { @@ -112,7 +117,16 @@ public final class ShaderHelper { } public static boolean useShaders() { - return ConfigHandler.useShaders && OpenGlHelper.shadersSupported; + return ConfigHandler.useShaders && OpenGlHelper.shadersSupported && checkIncompatibleMods(); + } + + private static boolean checkIncompatibleMods() { + if(!checkedIncompatibility) { + hasIncompatibleMods = Loader.isModLoaded("albedo") || Loader.isModLoaded("optifine"); + checkedIncompatibility = true; + } + + return !hasIncompatibleMods; } // Most of the code taken from the LWJGL wiki diff --git a/src/main/java/vazkii/botania/common/block/tile/TileLightRelay.java b/src/main/java/vazkii/botania/common/block/tile/TileLightRelay.java index 5fbf24512..7433cc94b 100644 --- a/src/main/java/vazkii/botania/common/block/tile/TileLightRelay.java +++ b/src/main/java/vazkii/botania/common/block/tile/TileLightRelay.java @@ -10,6 +10,14 @@ */ package vazkii.botania.common.block.tile; +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Nonnull; + +import elucent.albedo.lighting.ILightProvider; +import elucent.albedo.lighting.Light; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; @@ -28,7 +36,9 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import net.minecraftforge.fml.common.Optional; import vazkii.botania.api.state.BotaniaStateProps; import vazkii.botania.api.state.enums.LuminizerVariant; import vazkii.botania.api.wand.IWandBindable; @@ -39,11 +49,6 @@ import vazkii.botania.common.core.helper.PlayerHelper; import vazkii.botania.common.core.helper.Vector3; import vazkii.botania.common.lib.LibMisc; -import javax.annotation.Nonnull; -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; - public class TileLightRelay extends TileMod implements IWandBindable { private static final int MAX_DIST = 20; @@ -229,7 +234,8 @@ public class TileLightRelay extends TileMod implements IWandBindable { cmp.setInteger(TAG_BIND_Z, bindPos.getZ()); } - public static class EntityPlayerMover extends Entity { + @Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo") + public static class EntityPlayerMover extends Entity implements ILightProvider { private static final String TAG_EXIT_X = "exitX"; private static final String TAG_EXIT_Y = "exitY"; @@ -347,6 +353,17 @@ public class TileLightRelay extends TileMod implements IWandBindable { dataManager.set(EXIT_POS, pos); } + @Override + @Optional.Method(modid="albedo") + public Light provideLight() { + if(getPassengers().isEmpty()) + return null; + + Entity passenger = getPassengers().get(0); + Color color = Color.getHSBColor(passenger.ticksExisted / 36F, 1F, 1F); + return Light.builder().pos(this).color(color.getRGB(), false).radius(5).build(); + } + } } diff --git a/src/main/java/vazkii/botania/common/entity/EntityBabylonWeapon.java b/src/main/java/vazkii/botania/common/entity/EntityBabylonWeapon.java index 51c751cc5..6dab52675 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityBabylonWeapon.java +++ b/src/main/java/vazkii/botania/common/entity/EntityBabylonWeapon.java @@ -21,7 +21,9 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import net.minecraftforge.fml.common.Optional; import vazkii.botania.common.Botania; import vazkii.botania.common.core.handler.ModSounds; import vazkii.botania.common.core.helper.PlayerHelper; @@ -31,9 +33,14 @@ import vazkii.botania.common.item.equipment.tool.ToolCommons; import vazkii.botania.common.item.relic.ItemKingKey; import javax.annotation.Nonnull; + +import elucent.albedo.lighting.ILightProvider; +import elucent.albedo.lighting.Light; + import java.util.List; -public class EntityBabylonWeapon extends EntityThrowableCopy { +@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo") +public class EntityBabylonWeapon extends EntityThrowableCopy implements ILightProvider { private static final String TAG_CHARGING = "charging"; private static final String TAG_VARIETY = "variety"; @@ -195,6 +202,12 @@ public class EntityBabylonWeapon extends EntityThrowableCopy { setRotation(cmp.getFloat(TAG_ROTATION)); } + @Override + @Optional.Method(modid="albedo") + public Light provideLight() { + return Light.builder().pos(this).color(1F, 1F, 0F).radius(8).build(); + } + public boolean isCharging() { return dataManager.get(CHARGING); } diff --git a/src/main/java/vazkii/botania/common/entity/EntityFallingStar.java b/src/main/java/vazkii/botania/common/entity/EntityFallingStar.java index 024044cb2..7bd5860a9 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityFallingStar.java +++ b/src/main/java/vazkii/botania/common/entity/EntityFallingStar.java @@ -18,12 +18,17 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; +import net.minecraftforge.fml.common.Optional; import vazkii.botania.common.Botania; import vazkii.botania.common.core.handler.ConfigHandler; import java.util.List; -public class EntityFallingStar extends EntityThrowableCopy { +import elucent.albedo.lighting.ILightProvider; +import elucent.albedo.lighting.Light; + +@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo") +public class EntityFallingStar extends EntityThrowableCopy implements ILightProvider { public EntityFallingStar(World world) { super(world); @@ -86,6 +91,12 @@ public class EntityFallingStar extends EntityThrowableCopy { setDead(); } + + @Override + @Optional.Method(modid="albedo") + public Light provideLight() { + return Light.builder().pos(this).color(1F, 0F, 1F).radius(12).build(); + } } diff --git a/src/main/java/vazkii/botania/common/entity/EntityFlameRing.java b/src/main/java/vazkii/botania/common/entity/EntityFlameRing.java index 6ccc27fb5..bc7bbd22e 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityFlameRing.java +++ b/src/main/java/vazkii/botania/common/entity/EntityFlameRing.java @@ -10,7 +10,6 @@ */ package vazkii.botania.common.entity; - import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.SoundEvents; @@ -19,14 +18,19 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.World; +import net.minecraftforge.fml.common.Optional; import vazkii.botania.common.Botania; import vazkii.botania.common.core.helper.MathHelper; import javax.annotation.Nonnull; + +import elucent.albedo.lighting.ILightProvider; +import elucent.albedo.lighting.Light; + import java.util.List; - -public class EntityFlameRing extends Entity { +@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo") +public class EntityFlameRing extends Entity implements ILightProvider { public EntityFlameRing(World world) { super(world); @@ -96,10 +100,15 @@ public class EntityFlameRing extends Entity { return false; } - @Override protected void readEntityFromNBT(@Nonnull NBTTagCompound var1) {} @Override protected void writeEntityToNBT(@Nonnull NBTTagCompound var1) {} + + @Override + @Optional.Method(modid="albedo") + public Light provideLight() { + return Light.builder().pos(this).color(1F, 0.5F, 0F).radius(20).build(); + } } \ No newline at end of file diff --git a/src/main/java/vazkii/botania/common/entity/EntityMagicLandmine.java b/src/main/java/vazkii/botania/common/entity/EntityMagicLandmine.java index 0ccaf80d1..bf9b2190c 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityMagicLandmine.java +++ b/src/main/java/vazkii/botania/common/entity/EntityMagicLandmine.java @@ -19,13 +19,19 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.World; +import net.minecraftforge.fml.common.Optional; import vazkii.botania.common.Botania; import vazkii.botania.common.core.handler.ModSounds; import javax.annotation.Nonnull; + +import elucent.albedo.lighting.ILightProvider; +import elucent.albedo.lighting.Light; + import java.util.List; -public class EntityMagicLandmine extends Entity { +@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo") +public class EntityMagicLandmine extends Entity implements ILightProvider { public EntityDoppleganger summoner; @@ -86,4 +92,10 @@ public class EntityMagicLandmine extends Entity { protected void writeEntityToNBT(@Nonnull NBTTagCompound var1) { } + @Override + @Optional.Method(modid="albedo") + public Light provideLight() { + return Light.builder().pos(this).color(0.6F, 0F, 1F).radius(15).build(); + } + } diff --git a/src/main/java/vazkii/botania/common/entity/EntityManaBurst.java b/src/main/java/vazkii/botania/common/entity/EntityManaBurst.java index 3b887fde9..ce0736b72 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityManaBurst.java +++ b/src/main/java/vazkii/botania/common/entity/EntityManaBurst.java @@ -10,6 +10,19 @@ */ package vazkii.botania.common.entity; +import java.awt.Color; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Random; +import java.util.Set; +import java.util.UUID; + +import javax.annotation.Nonnull; + +import elucent.albedo.lighting.ILightProvider; +import elucent.albedo.lighting.Light; import net.minecraft.block.Block; import net.minecraft.block.BlockBush; import net.minecraft.block.BlockLeaves; @@ -31,6 +44,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import net.minecraftforge.fml.common.Optional; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import vazkii.botania.api.BotaniaAPI; @@ -50,17 +64,8 @@ import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.core.helper.Vector3; import vazkii.botania.common.item.equipment.bauble.ItemTinyPlanet; -import javax.annotation.Nonnull; -import java.awt.Color; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Random; -import java.util.Set; -import java.util.UUID; - -public class EntityManaBurst extends EntityThrowable implements IManaBurst { +@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo") +public class EntityManaBurst extends EntityThrowable implements IManaBurst, ILightProvider { private static final String TAG_TICKS_EXISTED = "ticksExisted"; private static final String TAG_COLOR = "color"; @@ -453,10 +458,7 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { float r = color.getRed() / 255F; float g = color.getGreen() / 255F; float b = color.getBlue() / 255F; - - int mana = getMana(); - int maxMana = getStartingMana(); - float osize = (float) mana / (float) maxMana; + float osize = getParticleSize(); float size = osize; if(fake) { @@ -522,6 +524,10 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { Botania.proxy.setWispFXDepthTest(true); } } + + public float getParticleSize() { + return (float) getMana() / (float) getStartingMana(); + } @Override protected void onImpact(@Nonnull RayTraceResult rtr) { @@ -799,6 +805,13 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst { if(tile != null && tile instanceof IManaSpreader) ((IManaSpreader) tile).setLastBurstDeathTick(getTicksExisted()); } + + @Override + @Optional.Method(modid="albedo") + public Light provideLight() { + int color = getColor(); + return Light.builder().pos(new Vec3d(posX - motionX, posY - motionY, posZ - motionZ)).color(color, false).radius(getParticleSize() * 8).build(); + } public static class PositionProperties { diff --git a/src/main/java/vazkii/botania/common/entity/EntityPixie.java b/src/main/java/vazkii/botania/common/entity/EntityPixie.java index 79c6b43ef..9cd0d4b33 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityPixie.java +++ b/src/main/java/vazkii/botania/common/entity/EntityPixie.java @@ -20,11 +20,16 @@ import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; import net.minecraft.world.World; +import net.minecraftforge.fml.common.Optional; import vazkii.botania.common.Botania; import javax.annotation.Nonnull; -public class EntityPixie extends EntityFlying { +import elucent.albedo.lighting.ILightProvider; +import elucent.albedo.lighting.Light; + +@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo") +public class EntityPixie extends EntityFlying implements ILightProvider { private static final DataParameter TYPE = EntityDataManager.createKey(EntityPixie.class, DataSerializers.VARINT); @@ -141,4 +146,13 @@ public class EntityPixie extends EntityFlying { return false; } + @Override + @Optional.Method(modid="albedo") + public Light provideLight() { + if(getType() == 1) + return null; + + return Light.builder().pos(this).color(1F, 0F, 0.5F).radius(8).build(); + } + } \ No newline at end of file