Merge 1.19 updates with 1.20 codebase

This commit is contained in:
Zontreck 2024-02-14 02:01:25 -07:00
parent 1fbd10471f
commit 0ba1e6e73e
344 changed files with 5441 additions and 2787 deletions

View file

@ -0,0 +1,165 @@
package dev.zontreck.otemod.enchantments;
import dev.zontreck.libzontreck.util.ItemUtils;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.TagKey;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.MendingEnchantment;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.server.ServerLifecycleHooks;
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 = new ArrayList<>();
enchanted.addAll(append(player, player.getInventory().items));
enchanted.addAll(append(player, player.getInventory().armor));
List<ItemStack> procList = new ArrayList<>();
procList.addAll(append(player, player.getInventory().offhand));
procList.addAll(append(player, player.getInventory().items));
for(ItemStack stack : enchanted)
{
for(ItemStack item : player.getInventory().items)
{
// 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(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.serverLevel().playSound(null, player.getOnPos(), SoundEvents.ANVIL_USE, SoundSource.NEUTRAL,1, player.getRandom().nextFloat());
}
}
}
item.shrink(1);
player.serverLevel().playSound(null, player.getOnPos(), SoundEvents.PLAYER_BURP, SoundSource.NEUTRAL,1, player.getRandom().nextFloat());
}
else item.setDamageValue(nDamage);
stack.setDamageValue(iDamage);
}
}
}
}
}

View file

@ -0,0 +1,39 @@
package dev.zontreck.otemod.enchantments;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.server.ServerLifecycleHooks;
@Mod.EventBusSubscriber
public class EnchantmentEvents
{
private static boolean canTick = false;
@SubscribeEvent
public static void onServerTick(TickEvent.ServerTickEvent event)
{
if(event.phase == TickEvent.Phase.START)
{
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
canTick = server!=null && server.getTickCount()%20==0;
}
}
@SubscribeEvent
public static void onTick(LivingEvent.LivingTickEvent tick)
{
if(canTick)
{
// Process Enchantments
if(tick.getEntity() instanceof ServerPlayer sp)
{
FlightEnchantment.runEntityTick(sp);
ConsumptionMending.onEntityTick(sp);
}
}
}
}

View file

@ -1,6 +1,7 @@
package dev.zontreck.otemod.enchantments;
import dev.zontreck.libzontreck.util.ItemUtils;
import dev.zontreck.libzontreck.util.ServerUtilities;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.effects.ModEffects;
@ -28,7 +29,6 @@ import net.minecraftforge.fml.common.Mod;
import java.util.concurrent.atomic.AtomicInteger;
@Mod.EventBusSubscriber(modid = OTEMod.MOD_ID)
public class FlightEnchantment extends Enchantment
{
@ -75,10 +75,10 @@ public class FlightEnchantment extends Enchantment
public static AtomicInteger TICKS = new AtomicInteger(0);
@SubscribeEvent
public static void onEnchantmentTick(TickEvent.PlayerTickEvent event)
public static void runEntityTick(ServerPlayer sp)
{
if(event.side == LogicalSide.CLIENT) return;
if(ServerUtilities.isClient()) return;
if(TICKS.getAndIncrement() >= (5*20))
{
@ -91,23 +91,17 @@ public class FlightEnchantment extends Enchantment
OTEMod.LOGGER.info("> Flight Enchantment Tick <");
}
if(event.phase == TickEvent.Phase.END)
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(), -1, 0, false, false, true);
ServerPlayer sp = (ServerPlayer) event.player;
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(), -1, 0, false, false, true);
event.player.addEffect(inst);
}
sp.addEffect(inst);
}
}

View file

@ -20,6 +20,11 @@ public class ModEnchantments {
public static final RegistryObject<Enchantment> BORROWED_PROTECTION = REGISTERS.register("borrowed_protection", ()->new BorrowedProtectionEnchantment(Enchantment.Rarity.UNCOMMON, EnchantmentCategory.ARMOR, ARMOR_SLOTS));
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 void register(IEventBus bus){

View file

@ -1,6 +1,7 @@
package dev.zontreck.otemod.enchantments;
import dev.zontreck.libzontreck.util.ItemUtils;
import dev.zontreck.libzontreck.util.ServerUtilities;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.effects.ModEffects;
@ -19,7 +20,6 @@ import net.minecraftforge.fml.common.Mod;
import java.util.concurrent.atomic.AtomicInteger;
@Mod.EventBusSubscriber(modid = OTEMod.MOD_ID)
public class NightVisionEnchantment extends Enchantment
{
@ -53,10 +53,10 @@ public class NightVisionEnchantment extends Enchantment
}
public static AtomicInteger TICKS = new AtomicInteger(0);
@SubscribeEvent
public static void onEnchantmentTick(TickEvent.PlayerTickEvent event)
public static void runEntityTick(ServerPlayer sp)
{
if(event.side == LogicalSide.CLIENT) return;
if(ServerUtilities.isClient()) return;
if(TICKS.getAndIncrement() >= (2*20))
{
@ -69,23 +69,18 @@ public class NightVisionEnchantment extends Enchantment
OTEMod.LOGGER.info("> NVision Enchantment Tick <");
}
if(event.phase == TickEvent.Phase.END)
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);
ServerPlayer sp = (ServerPlayer) event.player;
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);
event.player.addEffect(inst);
}
sp.addEffect(inst);
}
}