Add latest revisions after getting it functional
This commit is contained in:
parent
9653e273e4
commit
ffcecb8e8e
1443 changed files with 258988 additions and 6046 deletions
160
src/main/java/com/zontreck/enchantments/ConsumptionMending.java
Normal file
160
src/main/java/com/zontreck/enchantments/ConsumptionMending.java
Normal file
|
@ -0,0 +1,160 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.libzontreck.util.ItemUtils;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConsumptionMending extends Enchantment
|
||||
{
|
||||
protected ConsumptionMending(EquipmentSlot... slots) {
|
||||
super(Rarity.RARE, EnchantmentCategory.BREAKABLE, slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTradeable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurse() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinCost(int pLevel) {
|
||||
return 25 + (pLevel-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCost(int pLevel) {
|
||||
return pLevel * 23;
|
||||
}
|
||||
|
||||
private static List<ItemStack> append(ServerPlayer player, List<ItemStack> items)
|
||||
{
|
||||
List<ItemStack> enchanted = new ArrayList<>();
|
||||
|
||||
for(ItemStack stack : player.getInventory().items)
|
||||
{
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.CONSUMPTION_MENDING.get(), stack) > 0)
|
||||
{
|
||||
enchanted.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
return enchanted;
|
||||
}
|
||||
|
||||
public static void onEntityTick(ServerPlayer player)
|
||||
{
|
||||
// Check what items have this enchantment
|
||||
// If any, check for like-items that lack the enchant.
|
||||
|
||||
List<ItemStack> enchanted = ItemUtils.getPlayerInventory(player);
|
||||
List<ItemStack> procList = new ArrayList<>(enchanted);
|
||||
|
||||
for(ItemStack stack : enchanted)
|
||||
{
|
||||
int dmgValue = stack.getDamageValue();
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.CONSUMPTION_MENDING.get(), stack) == 0 || dmgValue == 0) continue; // Skip, because this is a ineligible item
|
||||
|
||||
for(ItemStack item : procList)
|
||||
{
|
||||
// Is this a like item, and does it have the enchant?
|
||||
boolean eligible = false;
|
||||
if(!(ItemUtils.getEnchantmentLevel(ModEnchantments.CONSUMPTION_MENDING.get(), item)>0))
|
||||
{
|
||||
eligible=true;
|
||||
if(!item.isDamageableItem())
|
||||
{
|
||||
eligible=false;
|
||||
}
|
||||
}
|
||||
|
||||
if(stack.getDamageValue()==0)
|
||||
{
|
||||
eligible=false;
|
||||
}
|
||||
|
||||
if(stack.sameItem(item)) {
|
||||
eligible = false;
|
||||
}
|
||||
|
||||
if(eligible)
|
||||
{
|
||||
// Let's eat
|
||||
int iDamage = stack.getDamageValue();
|
||||
int iMax = stack.getMaxDamage();
|
||||
|
||||
int iNeeds = iDamage * 2;
|
||||
|
||||
// The stack we are inspecting:
|
||||
int nDamage = item.getDamageValue();
|
||||
int nMax = item.getMaxDamage();
|
||||
|
||||
int iRemain = nMax - nDamage;
|
||||
|
||||
if(iRemain == iNeeds)
|
||||
{
|
||||
nDamage = nMax;
|
||||
iDamage=0;
|
||||
} else {
|
||||
if(iRemain > iNeeds)
|
||||
{
|
||||
iDamage -= iNeeds;
|
||||
nDamage += iNeeds;
|
||||
} else {
|
||||
iDamage -= iRemain;
|
||||
nDamage = nMax;
|
||||
}
|
||||
}
|
||||
|
||||
if(nDamage == nMax){
|
||||
// Check for curses on the item
|
||||
if(item.isEnchanted())
|
||||
{
|
||||
Map<Enchantment, Integer> enchantments = ItemUtils.getEnchantments(item);
|
||||
for(Map.Entry<Enchantment,Integer> entry : enchantments.entrySet())
|
||||
{
|
||||
Enchantment id = entry.getKey();
|
||||
int dice = player.getRandom().nextInt(0,20);
|
||||
|
||||
if(id.isCurse() && ((dice >= 13) && (dice <= 18)))
|
||||
{
|
||||
stack.enchant(id, entry.getValue());
|
||||
player.getLevel().playSound(null, player.getOnPos(), SoundEvents.ANVIL_USE, SoundSource.NEUTRAL,1, player.getRandom().nextFloat());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item.shrink(1);
|
||||
player.getLevel().playSound(null, player.getOnPos(), SoundEvents.PLAYER_BURP, SoundSource.NEUTRAL,1, player.getRandom().nextFloat());
|
||||
}
|
||||
else item.setDamageValue(nDamage);
|
||||
|
||||
stack.setDamageValue(iDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.MobType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
|
||||
public class DamageIncreaseEnchantment extends Enchantment
|
||||
{
|
||||
protected DamageIncreaseEnchantment(Rarity arg, EnchantmentCategory arg2, EquipmentSlot[] args) {
|
||||
super(arg, arg2, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurse() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTradeable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinLevel() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDiscoverable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamageBonus(int level, MobType mobType, ItemStack enchantedItem) {
|
||||
return (float) Math.pow(0.5, level);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class EnchantmentEvents
|
||||
{
|
||||
static Map<String, Integer> ticks = new HashMap<>();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handleEnchantmentTicks(TickEvent.PlayerTickEvent event)
|
||||
{
|
||||
if(event.side == LogicalSide.CLIENT) return;
|
||||
|
||||
if(event.phase == TickEvent.Phase.END)
|
||||
{
|
||||
if(event.player instanceof ServerPlayer sp)
|
||||
{
|
||||
boolean cont = false;
|
||||
|
||||
if(ticks.containsKey(sp.getStringUUID())){
|
||||
if(ticks.get(sp.getStringUUID()) > 150) {
|
||||
ticks.put(sp.getStringUUID(), 0);
|
||||
cont=true;
|
||||
} else cont=false;
|
||||
} else {
|
||||
// Insert
|
||||
ticks.put(sp.getStringUUID(),0);
|
||||
cont=false;
|
||||
}
|
||||
|
||||
if(!cont) {
|
||||
ticks.put(sp.getStringUUID(), ticks.get(sp.getStringUUID())+1);
|
||||
return;
|
||||
}
|
||||
|
||||
//AriasEssentials.LOGGER.info("ENCHANT TICK - Server Player");
|
||||
|
||||
FlightEnchantment.runEntityTick(sp);
|
||||
ConsumptionMending.onEntityTick(sp);
|
||||
VampiricMending.onTick(sp);
|
||||
NightVisionEnchantment.runEntityTick(sp);
|
||||
WaterBreathingEnchantment.runEntityTick(sp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.effects.ModEffects;
|
||||
import com.zontreck.libzontreck.util.ItemUtils;
|
||||
import com.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
public class FlightEnchantment extends Enchantment
|
||||
{
|
||||
|
||||
public FlightEnchantment(EquipmentSlot... slots)
|
||||
{
|
||||
super(Rarity.VERY_RARE, EnchantmentCategory.ARMOR_FEET, slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinCost(int level)
|
||||
{
|
||||
return 28 + (level - 1) * 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCost(int level)
|
||||
{
|
||||
return this.getMinCost(level) + 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly(){
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isTradeable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not a bug. Flight is meant to be a permanent upgrade to a item. It is considered a curse due to unstable behavior. Flight will eat up durability and forge energy
|
||||
// Flight should NOT be able to be removed via the grindstone
|
||||
@Override
|
||||
public boolean isCurse()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static void runEntityTick(ServerPlayer sp)
|
||||
{
|
||||
if(ServerUtilities.isClient()) return;
|
||||
|
||||
|
||||
if(AEServerConfig.getInstance().enable_debug)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("> Flight Enchantment Tick <");
|
||||
}
|
||||
|
||||
ItemStack feet = sp.getItemBySlot(EquipmentSlot.FEET);
|
||||
|
||||
boolean hasFlight = false;
|
||||
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get(), feet)>0)hasFlight=true;
|
||||
|
||||
if(hasFlight)
|
||||
{
|
||||
MobEffectInstance inst = new MobEffectInstance(ModEffects.FLIGHT.get(), 60*20, 0, false, false, true);
|
||||
MobEffectInstance existing = sp.getEffect(ModEffects.FLIGHT.get());
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
if(existing.getDuration() <= (30 * 20))
|
||||
{
|
||||
sp.addEffect(inst);
|
||||
return;
|
||||
}else return;
|
||||
}
|
||||
|
||||
sp.addEffect(inst);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MobEggEnchantment extends Enchantment
|
||||
{
|
||||
public static final String TAG_BIAS = "mob_egging_bias";
|
||||
|
||||
public MobEggEnchantment()
|
||||
{
|
||||
super(Rarity.VERY_RARE, EnchantmentCategory.WEAPON, new EquipmentSlot[] {EquipmentSlot.MAINHAND});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinCost(int level)
|
||||
{
|
||||
return 28 + (level - 1) * 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCost(int level)
|
||||
{
|
||||
return this.getMinCost(level) + 15;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack)
|
||||
{
|
||||
return super.canApplyAtEnchantingTable(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly(){
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isTradeable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDiscoverable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean givesEgg(int level, int bias)
|
||||
{
|
||||
int CHANCE = AEServerConfig.getInstance().drops.mobEggingChance;
|
||||
|
||||
CHANCE += level;
|
||||
CHANCE += bias;
|
||||
|
||||
if(AEServerConfig.getInstance().enable_debug)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("Spawn Egg Chance (" + CHANCE + ")");
|
||||
}
|
||||
return rollChance(CHANCE);
|
||||
}
|
||||
|
||||
public static boolean rollChance(int percent)
|
||||
{
|
||||
Random rng = new Random();
|
||||
int test = rng.nextInt(100) + 1 + (100 - percent);
|
||||
if(AEServerConfig.getInstance().enable_debug)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("Spawn Egg Dice Roll (" + test + " / " + percent + ")");
|
||||
}
|
||||
|
||||
return test <= percent;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
|
||||
public class ModDamageSources
|
||||
{
|
||||
public static final DamageSource VAMPIRIC_MENDING = new DamageSource("vampiric_mend");
|
||||
}
|
38
src/main/java/com/zontreck/enchantments/ModEnchantments.java
Normal file
38
src/main/java/com/zontreck/enchantments/ModEnchantments.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModEnchantments {
|
||||
|
||||
protected static final EquipmentSlot[] ARMOR_SLOTS = new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET};
|
||||
public static final DeferredRegister<Enchantment> REGISTERS = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, AriasEssentials.MOD_ID);
|
||||
|
||||
public static final RegistryObject<Enchantment> MOB_EGGING_ENCHANTMENT = REGISTERS.register("mob_egging", ()->new MobEggEnchantment());
|
||||
|
||||
public static final RegistryObject<Enchantment> FLIGHT_ENCHANTMENT = REGISTERS.register("player_flight", ()->new FlightEnchantment(EquipmentSlot.FEET));
|
||||
|
||||
|
||||
public static final RegistryObject<Enchantment> CONSUMPTION_MENDING = REGISTERS.register("consumption_mending", ()->new ConsumptionMending(EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.FEET, EquipmentSlot.LEGS, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND));
|
||||
|
||||
|
||||
public static final RegistryObject<Enchantment> NIGHT_VISION_ENCHANT = REGISTERS.register("night_vision", ()->new NightVisionEnchantment(EquipmentSlot.HEAD));
|
||||
|
||||
public static final RegistryObject<Enchantment> WATER_BREATHING_ENCHANT = REGISTERS.register("water_breathing", ()->new WaterBreathingEnchantment(EquipmentSlot.HEAD));
|
||||
|
||||
public static final RegistryObject<Enchantment> WIP_LEVEL_FIELD = REGISTERS.register("extra_strength", ()->new DamageIncreaseEnchantment(Enchantment.Rarity.UNCOMMON, EnchantmentCategory.WEAPON, new EquipmentSlot[] {EquipmentSlot.MAINHAND}));
|
||||
|
||||
public static final RegistryObject<Enchantment> VAMPIRIC_MENDING = REGISTERS.register("vampiric_mend", ()-> new VampiricMending(EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.FEET, EquipmentSlot.LEGS, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND));
|
||||
|
||||
|
||||
|
||||
public static void register(IEventBus bus){
|
||||
REGISTERS.register(bus);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.libzontreck.util.ItemUtils;
|
||||
import com.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
public class NightVisionEnchantment extends Enchantment
|
||||
{
|
||||
|
||||
public NightVisionEnchantment(EquipmentSlot... slots)
|
||||
{
|
||||
super(Rarity.VERY_RARE, EnchantmentCategory.ARMOR_HEAD, slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly(){
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isTradeable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not a bug. Flight is meant to be a permanent upgrade to a item. It is considered a curse due to unstable behavior. Flight will eat up durability and forge energy
|
||||
// Flight should NOT be able to be removed via the grindstone
|
||||
@Override
|
||||
public boolean isCurse()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void runEntityTick(ServerPlayer sp)
|
||||
{
|
||||
if(ServerUtilities.isClient()) return;
|
||||
|
||||
|
||||
if(AEServerConfig.getInstance().enable_debug)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("> NVision Enchantment Tick <");
|
||||
}
|
||||
|
||||
|
||||
ItemStack feet = sp.getItemBySlot(EquipmentSlot.HEAD);
|
||||
|
||||
boolean hasNV = false;
|
||||
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.NIGHT_VISION_ENCHANT.get(), feet)>0)hasNV=true;
|
||||
|
||||
if(hasNV)
|
||||
{
|
||||
MobEffectInstance inst = new MobEffectInstance(MobEffects.NIGHT_VISION, 60*20, 4, false, false, true);
|
||||
|
||||
MobEffectInstance existing = sp.getEffect(MobEffects.NIGHT_VISION);
|
||||
if(existing != null)
|
||||
{
|
||||
if(existing.getDuration() <= (30*20))
|
||||
{
|
||||
sp.addEffect(inst);
|
||||
return;
|
||||
}else return;
|
||||
}
|
||||
|
||||
sp.addEffect(inst);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
107
src/main/java/com/zontreck/enchantments/VampiricMending.java
Normal file
107
src/main/java/com/zontreck/enchantments/VampiricMending.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.libzontreck.chat.HoverTip;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.libzontreck.util.ItemUtils;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VampiricMending extends Enchantment
|
||||
{
|
||||
protected VampiricMending(EquipmentSlot... args) {
|
||||
super(Rarity.VERY_RARE, EnchantmentCategory.BREAKABLE, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTradeable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDiscoverable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurse() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void onTick(ServerPlayer player) {
|
||||
List<ItemStack> lst1 = ItemUtils.getPlayerInventory(player);
|
||||
|
||||
for(ItemStack stack : lst1) {
|
||||
if(!stack.isDamageableItem()) {
|
||||
continue; // Not damageable, no way it would have the enchant
|
||||
}
|
||||
|
||||
if(stack.getDamageValue() == 0) continue;
|
||||
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.VAMPIRIC_MENDING.get(), stack) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We can proceed
|
||||
int lvl = ItemUtils.getEnchantmentLevel(ModEnchantments.VAMPIRIC_MENDING.get(), stack);
|
||||
|
||||
// Get the multiplier for number of hearts to drink up
|
||||
float base = 1.0f; // player has 20 hearts / 2 = 10 full hearts
|
||||
float numOfHeartsToTake = base*lvl;
|
||||
float playerHealth = player.getHealth();
|
||||
|
||||
int cLvl = 1;
|
||||
// Calculate the amount needed up to max per enchant level
|
||||
while(cLvl <= lvl) {
|
||||
numOfHeartsToTake = base*cLvl;
|
||||
|
||||
if(lvl == cLvl) break;
|
||||
if(stack.getDamageValue() <= (50 * cLvl)) break;
|
||||
|
||||
cLvl++;
|
||||
}
|
||||
|
||||
// Get corrected number of hearts
|
||||
float numToTake = numOfHeartsToTake;
|
||||
if(playerHealth > numToTake) {
|
||||
// we can take that many hearts
|
||||
player.hurt(ModDamageSources.VAMPIRIC_MENDING, numToTake);
|
||||
} else {
|
||||
numToTake = player.getHealth();
|
||||
player.hurt(ModDamageSources.VAMPIRIC_MENDING, numToTake);
|
||||
|
||||
|
||||
ChatHelpers.broadcast(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + " !Dark_Red!Vampiric Item [Hover Here]").setStyle(Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.getItem(stack))), ServerLifecycleHooks.getCurrentServer());
|
||||
}
|
||||
|
||||
int newDmg = stack.getDamageValue() - (50 * lvl);
|
||||
if(newDmg <= 0) newDmg = 0;
|
||||
stack.setDamageValue(newDmg);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.libzontreck.util.ItemUtils;
|
||||
import com.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
public class WaterBreathingEnchantment extends Enchantment
|
||||
{
|
||||
|
||||
public WaterBreathingEnchantment(EquipmentSlot... slots)
|
||||
{
|
||||
super(Rarity.VERY_RARE, EnchantmentCategory.ARMOR_HEAD, slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly(){
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isTradeable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not a bug. Flight is meant to be a permanent upgrade to a item. It is considered a curse due to unstable behavior. Flight will eat up durability and forge energy
|
||||
// Flight should NOT be able to be removed via the grindstone
|
||||
@Override
|
||||
public boolean isCurse()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void runEntityTick(ServerPlayer sp)
|
||||
{
|
||||
if(ServerUtilities.isClient()) return;
|
||||
|
||||
|
||||
if(AEServerConfig.getInstance().enable_debug)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("> WBreath Enchantment Tick <");
|
||||
}
|
||||
|
||||
|
||||
ItemStack feet = sp.getItemBySlot(EquipmentSlot.HEAD);
|
||||
|
||||
boolean hasEnchantment = false;
|
||||
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.WATER_BREATHING_ENCHANT.get(), feet)>0)hasEnchantment=true;
|
||||
|
||||
if(hasEnchantment)
|
||||
{
|
||||
MobEffectInstance inst = new MobEffectInstance(MobEffects.WATER_BREATHING, 60*20, 4, false, false, true);
|
||||
|
||||
MobEffectInstance existing = sp.getEffect(MobEffects.WATER_BREATHING);
|
||||
if(existing != null)
|
||||
{
|
||||
if(existing.getDuration() <= (30*20))
|
||||
{
|
||||
sp.addEffect(inst);
|
||||
return;
|
||||
}else return;
|
||||
}
|
||||
|
||||
sp.addEffect(inst);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue