diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs index f9b2d33a..3f2271a9 100644 --- a/.settings/org.eclipse.jdt.ui.prefs +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -1,7 +1,11 @@ eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true -formatter_profile=_BloodMagic1.8 +formatter_profile=_BloodMagic formatter_settings_version=12 +org.eclipse.jdt.ui.exception.name=e +org.eclipse.jdt.ui.gettersetter.use.is=true +org.eclipse.jdt.ui.keywordthis=false +org.eclipse.jdt.ui.overrideannotation=true sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_missing_annotations=true diff --git a/src/main/java/WayofTime/bloodmagic/item/soulBreath/ItemFlightScroll.java b/src/main/java/WayofTime/bloodmagic/item/soulBreath/ItemFlightScroll.java new file mode 100644 index 00000000..e10d1297 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/soulBreath/ItemFlightScroll.java @@ -0,0 +1,116 @@ +package WayofTime.bloodmagic.item.soulBreath; + +import java.util.function.Consumer; + +import net.minecraft.client.renderer.ItemMeshDefinition; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.client.IMeshProvider; +import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable; +import WayofTime.bloodmagic.core.RegistrarBloodMagic; +import WayofTime.bloodmagic.iface.IActivatable; +import WayofTime.bloodmagic.util.Constants; +import WayofTime.bloodmagic.util.helper.NBTHelper; + +public class ItemFlightScroll extends ItemSoulBreathContainer implements IMeshProvider, IActivatable +{ + //TODO: A lot of this stuff could be moved to a toggle-able variant + public ItemFlightScroll() + { + super(); + setUnlocalizedName(BloodMagic.MODID + ".icarusScroll"); + setCreativeTab(BloodMagic.TAB_BM); + } + + @Override + public boolean getActivated(ItemStack stack) + { + return !stack.isEmpty() && NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED); + } + + @Override + public ItemStack setActivatedState(ItemStack stack, boolean activated) + { + if (!stack.isEmpty()) + { + NBTHelper.checkNBT(stack).getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated); + return stack; + } + + return stack; + } + + @Override + public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) + { + ItemStack stack = player.getHeldItem(hand); + + if (!world.isRemote) + { + if (player.isSneaking()) + setActivatedState(stack, !getActivated(stack)); + } + + return super.onItemRightClick(world, player, hand); + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) + { + if (!worldIn.isRemote && entityIn instanceof EntityPlayerMP && getActivated(stack)) + { + if (entityIn.ticksExisted % 100 == 0) + { + double drainNeeded = getBreathCostPerSecond(stack); + if (this.drainBreath(stack, drainNeeded, false) >= drainNeeded) + { + this.drainBreath(stack, drainNeeded, true); + } else + { + this.setActivatedState(stack, false); + } + } + + onEffectUpdate(stack, worldIn, (EntityPlayer) entityIn, itemSlot, isSelected); + } + } + + public void onEffectUpdate(ItemStack stack, World world, EntityPlayer player, int itemSlot, boolean isSelected) + { + player.addPotionEffect(new PotionEffect(RegistrarBloodMagic.FLIGHT, 2, 0)); + } + + @Override + public int getMaxBreath(ItemStack stack) + { + return 20; + } + + public double getBreathCostPerSecond(ItemStack stack) + { + return 0.01; + } + + @Override + @SideOnly(Side.CLIENT) + public ItemMeshDefinition getMeshDefinition() + { + return new CustomMeshDefinitionActivatable("icarus_scroll"); + } + + @Override + public void gatherVariants(Consumer variants) + { + variants.accept("active=false"); + variants.accept("active=true"); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/soulBreath/ItemSoulBreathContainer.java b/src/main/java/WayofTime/bloodmagic/item/soulBreath/ItemSoulBreathContainer.java new file mode 100644 index 00000000..1dfb41cd --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/soulBreath/ItemSoulBreathContainer.java @@ -0,0 +1,75 @@ +package WayofTime.bloodmagic.item.soulBreath; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import WayofTime.bloodmagic.soul.ISoulBreathContainer; +import WayofTime.bloodmagic.util.Constants; + +public abstract class ItemSoulBreathContainer extends Item implements ISoulBreathContainer +{ + @Override + public double getBreath(ItemStack stack) + { + NBTTagCompound tag = stack.getTagCompound(); + + return tag.getDouble(Constants.NBT.BREATH); + } + + @Override + public void setBreath(ItemStack stack, double amount) + { + NBTTagCompound tag = stack.getTagCompound(); + + tag.setDouble(Constants.NBT.BREATH, amount); + } + + @Override + public double drainBreath(ItemStack stack, double drainAmount, boolean doDrain) + { + double breath = getBreath(stack); + + double breathDrained = Math.min(drainAmount, breath); + + if (doDrain) + { + setBreath(stack, breath - breathDrained); + } + + return breathDrained; + } + + @Override + public double fillBreath(ItemStack stack, double fillAmount, boolean doFill) + { + double current = this.getBreath(stack); + double maxBreath = this.getMaxBreath(stack); + + double filled = Math.min(fillAmount, maxBreath - current); + + if (doFill) + { + this.setBreath(stack, filled + current); + } + + return filled; + } + + @Override + public boolean showDurabilityBar(ItemStack stack) + { + return true; + } + + @Override + public double getDurabilityForDisplay(ItemStack stack) + { + double maxWill = getMaxBreath(stack); + if (maxWill <= 0) + { + return 1; + } + return 1.0 - (getBreath(stack) / maxWill); + } + +} diff --git a/src/main/java/WayofTime/bloodmagic/soul/ISoulBreathContainer.java b/src/main/java/WayofTime/bloodmagic/soul/ISoulBreathContainer.java new file mode 100644 index 00000000..f8b9b137 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/soul/ISoulBreathContainer.java @@ -0,0 +1,16 @@ +package WayofTime.bloodmagic.soul; + +import net.minecraft.item.ItemStack; + +public interface ISoulBreathContainer +{ + double getBreath(ItemStack stack); + + void setBreath(ItemStack stack, double amount); + + int getMaxBreath(ItemStack stack); + + double drainBreath(ItemStack stack, double drainAmount, boolean doDrain); + + double fillBreath(ItemStack stack, double fillAmount, boolean doFill); +} diff --git a/src/main/resources/assets/bloodmagic/blockstates/icarus_scroll.json b/src/main/resources/assets/bloodmagic/blockstates/icarus_scroll.json new file mode 100644 index 00000000..748b4003 --- /dev/null +++ b/src/main/resources/assets/bloodmagic/blockstates/icarus_scroll.json @@ -0,0 +1,21 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "builtin/generated", + "transform": "forge:default-item" + }, + "variants": { + "active": { + "false": { + "textures": { + "layer0": "bloodmagic:items/icarusscroll_deactivated" + } + }, + "true": { + "textures": { + "layer0": "bloodmagic:items/icarusscroll_activated" + } + } + } + } +} diff --git a/src/main/resources/assets/bloodmagic/textures/items/icarusscroll_activated.png b/src/main/resources/assets/bloodmagic/textures/items/icarusscroll_activated.png new file mode 100644 index 00000000..767852ce Binary files /dev/null and b/src/main/resources/assets/bloodmagic/textures/items/icarusscroll_activated.png differ diff --git a/src/main/resources/assets/bloodmagic/textures/items/icarusscroll_deactivated.png b/src/main/resources/assets/bloodmagic/textures/items/icarusscroll_deactivated.png new file mode 100644 index 00000000..d16e87e0 Binary files /dev/null and b/src/main/resources/assets/bloodmagic/textures/items/icarusscroll_deactivated.png differ