Move inner helper method of manaprof armor to the interface itself

This commit is contained in:
Vincent Lee committed 2020-02-14 23:53:38 -06:00
1 parent 92c6708a68
commit 669568f426
10 files changed
+26 -39

No files matched your search

@@ -25,35 +25,31 @@ import vazkii.botania.api.mana.ManaProficiencyEvent;
* armor set, where only one piece implements it.
*/
public interface IManaProficiencyArmor {
default boolean shouldGiveProficiency(ItemStack armorStack, EquipmentSlotType slot, PlayerEntity player, ItemStack rod) {
return false;
}
public final static class Helper {
public static boolean hasProficiency(PlayerEntity player, ItemStack rod) {
boolean proficient = false;
for(EquipmentSlotType e: EquipmentSlotType.values()) {
if(e.getSlotType() != EquipmentSlotType.Group.ARMOR)
continue;
ItemStack armor = player.getItemStackFromSlot(e);
if(!armor.isEmpty()) {
Item item = armor.getItem();
if(item instanceof IManaProficiencyArmor && ((IManaProficiencyArmor) item).shouldGiveProficiency(armor, e, player, rod)) {
proficient = true;
break;
}
static boolean hasProficiency(PlayerEntity player, ItemStack rod) {
boolean proficient = false;
for(EquipmentSlotType e: EquipmentSlotType.values()) {
if(e.getSlotType() != EquipmentSlotType.Group.ARMOR)
continue;
ItemStack armor = player.getItemStackFromSlot(e);
if(!armor.isEmpty()) {
Item item = armor.getItem();
if(item instanceof IManaProficiencyArmor && ((IManaProficiencyArmor) item).shouldGiveProficiency(armor, e, player, rod)) {
proficient = true;
break;
}
}
ManaProficiencyEvent event = new ManaProficiencyEvent(player, rod, proficient);
MinecraftForge.EVENT_BUS.post(event);
return event.isProficient();
}
ManaProficiencyEvent event = new ManaProficiencyEvent(player, rod, proficient);
MinecraftForge.EVENT_BUS.post(event);
return event.isProficient();
}
}
@@ -15,7 +15,6 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
@@ -51,7 +50,7 @@ public class ItemDiviningRod extends Item implements IManaUsingItem, IAvatarWiel
ItemStack stack = p.getHeldItem(hand);
if(ManaItemHandler.requestManaExactForTool(stack, p, COST, true)) {
if(world.isRemote) {
int range = IManaProficiencyArmor.Helper.hasProficiency(p, stack) ? 20 : 15;
int range = IManaProficiencyArmor.hasProficiency(p, stack) ? 20 : 15;
long seedxor = world.rand.nextLong();
doHighlight(world, new BlockPos(p), range, seedxor);
p.swingArm(hand);
@@ -45,7 +45,6 @@ import vazkii.botania.api.mana.ManaItemHandler;
import vazkii.botania.client.core.handler.ItemsRemainingRenderHandler;
import vazkii.botania.common.block.BlockPlatform;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import net.minecraft.item.Item;
import javax.annotation.Nonnull;
import java.util.ArrayList;
@@ -119,7 +118,7 @@ public class ItemExchangeRod extends Item implements IManaUsingItem, IWireframeC
PlayerEntity player = (PlayerEntity) entity;
int extraRange = ItemNBTHelper.getInt(stack, TAG_EXTRA_RANGE, 1);
int extraRangeNew = IManaProficiencyArmor.Helper.hasProficiency(player, stack) ? 3 : 1;
int extraRangeNew = IManaProficiencyArmor.hasProficiency(player, stack) ? 3 : 1;
if(extraRange != extraRangeNew)
ItemNBTHelper.setInt(stack, TAG_EXTRA_RANGE, extraRangeNew);
@@ -55,7 +55,7 @@ public class ItemFireRod extends Item implements IManaUsingItem, IAvatarWieldabl
entity.setPosition(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
world.addEntity(entity);
player.getCooldownTracker().setCooldown(this, IManaProficiencyArmor.Helper.hasProficiency(player, stack) ? COOLDOWN / 2 : COOLDOWN);
player.getCooldownTracker().setCooldown(this, IManaProficiencyArmor.hasProficiency(player, stack) ? COOLDOWN / 2 : COOLDOWN);
ManaItemHandler.requestManaExactForTool(stack, player, COST, true);
ctx.getWorld().playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_BLAZE_AMBIENT, player != null ? SoundCategory.PLAYERS : SoundCategory.BLOCKS, 1F, 1F);
@@ -20,7 +20,6 @@ import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.tags.Tag;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
@@ -213,7 +212,7 @@ public class ItemGravityRod extends Item implements IManaUsingItem {
Vector3 moveVector = new Vector3(player.getLookVec().normalize());
if(item instanceof ItemEntity) {
((ItemEntity) item).setPickupDelay(20);
float mot = IManaProficiencyArmor.Helper.hasProficiency(player, stack) ? 2.25F : 1.5F;
float mot = IManaProficiencyArmor.hasProficiency(player, stack) ? 2.25F : 1.5F;
item.setMotion(moveVector.x * mot, moveVector.y, moveVector.z * mot);
if(!player.world.isRemote) {
EntityThrownItem thrown = new EntityThrownItem(item.world, item.getX(), item.getY(), item.getZ(), (ItemEntity) item);
@@ -17,7 +17,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.UseAction;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
@@ -60,7 +59,7 @@ public class ItemMissileRod extends Item implements IManaUsingItem, IAvatarWield
if(!(living instanceof PlayerEntity)) return;
PlayerEntity player = (PlayerEntity) living;
if(count != getUseDuration(stack) && count % (IManaProficiencyArmor.Helper.hasProficiency(player, stack) ? 1 : 2) == 0 && !player.world.isRemote && ManaItemHandler.requestManaExactForTool(stack, player, COST_PER, false)) {
if(count != getUseDuration(stack) && count % (IManaProficiencyArmor.hasProficiency(player, stack) ? 1 : 2) == 0 && !player.world.isRemote && ManaItemHandler.requestManaExactForTool(stack, player, COST_PER, false)) {
if(spawnMissile(player.world, player, player.getX() + (Math.random() - 0.5 * 0.1), player.getY() + 2.4 + (Math.random() - 0.5 * 0.1), player.getZ() + (Math.random() - 0.5 * 0.1)))
ManaItemHandler.requestManaExactForTool(stack, player, COST_PER, true);
@@ -15,7 +15,6 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
@@ -71,7 +70,7 @@ public class ItemRainbowRod extends Item implements IManaUsingItem, IAvatarWield
BlockPos.Mutable lastChecker = new BlockPos.Mutable();
int count = 0;
boolean prof = IManaProficiencyArmor.Helper.hasProficiency(player, stack);
boolean prof = IManaProficiencyArmor.hasProficiency(player, stack);
int maxlen = prof ? 160 : 100;
int time = prof ? (int) (TIME * 1.6) : TIME;
@@ -21,7 +21,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.UseAction;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
@@ -126,7 +125,7 @@ public class ItemSmeltRod extends Item implements IManaUsingItem {
}
if(!decremented)
playerData.put(p, new SmeltData(pos, IManaProficiencyArmor.Helper.hasProficiency(p, stack) ? (int) (TIME * 0.6) : TIME));
playerData.put(p, new SmeltData(pos, IManaProficiencyArmor.hasProficiency(p, stack) ? (int) (TIME * 0.6) : TIME));
else {
for(int i = 0; i < 2; i++) {
double x = pos.getPos().getX() + Math.random();
@@ -22,7 +22,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.UseAction;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
@@ -87,7 +86,7 @@ public class ItemTerraformRod extends Item implements IManaUsingItem, IBlockProv
}
private void terraform(ItemStack stack, World world, PlayerEntity player) {
int range = IManaProficiencyArmor.Helper.hasProficiency(player, stack) ? 22 : 16;
int range = IManaProficiencyArmor.hasProficiency(player, stack) ? 22 : 16;
BlockPos startCenter = new BlockPos(player).down();
@@ -14,11 +14,9 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.UseAction;
import net.minecraft.potion.EffectInstance;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
@@ -71,7 +69,7 @@ public class ItemTornadoRod extends Item implements IManaUsingItem, IAvatarWield
} else if(isFlying(stack)) {
if(held) {
player.fallDistance = 0F;
double my = IManaProficiencyArmor.Helper.hasProficiency(player, stack) ? 1.6 : 1.25;
double my = IManaProficiencyArmor.hasProficiency(player, stack) ? 1.6 : 1.25;
Vec3d oldMot = player.getMotion();
player.setMotion(new Vec3d(oldMot.getX(), my, oldMot.getZ()));