From aa49c65603defeea37d4561e649ca351943015ee Mon Sep 17 00:00:00 2001 From: OldSerpskiStalker Date: Fri, 25 Oct 2024 09:19:00 +0500 Subject: [PATCH] New mechanics of drop heads from entities --- .../debug/event/OnEventDummy.java | 74 +++++++++++++++++++ .../customlibrary/MultipleKeyWord.java | 73 ------------------ 2 files changed, 74 insertions(+), 73 deletions(-) diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/debug/event/OnEventDummy.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/debug/event/OnEventDummy.java index fc51ae4..6b7f4e6 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/debug/event/OnEventDummy.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/debug/event/OnEventDummy.java @@ -1,9 +1,29 @@ package org.imesense.dynamicspawncontrol.debug.event; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.init.Enchantments; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; +import net.minecraft.util.DamageSource; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.imesense.dynamicspawncontrol.ProjectStructure; import org.imesense.dynamicspawncontrol.debug.CodeGenericUtil; import org.imesense.dynamicspawncontrol.technical.customlibrary.Log; +import scala.util.Random; + +import java.util.HashSet; /** * @@ -31,4 +51,58 @@ public OnEventDummy() instanceExists = true; } + + @SubscribeEvent + public void onEntityDeath(LivingDeathEvent event) { + if (event.getSource().getTrueSource() instanceof EntityLivingBase) { + EntityLivingBase killer = (EntityLivingBase) event.getSource().getTrueSource(); + Entity entity = event.getEntity(); + + if (entity instanceof EntitySkeleton || entity instanceof EntityZombie || entity instanceof EntityCreeper) { + float dropChance = calculateDropChance(killer); + + if (killer.getRNG().nextFloat() < dropChance) { + dropHead((EntityLivingBase) entity, killer.world); + } + } + } + } + + private float calculateDropChance(EntityLivingBase killer) { + ItemStack heldItem = killer.getHeldItemMainhand(); + float baseChance = 0.0f; + + if (heldItem.getItem() == Items.WOODEN_SWORD) { + baseChance = 0.05f; + } else if (heldItem.getItem() == Items.STONE_SWORD) { + baseChance = 0.10f; + } else if (heldItem.getItem() == Items.IRON_SWORD) { + baseChance = 0.15f; + } else if (heldItem.getItem() == Items.GOLDEN_SWORD) { + baseChance = 0.20f; + } else if (heldItem.getItem() == Items.DIAMOND_SWORD) { + baseChance = 0.30f; + } + + int smiteLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.SMITE, heldItem); + baseChance += smiteLevel * 0.10f; + + return MathHelper.clamp(baseChance, 0.0f, 1.0f); + } + + private void dropHead(EntityLivingBase entity, World world) { + ItemStack headItem = ItemStack.EMPTY; + + if (entity instanceof EntitySkeleton) { + headItem = new ItemStack(Items.SKULL, 1, 0); + } else if (entity instanceof EntityZombie) { + headItem = new ItemStack(Items.SKULL, 1, 2); + } else if (entity instanceof EntityCreeper) { + headItem = new ItemStack(Items.SKULL, 1, 4); + } + + if (!headItem.isEmpty()) { + entity.entityDropItem(headItem, 0); + } + } } diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/MultipleKeyWord.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/MultipleKeyWord.java index 7d9e1f6..bf71edc 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/MultipleKeyWord.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/MultipleKeyWord.java @@ -8,16 +8,8 @@ */ public final class MultipleKeyWord { - /* - * ********************************************************************************************************************* - * Общие ключевые слова - * ********************************************************************************************************************* - */ public static class CommonKeyWorlds { - /* - * Текущий игровой мир - */ public static final AttributeKey ID_RULE = AttributeKey.create(AttributeType.INTEGER, "id_rule"); public static final AttributeKey SEE_SKY = AttributeKey.create(AttributeType.BOOLEAN, "see_sky"); public static final AttributeKey WEATHER = AttributeKey.create(AttributeType.STRING, "weather"); @@ -26,70 +18,37 @@ public static class CommonKeyWorlds public static final AttributeKey BIOMES_TYPE = AttributeKey.create(AttributeType.STRING, "biomes_type"); public static final AttributeKey DIMENSION = AttributeKey.create(AttributeType.INTEGER, "dimension"); - /* - * Экипировка игрока - */ public static final AttributeKey HELMET = AttributeKey.create(AttributeType.JSON, "helmet"); public static final AttributeKey CHEST_PLATE = AttributeKey.create(AttributeType.JSON, "chest_plate"); public static final AttributeKey LEGGINGS = AttributeKey.create(AttributeType.JSON, "leggings"); public static final AttributeKey BOOTS = AttributeKey.create(AttributeType.JSON, "boots"); - /* - * Минимальное/максимальное время - */ public static final AttributeKey MIN_TIME = AttributeKey.create(AttributeType.INTEGER, "min_world_time"); public static final AttributeKey MAX_TIME = AttributeKey.create(AttributeType.INTEGER, "max_world_time"); - /* - * Минимальный/максимальный свет - */ public static final AttributeKey MIN_LIGHT = AttributeKey.create(AttributeType.INTEGER, "min_light"); public static final AttributeKey MAX_LIGHT = AttributeKey.create(AttributeType.INTEGER, "max_light"); - /* - * Минимальная/максимальная высота - */ public static final AttributeKey MIN_HEIGHT = AttributeKey.create(AttributeType.INTEGER, "min_height"); public static final AttributeKey MAX_HEIGHT = AttributeKey.create(AttributeType.INTEGER, "max_height"); - /* - * Минимальная/максимальная сложность в мире - */ public static final AttributeKey DIFFICULTY = AttributeKey.create(AttributeType.STRING, "difficulty"); public static final AttributeKey MIN_DIFFICULTY = AttributeKey.create(AttributeType.FLOAT, "min_difficulty"); public static final AttributeKey MAX_DIFFICULTY = AttributeKey.create(AttributeType.FLOAT, "max_difficulty"); - /* - * Минимальная/максимальная дистанция спавна - */ public static final AttributeKey MIN_SPAWN_DIST = AttributeKey.create(AttributeType.FLOAT, "min_spawn_dist"); public static final AttributeKey MAX_SPAWN_DIST = AttributeKey.create(AttributeType.FLOAT, "max_spawn_dist"); - /* - * Блок и положение блока в мире - */ public static final AttributeKey BLOCK = AttributeKey.create(AttributeType.JSON, "block"); public static final AttributeKey BLOCK_OFFSET = AttributeKey.create(AttributeType.JSON, "block_offset"); - /* - * Активная фаза луны - */ public static final AttributeKey GET_MOON_PHASE = AttributeKey.create(AttributeType.INTEGER, "moon_phase"); - /* - * Определение живого существа - */ public static final AttributeKey MOB = AttributeKey.create(AttributeType.STRING, "mob"); - /* - * Глобальный тип живых существ - */ public static final AttributeKey ANIMALS = AttributeKey.create(AttributeType.BOOLEAN, "animals"); public static final AttributeKey MONSTERS = AttributeKey.create(AttributeType.BOOLEAN, "monsters"); - /* - * Определение того, что действие выполнил игрок - */ public static final AttributeKey PLAYER = AttributeKey.create(AttributeType.BOOLEAN, "player"); public static final AttributeKey FAKE_PLAYER = AttributeKey.create(AttributeType.BOOLEAN, "fake_player"); public static final AttributeKey REAL_PLAYER = AttributeKey.create(AttributeType.BOOLEAN, "real_player"); @@ -98,32 +57,20 @@ public static class CommonKeyWorlds public static final AttributeKey OFF_HAND_ITEM = AttributeKey.create(AttributeType.JSON, "off_hand_item"); public static final AttributeKey BOTH_HANDS_ITEM = AttributeKey.create(AttributeType.JSON, "both_hands_item"); - /* - * Проверка на вид повреждения - */ public static final AttributeKey EXPLOSION = AttributeKey.create(AttributeType.BOOLEAN, "explosion"); public static final AttributeKey PROJECTILE = AttributeKey.create(AttributeType.BOOLEAN, "projectile"); public static final AttributeKey FIRE = AttributeKey.create(AttributeType.BOOLEAN, "fire"); public static final AttributeKey MAGIC = AttributeKey.create(AttributeType.BOOLEAN, "magic"); public static final AttributeKey SOURCE = AttributeKey.create(AttributeType.STRING, "source"); - /* - * Ключи рандомайзера для определения шансов действия - */ public static final AttributeKey RANDOM_KEY_0 = AttributeKey.create(AttributeType.FLOAT, "random_key_0"); public static final AttributeKey RANDOM_KEY_1 = AttributeKey.create(AttributeType.FLOAT, "random_key_1"); public static final AttributeKey RANDOM_KEY_2 = AttributeKey.create(AttributeType.FLOAT, "random_key_2"); public static final AttributeKey RANDOM_KEY_3 = AttributeKey.create(AttributeType.FLOAT, "random_key_3"); public static final AttributeKey RANDOM_KEY_4 = AttributeKey.create(AttributeType.FLOAT, "random_key_4"); - /* - * Условия на срабатывания блоков кода - */ public static final AttributeKey ACTION_RESULT = AttributeKey.create(AttributeType.STRING, "return"); - /* - * Мировые действия - */ public static final AttributeKey ACTION_MESSAGE = AttributeKey.create(AttributeType.STRING, "message"); public static final AttributeKey ACTION_ANGRY = AttributeKey.create(AttributeType.BOOLEAN, "angry"); public static final AttributeKey ACTION_HELD_ITEM = AttributeKey.create(AttributeType.JSON, "mob_held_item"); @@ -152,11 +99,6 @@ public static class CommonKeyWorlds public static final AttributeKey ACTION_DAMAGE = AttributeKey.create(AttributeType.STRING, "damage"); } - /* - * ********************************************************************************************************************* - * Индивидуальные ключевые слова (SpawnConditions.json/ZombieSummonAid.json) - * ********************************************************************************************************************* - */ public static class SpawnCondition { public static final AttributeKey CAN_SPAWN_HERE = AttributeKey.create(AttributeType.BOOLEAN, "can_spawn_here"); @@ -164,11 +106,6 @@ public static class SpawnCondition public static final AttributeKey SPAWNER = AttributeKey.create(AttributeType.BOOLEAN, "spawner"); } - /* - * ********************************************************************************************************************* - * Индивидуальные ключевые слова (MainPotentialSpawn.json) - * ********************************************************************************************************************* - */ public static class PotentialSpawn { public static AttributeKey MOB_STRUCT = AttributeKey.create(AttributeType.MAP, "struct"); @@ -181,11 +118,6 @@ public static class PotentialSpawn public static AttributeKey MOB_GROUP_COUNT_MAX = AttributeKey.create(AttributeType.INTEGER, "group_count_max"); } - /* - * ********************************************************************************************************************* - * Индивидуальные ключевые слова (MobTaskManager.json) - * ********************************************************************************************************************* - */ public static class MobTaskManager { public static final AttributeKey ENEMIES_TO = AttributeKey.create(AttributeType.STRING, "enemies_to"); @@ -196,11 +128,6 @@ public static class MobTaskManager public static final AttributeKey THEM_ID = AttributeKey.create(AttributeType.STRING, "them_id"); } - /* - * ********************************************************************************************************************* - * Индивидуальные ключевые слова (DropAllItems.json) - * ********************************************************************************************************************* - */ public static class DroopLoot { public static final AttributeKey ACTION_ITEM = AttributeKey.create(AttributeType.STRING, "item");