Skip to content

Commit

Permalink
Applied Neptunium Boost with AttributeModifier Closes #155
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Nov 8, 2020
1 parent dc0d7f2 commit b81ab61
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
minecraft_version=1.16.3
forge_version=34.1.34
minecraft_version=1.16.4
forge_version=35.0.7
mappings=20201028-1.16.3
mod_version=2.1.5
jei_version=7.6.0.49
mod_version=2.1.6
jei_version=7.6.0.52

org.gradle.jvmargs=-Xmx4G
org.gradle.daemon=false
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.teammetallurgy.aquaculture.item.neptunium;

import com.teammetallurgy.aquaculture.Aquaculture;
import com.teammetallurgy.aquaculture.init.AquaItems;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
Expand All @@ -13,10 +16,17 @@
import net.minecraft.potion.Effects;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import javax.annotation.Nonnull;
import java.util.UUID;

@Mod.EventBusSubscriber(modid = Aquaculture.MOD_ID)
public class NeptuniumArmor extends ArmorItem {
private static final AttributeModifier INCREASED_SWIM_SPEED = new AttributeModifier(UUID.fromString("d820cadc-2d19-421c-b19f-4c1f5b84a418"), "Neptunium Boots swim speed boost", 1.5D, AttributeModifier.Operation.ADDITION);
private String texture;

public NeptuniumArmor(IArmorMaterial armorMaterial, EquipmentSlotType equipmentSlot) {
Expand All @@ -25,6 +35,7 @@ public NeptuniumArmor(IArmorMaterial armorMaterial, EquipmentSlotType equipmentS

@Override
public void onArmorTick(@Nonnull ItemStack stack, World world, PlayerEntity player) {
ModifiableAttributeInstance swimSpeed = player.getAttribute(ForgeMod.SWIM_SPEED.get());
if (player.areEyesInFluid(FluidTags.WATER)) {
if (this.slot == EquipmentSlotType.HEAD) {
player.addPotionEffect(new EffectInstance(Effects.NIGHT_VISION, 20, 0, false, false, false));
Expand All @@ -35,8 +46,31 @@ public void onArmorTick(@Nonnull ItemStack stack, World world, PlayerEntity play
player.setMotion(player.getMotion().add(0, player.fallDistance, 0));
}
} else if (this.slot == EquipmentSlotType.FEET) {
player.addPotionEffect(new EffectInstance(Effects.SPEED, 20, 0, false, false, false));
player.move(MoverType.PLAYER, player.getMotion()); //Make the swimming react to the swiftness potion
if (!world.isRemote) {
if (swimSpeed != null && !swimSpeed.hasModifier(INCREASED_SWIM_SPEED)) {
swimSpeed.applyNonPersistentModifier(INCREASED_SWIM_SPEED);
}
}
}
}
}

@SubscribeEvent
public static void onLivingTick(LivingEvent.LivingUpdateEvent event) {
LivingEntity livingEntity = event.getEntityLiving();
ModifiableAttributeInstance swimSpeed = livingEntity.getAttribute(ForgeMod.SWIM_SPEED.get());
if (livingEntity instanceof PlayerEntity) {
if (livingEntity.getItemStackFromSlot(EquipmentSlotType.FEET).getItem() != AquaItems.NEPTUNIUM_BOOTS) {
if (!livingEntity.world.isRemote) {
if (swimSpeed != null && swimSpeed.hasModifier(INCREASED_SWIM_SPEED)) {
swimSpeed.removeModifier(INCREASED_SWIM_SPEED);
}
}
}
if (!livingEntity.areEyesInFluid(FluidTags.WATER)) {
if (swimSpeed != null && swimSpeed.hasModifier(INCREASED_SWIM_SPEED)) {
swimSpeed.removeModifier(INCREASED_SWIM_SPEED);
}
}
}
}
Expand Down

0 comments on commit b81ab61

Please sign in to comment.