From e8b2b13a389cbeb3d66e52de59bec5fdc573c74e Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 3 Mar 2019 22:38:54 +0200 Subject: [PATCH] The light gem will now emit light --- .../unicopia/spell/SpellLight.java | 64 +++++++++++++++++++ .../unicopia/spell/SpellRegistry.java | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/spell/SpellLight.java diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellLight.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellLight.java new file mode 100644 index 00000000..ebcb8131 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellLight.java @@ -0,0 +1,64 @@ +package com.minelittlepony.unicopia.spell; + +import com.minelittlepony.util.PosHelper; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.EnumSkyBlock; +import net.minecraft.world.World; + +public class SpellLight extends GenericSpell { + + private BlockPos lastPos; + private ICaster source; + + public SpellLight() { + super("light", 0xF7FACB, SpellAffinity.GOOD); + } + + @Override + public void onPlaced(ICaster caster) { + this.source = caster; + } + + @Override + public void setDead() { + super.setDead(); + + if (lastPos != null) { + source.getWorld().checkLight(lastPos); + } + } + + @Override + public boolean update(ICaster source) { + this.source = source; + + BlockPos pos = source.getOrigin().down(); + + World world = source.getWorld(); + + if (lastPos != null && !lastPos.equals(pos)) { + world.checkLight(lastPos); + } + + lastPos = pos; + + + int light = world.getLightFor(EnumSkyBlock.BLOCK, pos); + + if (light < 8) { + world.setLightFor(EnumSkyBlock.BLOCK, pos, 8); + world.notifyLightSet(pos); + world.checkLight(pos.up()); + } + + return true; + } + + protected void resetLight(BlockPos pos) { + + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java index 42eb2a9b..34900f68 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellRegistry.java @@ -46,7 +46,7 @@ public class SpellRegistry { registerSpell(SpellDarkness::new); registerSpell(SpellFlame::new); registerSpell(SpellSiphon::new); - registerSpell(GenericSpell.factory("light", 0xF7FACB, SpellAffinity.GOOD)); + registerSpell(SpellLight::new); } @Nullable