This repository has been archived by the owner on May 13, 2023. It is now read-only.
forked from WayofTime/BloodMagic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/java/WayofTime/bloodmagic/item/soulBreath/ItemFlightScroll.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ItemStack> 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<String> variants) | ||
{ | ||
variants.accept("active=false"); | ||
variants.accept("active=true"); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/WayofTime/bloodmagic/item/soulBreath/ItemSoulBreathContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/WayofTime/bloodmagic/soul/ISoulBreathContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/resources/assets/bloodmagic/blockstates/icarus_scroll.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} | ||
} | ||
} |
Binary file added
BIN
+625 Bytes
src/main/resources/assets/bloodmagic/textures/items/icarusscroll_activated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+622 Bytes
src/main/resources/assets/bloodmagic/textures/items/icarusscroll_deactivated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.