From 920d105374a502927355953ac7393835cd155342 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Tue, 1 May 2018 06:51:37 -0400 Subject: [PATCH] Needed to be more pushy. --- .settings/org.eclipse.jdt.ui.prefs | 6 +- .../item/soulBreath/ItemFlightScroll.java | 116 ++++++++++++++++++ .../soulBreath/ItemSoulBreathContainer.java | 75 +++++++++++ .../bloodmagic/soul/ISoulBreathContainer.java | 16 +++ .../bloodmagic/blockstates/icarus_scroll.json | 21 ++++ .../textures/items/icarusscroll_activated.png | Bin 0 -> 625 bytes .../items/icarusscroll_deactivated.png | Bin 0 -> 622 bytes 7 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 src/main/java/WayofTime/bloodmagic/item/soulBreath/ItemFlightScroll.java create mode 100644 src/main/java/WayofTime/bloodmagic/item/soulBreath/ItemSoulBreathContainer.java create mode 100644 src/main/java/WayofTime/bloodmagic/soul/ISoulBreathContainer.java create mode 100644 src/main/resources/assets/bloodmagic/blockstates/icarus_scroll.json create mode 100644 src/main/resources/assets/bloodmagic/textures/items/icarusscroll_activated.png create mode 100644 src/main/resources/assets/bloodmagic/textures/items/icarusscroll_deactivated.png 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 0000000000000000000000000000000000000000..767852ce986246c1e6191e3f19b48d99190d2fb9 GIT binary patch literal 625 zcmV-%0*?KOP)WFU8GbZ8()Nlj2>E@cM*00GrWL_t(I%f*vBXjDNI zhQBj+?>@4wkJyQY4-{;zY()eg;A0D0>y@Aq4W`hnAi*rCuy#=pgJ=<7hzM$FXDx_U zT38D)=I-9TGxxVxU0sq?DLgRE%$e`}^Pe*&iM51djZs+bVB+{jb(c~?5I%?y`brIm zB4hSlYO4a~ntRn~j1#&YT&WBaxlfsC-DLXZbEZzz|0YWsTA!ayNT84N=OmCoA09S- z@156~{Uwbb9?_qC``5(Rck9|(-GY2Z`f~w?$OFXHD$Yd|s#VCv{YUp`y;vN6!o_2w z8asOl1yAlX${RK#d5|OYl72Pku*hMyf{Dpug7U!jLzjpA`0{3&-Srj#U*BFQ_;lqi z^fC=D_~Zw99?0`R`2LMgPsS;f*FoCBMG@U@SPtlRa?C~j;V4#!%mE^#2~tj$EMOMl z;+RenmJd>`=8(j;gOlt$dX*hVrofC{CtF0t3VTkqDb_X-SJqQ1MFYT~3u6b$0=O{Q zBxGH{P}U=aj66#zlt(Zevv=A6+<3KQLkheXR~|oQ=2{c80t$g%vVa+sYNJGPnfC2l zOgxw$@?fCg^uAbz5j+%PD8_~Wvp(EsA}%_-7ZS|9@7WOGzx~EvMve3JEpOYO00000 LNkvXXu0mjf0SO1@ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..d16e87e04373ef1e329f7359fdc428718a6b2d29 GIT binary patch literal 622 zcmV-!0+IcRP)WFU8GbZ8()Nlj2>E@cM*00GiTL_t(I%f*wwYg2I) z#XtA^eJ^?GOInS%h<}BXi<1sc{)pn*xmZMMsxBH(gcg4hovKAF7KciyS_F0Ipp*ZC zqc|x9V(d#^-uL^iL!cVcOdY)I6k3 zVd+yUV+mFoM|5Up4&UoyiV>)iyOf2+``p>w;O3dycm-cKuIkAj-)MDORJT?E_<8IC z2S2Y-zkHEf=g(0t|AooFA-;cF)5Gy0)Mcc<+ZdGGLm0;xV+rCIa^?BUXDq(y3|pw5 zs_N{eYp8eRE+d*cfT{yE_