Skip to content

Commit

Permalink
New mechanics of drop heads from entities
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Oct 25, 2024
1 parent 1f369e4 commit aa49c65
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -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;

/**
*
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@
*/
public final class MultipleKeyWord
{
/*
* *********************************************************************************************************************
* Общие ключевые слова
* *********************************************************************************************************************
*/
public static class CommonKeyWorlds
{
/*
* Текущий игровой мир
*/
public static final AttributeKey<Integer> ID_RULE = AttributeKey.create(AttributeType.INTEGER, "id_rule");
public static final AttributeKey<Boolean> SEE_SKY = AttributeKey.create(AttributeType.BOOLEAN, "see_sky");
public static final AttributeKey<String> WEATHER = AttributeKey.create(AttributeType.STRING, "weather");
Expand All @@ -26,70 +18,37 @@ public static class CommonKeyWorlds
public static final AttributeKey<String> BIOMES_TYPE = AttributeKey.create(AttributeType.STRING, "biomes_type");
public static final AttributeKey<Integer> DIMENSION = AttributeKey.create(AttributeType.INTEGER, "dimension");

/*
* Экипировка игрока
*/
public static final AttributeKey<String> HELMET = AttributeKey.create(AttributeType.JSON, "helmet");
public static final AttributeKey<String> CHEST_PLATE = AttributeKey.create(AttributeType.JSON, "chest_plate");
public static final AttributeKey<String> LEGGINGS = AttributeKey.create(AttributeType.JSON, "leggings");
public static final AttributeKey<String> BOOTS = AttributeKey.create(AttributeType.JSON, "boots");

/*
* Минимальное/максимальное время
*/
public static final AttributeKey<Integer> MIN_TIME = AttributeKey.create(AttributeType.INTEGER, "min_world_time");
public static final AttributeKey<Integer> MAX_TIME = AttributeKey.create(AttributeType.INTEGER, "max_world_time");

/*
* Минимальный/максимальный свет
*/
public static final AttributeKey<Integer> MIN_LIGHT = AttributeKey.create(AttributeType.INTEGER, "min_light");
public static final AttributeKey<Integer> MAX_LIGHT = AttributeKey.create(AttributeType.INTEGER, "max_light");

/*
* Минимальная/максимальная высота
*/
public static final AttributeKey<Integer> MIN_HEIGHT = AttributeKey.create(AttributeType.INTEGER, "min_height");
public static final AttributeKey<Integer> MAX_HEIGHT = AttributeKey.create(AttributeType.INTEGER, "max_height");

/*
* Минимальная/максимальная сложность в мире
*/
public static final AttributeKey<String> DIFFICULTY = AttributeKey.create(AttributeType.STRING, "difficulty");
public static final AttributeKey<Float> MIN_DIFFICULTY = AttributeKey.create(AttributeType.FLOAT, "min_difficulty");
public static final AttributeKey<Float> MAX_DIFFICULTY = AttributeKey.create(AttributeType.FLOAT, "max_difficulty");

/*
* Минимальная/максимальная дистанция спавна
*/
public static final AttributeKey<Float> MIN_SPAWN_DIST = AttributeKey.create(AttributeType.FLOAT, "min_spawn_dist");
public static final AttributeKey<Float> MAX_SPAWN_DIST = AttributeKey.create(AttributeType.FLOAT, "max_spawn_dist");

/*
* Блок и положение блока в мире
*/
public static final AttributeKey<String> BLOCK = AttributeKey.create(AttributeType.JSON, "block");
public static final AttributeKey<String> BLOCK_OFFSET = AttributeKey.create(AttributeType.JSON, "block_offset");

/*
* Активная фаза луны
*/
public static final AttributeKey<Integer> GET_MOON_PHASE = AttributeKey.create(AttributeType.INTEGER, "moon_phase");

/*
* Определение живого существа
*/
public static final AttributeKey<String> MOB = AttributeKey.create(AttributeType.STRING, "mob");

/*
* Глобальный тип живых существ
*/
public static final AttributeKey<Boolean> ANIMALS = AttributeKey.create(AttributeType.BOOLEAN, "animals");
public static final AttributeKey<Boolean> MONSTERS = AttributeKey.create(AttributeType.BOOLEAN, "monsters");

/*
* Определение того, что действие выполнил игрок
*/
public static final AttributeKey<Boolean> PLAYER = AttributeKey.create(AttributeType.BOOLEAN, "player");
public static final AttributeKey<Boolean> FAKE_PLAYER = AttributeKey.create(AttributeType.BOOLEAN, "fake_player");
public static final AttributeKey<Boolean> REAL_PLAYER = AttributeKey.create(AttributeType.BOOLEAN, "real_player");
Expand All @@ -98,32 +57,20 @@ public static class CommonKeyWorlds
public static final AttributeKey<String> OFF_HAND_ITEM = AttributeKey.create(AttributeType.JSON, "off_hand_item");
public static final AttributeKey<String> BOTH_HANDS_ITEM = AttributeKey.create(AttributeType.JSON, "both_hands_item");

/*
* Проверка на вид повреждения
*/
public static final AttributeKey<Boolean> EXPLOSION = AttributeKey.create(AttributeType.BOOLEAN, "explosion");
public static final AttributeKey<Boolean> PROJECTILE = AttributeKey.create(AttributeType.BOOLEAN, "projectile");
public static final AttributeKey<Boolean> FIRE = AttributeKey.create(AttributeType.BOOLEAN, "fire");
public static final AttributeKey<Boolean> MAGIC = AttributeKey.create(AttributeType.BOOLEAN, "magic");
public static final AttributeKey<String> SOURCE = AttributeKey.create(AttributeType.STRING, "source");

/*
* Ключи рандомайзера для определения шансов действия
*/
public static final AttributeKey<Float> RANDOM_KEY_0 = AttributeKey.create(AttributeType.FLOAT, "random_key_0");
public static final AttributeKey<Float> RANDOM_KEY_1 = AttributeKey.create(AttributeType.FLOAT, "random_key_1");
public static final AttributeKey<Float> RANDOM_KEY_2 = AttributeKey.create(AttributeType.FLOAT, "random_key_2");
public static final AttributeKey<Float> RANDOM_KEY_3 = AttributeKey.create(AttributeType.FLOAT, "random_key_3");
public static final AttributeKey<Float> RANDOM_KEY_4 = AttributeKey.create(AttributeType.FLOAT, "random_key_4");

/*
* Условия на срабатывания блоков кода
*/
public static final AttributeKey<String> ACTION_RESULT = AttributeKey.create(AttributeType.STRING, "return");

/*
* Мировые действия
*/
public static final AttributeKey<String> ACTION_MESSAGE = AttributeKey.create(AttributeType.STRING, "message");
public static final AttributeKey<Boolean> ACTION_ANGRY = AttributeKey.create(AttributeType.BOOLEAN, "angry");
public static final AttributeKey<String> ACTION_HELD_ITEM = AttributeKey.create(AttributeType.JSON, "mob_held_item");
Expand Down Expand Up @@ -152,23 +99,13 @@ public static class CommonKeyWorlds
public static final AttributeKey<String> ACTION_DAMAGE = AttributeKey.create(AttributeType.STRING, "damage");
}

/*
* *********************************************************************************************************************
* Индивидуальные ключевые слова (SpawnConditions.json/ZombieSummonAid.json)
* *********************************************************************************************************************
*/
public static class SpawnCondition
{
public static final AttributeKey<Boolean> CAN_SPAWN_HERE = AttributeKey.create(AttributeType.BOOLEAN, "can_spawn_here");
public static final AttributeKey<Boolean> NOT_COLLIDING = AttributeKey.create(AttributeType.BOOLEAN, "not_colliding");
public static final AttributeKey<Boolean> SPAWNER = AttributeKey.create(AttributeType.BOOLEAN, "spawner");
}

/*
* *********************************************************************************************************************
* Индивидуальные ключевые слова (MainPotentialSpawn.json)
* *********************************************************************************************************************
*/
public static class PotentialSpawn
{
public static AttributeKey<?> MOB_STRUCT = AttributeKey.create(AttributeType.MAP, "struct");
Expand All @@ -181,11 +118,6 @@ public static class PotentialSpawn
public static AttributeKey<Integer> MOB_GROUP_COUNT_MAX = AttributeKey.create(AttributeType.INTEGER, "group_count_max");
}

/*
* *********************************************************************************************************************
* Индивидуальные ключевые слова (MobTaskManager.json)
* *********************************************************************************************************************
*/
public static class MobTaskManager
{
public static final AttributeKey<String> ENEMIES_TO = AttributeKey.create(AttributeType.STRING, "enemies_to");
Expand All @@ -196,11 +128,6 @@ public static class MobTaskManager
public static final AttributeKey<String> THEM_ID = AttributeKey.create(AttributeType.STRING, "them_id");
}

/*
* *********************************************************************************************************************
* Индивидуальные ключевые слова (DropAllItems.json)
* *********************************************************************************************************************
*/
public static class DroopLoot
{
public static final AttributeKey<String> ACTION_ITEM = AttributeKey.create(AttributeType.STRING, "item");
Expand Down

0 comments on commit aa49c65

Please sign in to comment.