Added additional anointments as well as some misc things
Added several Anointments (still need to list them fully). Also made it so that the Charges can be thrown.
This commit is contained in:
parent
e2ce9a473b
commit
5713d6db2a
42 changed files with 1222 additions and 446 deletions
|
@ -11,16 +11,22 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.entity.projectile.ArrowEntity;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.BowItem;
|
||||
import net.minecraft.item.CrossbowItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.potion.Effects;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDamageEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
||||
|
@ -552,4 +558,108 @@ public class GenericHandler
|
|||
AnointmentHolder holder = AnointmentHolder.fromItemStack(stack);
|
||||
AnointmentHolder.appendAnointmentTooltip(holder, event.getToolTip());
|
||||
}
|
||||
|
||||
private static final Map<ItemStack, Double> rollMap = new HashMap<ItemStack, Double>();
|
||||
|
||||
@SubscribeEvent
|
||||
public void onEntityUseTick(LivingEntityUseItemEvent.Tick event)
|
||||
{
|
||||
ItemStack stack = event.getItem();
|
||||
if (stack.getItem() instanceof BowItem || stack.getItem() instanceof CrossbowItem)
|
||||
{
|
||||
AnointmentHolder holder = AnointmentHolder.fromItemStack(stack);
|
||||
int quickDrawLevel = holder.getAnointmentLevel(AnointmentRegistrar.ANOINTMENT_QUICK_DRAW.get());
|
||||
if (quickDrawLevel > 0)
|
||||
{
|
||||
double amount = rollMap.getOrDefault(stack, 0D) + AnointmentRegistrar.ANOINTMENT_QUICK_DRAW.get().getBonusValue("speed", quickDrawLevel).doubleValue();
|
||||
if (amount >= 1)
|
||||
{
|
||||
int drawReduction = (int) amount;
|
||||
event.setDuration(event.getDuration() - drawReduction);
|
||||
} else
|
||||
{
|
||||
rollMap.put(stack, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onEntityFinishUse(LivingEntityUseItemEvent.Stop event)
|
||||
{
|
||||
ItemStack stack = event.getItem();
|
||||
if (stack.getItem() instanceof CrossbowItem)
|
||||
{
|
||||
int i = stack.getUseDuration() - event.getDuration();
|
||||
float f = getCharge(i, stack);
|
||||
if (f < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
AnointmentHolder holder = AnointmentHolder.fromItemStack(stack);
|
||||
if (holder != null)
|
||||
{
|
||||
if (holder.consumeAnointmentDurabilityOnUseFinish(stack, EquipmentSlotType.MAINHAND))
|
||||
{
|
||||
|
||||
holder.toItemStack(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onEntityJoinEvent(EntityJoinWorldEvent event)
|
||||
{
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof ArrowEntity)
|
||||
{
|
||||
if (entity.ticksExisted <= 0)
|
||||
{
|
||||
// System.out.println("An arrow joined the world! Looking for the shooter...");
|
||||
ArrowEntity arrowEntity = (ArrowEntity) entity;
|
||||
Entity shooter = arrowEntity.func_234616_v_();
|
||||
if (shooter instanceof PlayerEntity)
|
||||
{
|
||||
PlayerEntity playerShooter = (PlayerEntity) shooter;
|
||||
for (Hand hand : Hand.values())
|
||||
{
|
||||
ItemStack heldStack = playerShooter.getHeldItem(hand);
|
||||
AnointmentHolder holder = AnointmentHolder.fromItemStack(heldStack);
|
||||
if (holder == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int powerLevel = holder.getAnointmentLevel(AnointmentRegistrar.ANOINTMENT_BOW_POWER.get());
|
||||
if (powerLevel > 0)
|
||||
{
|
||||
arrowEntity.setDamage(arrowEntity.getDamage() * AnointmentRegistrar.ANOINTMENT_BOW_POWER.get().getBonusValue("damage", powerLevel).doubleValue());
|
||||
|
||||
// System.out.println("Arrow damage is now: " + arrowEntity.getDamage());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static float getCharge(int useTime, ItemStack stack)
|
||||
{
|
||||
float f = (float) useTime / (float) getChargeTime(stack);
|
||||
if (f > 1.0F)
|
||||
{
|
||||
f = 1.0F;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
public static int getChargeTime(ItemStack stack)
|
||||
{
|
||||
int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.QUICK_CHARGE, stack);
|
||||
return i == 0 ? 25 : 25 - 5 * i;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue