Skip to content

Commit

Permalink
Changed Is Offhand check to NBT for Nuit's Ire and Quarter. Closes #277
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Jun 4, 2021
1 parent f229b0d commit 2fe88ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.teammetallurgy.atum.init.AtumItems;
import com.teammetallurgy.atum.init.AtumParticles;
import com.teammetallurgy.atum.items.tools.KhopeshItem;
import com.teammetallurgy.atum.misc.StackHelper;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import net.minecraft.entity.Entity;
Expand All @@ -16,6 +17,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Rarity;
import net.minecraft.item.UseAction;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.ActionResult;
Expand All @@ -32,7 +34,6 @@

@Mod.EventBusSubscriber(modid = Atum.MOD_ID)
public class NuitsIreItem extends KhopeshItem implements IArtifact {
private boolean isOffhand = false;
private static final Object2BooleanMap<LivingEntity> IS_BLOCKING = new Object2BooleanOpenHashMap<>();

public NuitsIreItem() {
Expand All @@ -52,23 +53,24 @@ public UseAction getUseAction(@Nonnull ItemStack stack) {

@Override
public int getUseDuration(@Nonnull ItemStack stack) {
return isOffhand ? 72000 : 0;
return this.getIsOffHand(stack) ? 72000 : 0;
}

@Override
public boolean isShield(@Nonnull ItemStack stack, @Nullable LivingEntity entity) {
return isOffhand;
return this.getIsOffHand(stack);
}

@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull World world, @Nonnull PlayerEntity player, @Nonnull Hand hand) {
CompoundNBT tag = StackHelper.getTag(player.getHeldItem(hand));
if (hand == Hand.OFF_HAND) {
player.setActiveHand(Hand.OFF_HAND);
this.isOffhand = true;
tag.putBoolean("is_offhand", true);
return new ActionResult<>(ActionResultType.SUCCESS, player.getHeldItem(Hand.OFF_HAND));
}
this.isOffhand = false;
tag.putBoolean("is_offhand", false);
return super.onItemRightClick(world, player, hand);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.teammetallurgy.atum.init.AtumItems;
import com.teammetallurgy.atum.init.AtumParticles;
import com.teammetallurgy.atum.items.tools.KhopeshItem;
import com.teammetallurgy.atum.misc.StackHelper;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import net.minecraft.entity.Entity;
Expand All @@ -16,6 +17,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Rarity;
import net.minecraft.item.UseAction;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.ActionResult;
Expand All @@ -32,7 +34,6 @@

@Mod.EventBusSubscriber(modid = Atum.MOD_ID)
public class NuitsQuarterItem extends KhopeshItem implements IArtifact {
private boolean isOffhand = false;
private static final Object2BooleanMap<LivingEntity> IS_BLOCKING = new Object2BooleanOpenHashMap<>();

public NuitsQuarterItem() {
Expand All @@ -52,23 +53,24 @@ public UseAction getUseAction(@Nonnull ItemStack stack) {

@Override
public int getUseDuration(@Nonnull ItemStack stack) {
return isOffhand ? 72000 : 0;
return this.getIsOffHand(stack) ? 72000 : 0;
}

@Override
public boolean isShield(@Nonnull ItemStack stack, @Nullable LivingEntity entity) {
return isOffhand;
return this.getIsOffHand(stack);
}

@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull World world, @Nonnull PlayerEntity player, @Nonnull Hand hand) {
CompoundNBT tag = StackHelper.getTag(player.getHeldItem(hand));
if (hand == Hand.OFF_HAND) {
player.setActiveHand(Hand.OFF_HAND);
this.isOffhand = true;
tag.putBoolean("is_offhand", true);
return new ActionResult<>(ActionResultType.SUCCESS, player.getHeldItem(Hand.OFF_HAND));
}
this.isOffhand = false;
tag.putBoolean("is_offhand", false);
return super.onItemRightClick(world, player, hand);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.teammetallurgy.atum.items.tools;

import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.misc.StackHelper;
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
import net.minecraft.enchantment.EnchantmentHelper;
Expand Down Expand Up @@ -34,6 +35,10 @@ public KhopeshItem(IItemTier itemTier, Item.Properties properties) {
super(itemTier, 3, -2.6F, properties.group(Atum.GROUP));
}

public boolean getIsOffHand(@Nonnull ItemStack stack) {
return StackHelper.hasKey(stack, "is_offhand") && stack.getTag() != null && stack.getTag().getBoolean("is_offhand");
}

@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onAttack(AttackEntityEvent event) {
PlayerEntity player = event.getPlayer();
Expand Down

0 comments on commit 2fe88ee

Please sign in to comment.