-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add the Nano Saber * reviews * spotless
- Loading branch information
Showing
14 changed files
with
314 additions
and
13 deletions.
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
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
14 changes: 14 additions & 0 deletions
14
src/generated/resources/assets/gtceu/models/item/nano_saber.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,14 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"overrides": [ | ||
{ | ||
"model": "gtceu:item/nano_saber/active", | ||
"predicate": { | ||
"gtceu:nano_saber_active": 1.0 | ||
} | ||
} | ||
], | ||
"textures": { | ||
"layer0": "gtceu:item/nano_saber/normal" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/generated/resources/assets/gtceu/models/item/nano_saber/active.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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "gtceu:item/nano_saber/active" | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/gregtechceu/gtceu/api/item/component/IEnchantableItem.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,13 @@ | ||
package com.gregtechceu.gtceu.api.item.component; | ||
|
||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.enchantment.Enchantment; | ||
|
||
public interface IEnchantableItem { | ||
|
||
boolean isEnchantable(ItemStack stack); | ||
|
||
int getEnchantmentValue(ItemStack stack); | ||
|
||
boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/gregtechceu/gtceu/api/item/component/IItemAttributes.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,13 @@ | ||
package com.gregtechceu.gtceu.api.item.component; | ||
|
||
import net.minecraft.world.entity.EquipmentSlot; | ||
import net.minecraft.world.entity.ai.attributes.Attribute; | ||
import net.minecraft.world.entity.ai.attributes.AttributeModifier; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import com.google.common.collect.Multimap; | ||
|
||
public interface IItemAttributes { | ||
|
||
Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlot slot, ItemStack stack); | ||
} |
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
69 changes: 69 additions & 0 deletions
69
src/main/java/com/gregtechceu/gtceu/common/item/NanoSaberBehavior.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,69 @@ | ||
package com.gregtechceu.gtceu.common.item; | ||
|
||
import com.gregtechceu.gtceu.GTCEu; | ||
import com.gregtechceu.gtceu.api.item.component.IEnchantableItem; | ||
import com.gregtechceu.gtceu.api.item.component.IItemAttributes; | ||
import com.gregtechceu.gtceu.config.ConfigHolder; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.EquipmentSlot; | ||
import net.minecraft.world.entity.ai.attributes.Attribute; | ||
import net.minecraft.world.entity.ai.attributes.AttributeModifier; | ||
import net.minecraft.world.entity.ai.attributes.Attributes; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.item.enchantment.Enchantment; | ||
import net.minecraft.world.item.enchantment.Enchantments; | ||
|
||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.Multimap; | ||
|
||
public class NanoSaberBehavior extends ToggleEnergyConsumerBehavior implements IItemAttributes, IEnchantableItem { | ||
|
||
public static final ResourceLocation OVERRIDE_KEY_LOCATION = GTCEu.id("nano_saber_active"); | ||
|
||
private final double baseAttackDamage; | ||
private final double additionalAttackDamage; | ||
|
||
public NanoSaberBehavior() { | ||
super(ConfigHolder.INSTANCE.tools.nanoSaber.energyConsumption); | ||
this.baseAttackDamage = ConfigHolder.INSTANCE.tools.nanoSaber.nanoSaberBaseDamage; | ||
this.additionalAttackDamage = ConfigHolder.INSTANCE.tools.nanoSaber.nanoSaberDamageBoost; | ||
} | ||
|
||
@Override | ||
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlot slot, ItemStack stack) { | ||
HashMultimap<Attribute, AttributeModifier> modifiers = HashMultimap.create(); | ||
if (slot == EquipmentSlot.MAINHAND) { | ||
double attackDamage = baseAttackDamage + (isItemActive(stack) ? additionalAttackDamage : 0.0D); | ||
modifiers.put(Attributes.ATTACK_SPEED, | ||
new AttributeModifier(Item.BASE_ATTACK_SPEED_UUID, "Weapon modifier", -2.0, | ||
AttributeModifier.Operation.ADDITION)); | ||
modifiers.put(Attributes.ATTACK_DAMAGE, | ||
new AttributeModifier(Item.BASE_ATTACK_DAMAGE_UUID, "Weapon Modifier", attackDamage, | ||
AttributeModifier.Operation.ADDITION)); | ||
} | ||
return modifiers; | ||
} | ||
|
||
@Override | ||
public boolean isEnchantable(ItemStack stack) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int getEnchantmentValue(ItemStack stack) { | ||
return 33; | ||
} | ||
|
||
@Override | ||
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { | ||
if (enchantment.category == null) { | ||
return false; | ||
} | ||
return enchantment != Enchantments.UNBREAKING && | ||
enchantment != Enchantments.MENDING && | ||
enchantment.category.canEnchant(Items.IRON_SWORD); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/com/gregtechceu/gtceu/common/item/ToggleEnergyConsumerBehavior.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,78 @@ | ||
package com.gregtechceu.gtceu.common.item; | ||
|
||
import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper; | ||
import com.gregtechceu.gtceu.api.capability.IElectricItem; | ||
import com.gregtechceu.gtceu.api.item.component.IAddInformation; | ||
import com.gregtechceu.gtceu.api.item.component.IInteractionItem; | ||
import com.gregtechceu.gtceu.api.item.component.IItemLifeCycle; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResultHolder; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.TooltipFlag; | ||
import net.minecraft.world.level.Level; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class ToggleEnergyConsumerBehavior implements IInteractionItem, IItemLifeCycle, IAddInformation { | ||
|
||
private final int energyUsagePerTick; | ||
|
||
public ToggleEnergyConsumerBehavior(int energyUsagePerTick) { | ||
this.energyUsagePerTick = energyUsagePerTick; | ||
} | ||
|
||
@Override | ||
public InteractionResultHolder<ItemStack> use(Item item, Level world, Player player, InteractionHand hand) { | ||
ItemStack itemStack = player.getItemInHand(hand); | ||
if (player.isShiftKeyDown()) { | ||
IElectricItem electricItem = GTCapabilityHelper.getElectricItem(itemStack); | ||
boolean isItemActive = isItemActive(itemStack); | ||
if (isItemActive) { | ||
setItemActive(itemStack, false); | ||
} else if (electricItem != null && drainActivationEnergy(electricItem, true)) { | ||
setItemActive(itemStack, true); | ||
} | ||
} | ||
return InteractionResultHolder.pass(itemStack); | ||
} | ||
|
||
private boolean drainActivationEnergy(IElectricItem electricItem, boolean simulate) { | ||
return electricItem.discharge(energyUsagePerTick, electricItem.getTier(), true, false, simulate) >= | ||
energyUsagePerTick; | ||
} | ||
|
||
@Override | ||
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { | ||
IElectricItem electricItem = GTCapabilityHelper.getElectricItem(stack); | ||
if (isItemActive(stack) && electricItem != null) { | ||
boolean shouldRemainActive = drainActivationEnergy(electricItem, false); | ||
if (!shouldRemainActive) { | ||
setItemActive(stack, false); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltipComponents, | ||
TooltipFlag isAdvanced) { | ||
tooltipComponents.add(Component.translatable("behavior.toggle_energy_consumer.tooltip")); | ||
} | ||
|
||
public static boolean isItemActive(ItemStack itemStack) { | ||
CompoundTag tagCompound = itemStack.getTag(); | ||
return tagCompound != null && tagCompound.getBoolean("Active"); | ||
} | ||
|
||
public static void setItemActive(ItemStack itemStack, boolean isActive) { | ||
CompoundTag tagCompound = itemStack.getOrCreateTag(); | ||
tagCompound.putBoolean("Active", isActive); | ||
} | ||
} |
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
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
Oops, something went wrong.