Needed to be more pushy.

This commit is contained in:
WayofTime 2018-05-01 06:51:37 -04:00
parent 29ae24b044
commit 920d105374
7 changed files with 233 additions and 1 deletions

View file

@ -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

View file

@ -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");
}
}

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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 not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B