Migrate Albedo compat to caps, fixing NPEs on null lights on new Albedo

Fixes #2920, fixes #3040
This commit is contained in:
Hubry committed 2019-12-08 17:16:51 +01:00
1 parent 6666cf1e23
commit 050d11a547
15 files changed
+117 -239

No files matched your search

+1
View File
@@ -92,6 +92,7 @@ dependencies {
deobfCompile "com.azanor.baubles:Baubles:1.12-1.5.2"
deobfCompile "mezz.jei:jei_1.12.2:4.13.1.220"
deobfCompile "thaumcraft:Thaumcraft:1.12.2:6.1.BETA26"
compileOnly "albedo:albedo:1.12.2:1.1.0"
//and a bit more for SCP
sshAntTask "org.apache.ant:ant-jsch:1.7.1", "jsch:jsch:0.1.29"
@@ -1,36 +0,0 @@
/*
* 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();
}
@@ -1,136 +0,0 @@
/*
* 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");
}
}
}
}
@@ -32,6 +32,7 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@@ -63,6 +64,7 @@ import vazkii.botania.client.fx.FXWisp;
import vazkii.botania.client.gui.lexicon.GuiLexicon;
import vazkii.botania.client.gui.lexicon.GuiLexiconEntry;
import vazkii.botania.client.gui.lexicon.GuiLexiconIndex;
import vazkii.botania.client.integration.albedo.AlbedoCompat;
import vazkii.botania.client.render.entity.LayerGaiaHead;
import vazkii.botania.client.render.entity.RenderBabylonWeapon;
import vazkii.botania.client.render.entity.RenderCorporeaSpark;
@@ -175,6 +177,10 @@ public class ClientProxy implements IProxy {
dootDoot = true;
}
if (Loader.isModLoaded("albedo") && ConfigHandler.enableAlbedo) {
MinecraftForge.EVENT_BUS.register(AlbedoCompat.class);
}
TileEntityItemStackRenderer.instance = new RenderTilePylon.ForwardingTEISR(TileEntityItemStackRenderer.instance);
ClientRegistry.registerKeyBinding(ClientProxy.CORPOREA_REQUEST);
@@ -0,0 +1,97 @@
package vazkii.botania.client.integration.albedo;
import elucent.albedo.event.GatherLightsEvent;
import elucent.albedo.lighting.ILightProvider;
import elucent.albedo.lighting.Light;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import vazkii.botania.common.block.tile.TileLightRelay;
import vazkii.botania.common.entity.EntityBabylonWeapon;
import vazkii.botania.common.entity.EntityFallingStar;
import vazkii.botania.common.entity.EntityFlameRing;
import vazkii.botania.common.entity.EntityMagicLandmine;
import vazkii.botania.common.entity.EntityManaBurst;
import vazkii.botania.common.entity.EntityPixie;
import vazkii.botania.common.lib.LibMisc;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.awt.Color;
import java.util.function.Function;
public class AlbedoCompat {
private static ResourceLocation CAP_NAME = new ResourceLocation(LibMisc.MOD_ID, "albedo_light");
@CapabilityInject(ILightProvider.class)
private static final Capability<ILightProvider> LIGHT_CAPABILITY = null;
@SubscribeEvent
public static void attachLights(AttachCapabilitiesEvent<Entity> event) {
Entity e = event.getObject();
if (e instanceof EntityFlameRing) {
addLight(event, (entity) -> Light.builder().pos(entity).color(1F, 0.5F, 0F).radius(20).build());
} else if (e instanceof EntityPixie) {
addLight(event, (EntityPixie pixie) -> pixie.getType() == 1 ? null : Light.builder().pos(pixie).color(1F, 0F, 0.5F).radius(8).build());
} else if (e instanceof EntityManaBurst) {
addLight(event, (EntityManaBurst burst) -> {
int color = burst.getColor();
return Light.builder()
.pos(burst.posX - burst.motionX, burst.posY - burst.motionY, burst.posZ - burst.motionZ)
.color(color, false)
.radius(burst.getParticleSize() * 8)
.build();
});
} else if (e instanceof TileLightRelay.EntityPlayerMover) {
addLight(event, (TileLightRelay.EntityPlayerMover mover) -> {
if (mover.getPassengers().isEmpty())
return null;
Entity passenger = mover.getPassengers().get(0);
Color color = Color.getHSBColor(passenger.ticksExisted / 36F, 1F, 1F);
return Light.builder().pos(mover).color(color.getRGB(), false).radius(5).build();
});
} else if (e instanceof EntityFallingStar) {
addLight(event, entity -> Light.builder().pos(entity).color(1F, 0F, 1F).radius(12).build());
} else if (e instanceof EntityBabylonWeapon) {
addLight(event, entity -> Light.builder().pos(entity).color(1F, 1F, 0F).radius(8).build());
} else if (e instanceof EntityMagicLandmine) {
addLight(event, entity -> Light.builder().pos(entity).color(0.6F, 0F, 1F).radius(15).build());
}
}
private static <T extends Entity> void addLight(AttachCapabilitiesEvent<Entity> event, Function<T, Light> lightFunction) {
event.addCapability(CAP_NAME, new BotaniaLightProvider<>(lightFunction));
}
private static class BotaniaLightProvider<E extends Entity> implements ILightProvider, ICapabilityProvider {
private Function<E, Light> lightFunction;
BotaniaLightProvider(Function<E, Light> light) {
this.lightFunction = light;
}
@Override
public void gatherLights(GatherLightsEvent event, Entity context) {
@SuppressWarnings("unchecked")
Light light = lightFunction.apply((E) context);
if(light != null)
event.add(light);
}
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return capability == LIGHT_CAPABILITY;
}
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
return capability == LIGHT_CAPABILITY ? LIGHT_CAPABILITY.cast(this) : null;
}
}
}
@@ -235,8 +235,7 @@ public class TileLightRelay extends TileMod implements ITickable, IWandBindable
cmp.setInteger(TAG_BIND_Z, bindPos.getZ());
}
@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo")
public static class EntityPlayerMover extends Entity implements ILightProvider {
public static class EntityPlayerMover extends Entity {
private static final String TAG_EXIT_X = "exitX";
private static final String TAG_EXIT_Y = "exitY";
@@ -354,17 +353,6 @@ public class TileLightRelay extends TileMod implements ITickable, 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();
}
}
}
@@ -85,6 +85,7 @@ public final class ConfigHandler {
public static boolean invertMagnetRing = false;
public static boolean enableThaumcraftStablizers = true;
public static boolean enableThaumcraftAspects = true;
public static boolean enableAlbedo = true;
public static boolean enableShedding = false;
public static int harvestLevelWeight = 2;
@@ -240,6 +241,9 @@ public final class ConfigHandler {
desc = "Set this to false to disable Thaumcraft aspects on Botania items";
enableThaumcraftAspects = loadPropBool("thaumcraftAspects.enabled", desc, enableThaumcraftAspects);
desc = "Set this to false to disable Albedo compat for moving colored lights on some Botania entities";
enableAlbedo = loadPropBool("albedoLights.enabled", desc, enableAlbedo);
desc = "Set this to true to enable the Shedding feature from 1.7.10. You'll need to load the game to generate the options. No options are enabled by default. This increases load time.";
enableShedding = loadPropBool("shedding.enable", desc, enableShedding);
@@ -39,8 +39,7 @@ import elucent.albedo.lighting.Light;
import java.util.List;
@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo")
public class EntityBabylonWeapon extends EntityThrowableCopy implements ILightProvider {
public class EntityBabylonWeapon extends EntityThrowableCopy {
private static final String TAG_CHARGING = "charging";
private static final String TAG_VARIETY = "variety";
@@ -202,12 +201,6 @@ public class EntityBabylonWeapon extends EntityThrowableCopy implements ILightPr
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);
}
@@ -27,8 +27,7 @@ import java.util.List;
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 class EntityFallingStar extends EntityThrowableCopy {
public EntityFallingStar(World world) {
super(world);
@@ -91,12 +90,6 @@ public class EntityFallingStar extends EntityThrowableCopy implements ILightProv
setDead();
}
@Override
@Optional.Method(modid="albedo")
public Light provideLight() {
return Light.builder().pos(this).color(1F, 0F, 1F).radius(12).build();
}
}
@@ -29,8 +29,7 @@ import elucent.albedo.lighting.Light;
import java.util.List;
@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo")
public class EntityFlameRing extends Entity implements ILightProvider {
public class EntityFlameRing extends Entity {
public EntityFlameRing(World world) {
super(world);
@@ -105,10 +104,4 @@ public class EntityFlameRing extends Entity implements ILightProvider {
@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();
}
}
@@ -30,8 +30,7 @@ import elucent.albedo.lighting.Light;
import java.util.List;
@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo")
public class EntityMagicLandmine extends Entity implements ILightProvider {
public class EntityMagicLandmine extends Entity {
public EntityDoppleganger summoner;
@@ -92,10 +91,4 @@ public class EntityMagicLandmine extends Entity implements ILightProvider {
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();
}
}
@@ -65,8 +65,7 @@ import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.core.helper.Vector3;
import vazkii.botania.common.item.equipment.bauble.ItemTinyPlanet;
@Optional.Interface(iface="elucent.albedo.lighting.ILightProvider", modid="albedo")
public class EntityManaBurst extends EntityThrowable implements IManaBurst, ILightProvider {
public class EntityManaBurst extends EntityThrowable implements IManaBurst {
private static final String TAG_TICKS_EXISTED = "ticksExisted";
private static final String TAG_COLOR = "color";
@@ -817,13 +816,6 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst, ILig
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 {
@@ -28,8 +28,7 @@ import javax.annotation.Nonnull;
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 {
public class EntityPixie extends EntityFlying {
private static final DataParameter<Integer> TYPE = EntityDataManager.createKey(EntityPixie.class, DataSerializers.VARINT);
@@ -145,14 +144,4 @@ public class EntityPixie extends EntityFlying implements ILightProvider {
public boolean canBeLeashedTo(EntityPlayer player) {
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();
}
}
@@ -17,7 +17,7 @@ public final class LibMisc {
public static final String MOD_NAME = "Botania";
public static final String BUILD = "GRADLE:BUILD";
public static final String VERSION = "GRADLE:VERSION-" + BUILD;
public static final String DEPENDENCIES = "required-after:baubles@[1.5.2,);after:thaumcraft@[6.1.BETA21,);after:jei@[1.12.2-4.13.1.220,)";
public static final String DEPENDENCIES = "required-after:baubles@[1.5.2,);after:thaumcraft@[6.1.BETA21,);after:jei@[1.12.2-4.13.1.220,);after:albedo@[1.0.0,)";
// Network Contants
public static final String NETWORK_CHANNEL = MOD_ID;
@@ -381,6 +381,7 @@ seasonalFeatures.enabled=Seasonal Features
shedding.enable=Natural Shedding
thaumcraftAspects.enabled=TC Aspects
thaumraftStabilizers.enabled=TC Infusion Stabilizers
albedoLights.enabled=Albedo Lights
# VERSION CHECKING
botania.versioning.flavour0=NANI SORE!? BOTANIA IS OUTDATED!?