Skip to content

Commit

Permalink
Fix game launch
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Sep 20, 2024
1 parent fa3576a commit 319e481
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public class ConfigDebugSingleEvents implements IConfig
*/
public static boolean DebugActionPanicToIdLog = false;

/**
*
* @param nameClass
*/
public ConfigDebugSingleEvents(final String nameClass)
{

}

/**
*
* @param event
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.imesense.dynamicspawncontrol.technical.eventprocessor.single;

import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.imesense.dynamicspawncontrol.technical.configs.ConfigZombieDropItem;
import org.imesense.dynamicspawncontrol.technical.customlibrary.Log;

import java.util.List;
import java.util.Random;

/**
*
*/
@Mod.EventBusSubscriber
public final class OnDropZombieItems
{
/**
*
* @param nameClass
*/
public OnDropZombieItems(final String nameClass)
{
Log.writeDataToLogFile(Log.TypeLog[0], nameClass);
}

/**
*
* @param event
*/
@SubscribeEvent(priority = EventPriority.LOWEST)
public synchronized void onUpdateLivingDropsEvent_0(LivingDropsEvent event)
{
if (event.getEntity() instanceof EntityZombie)
{
EntityZombie zombie = (EntityZombie)event.getEntity();

List<EntityItem> drops = event.getDrops();

addDamagedItemToDrops(zombie, drops, zombie.getItemStackFromSlot(EntityEquipmentSlot.HEAD), ConfigZombieDropItem.HeadDamageFactor);
addDamagedItemToDrops(zombie, drops, zombie.getItemStackFromSlot(EntityEquipmentSlot.CHEST), ConfigZombieDropItem.ChestDamageFactor);
addDamagedItemToDrops(zombie, drops, zombie.getItemStackFromSlot(EntityEquipmentSlot.LEGS), ConfigZombieDropItem.LegsDamageFactor);
addDamagedItemToDrops(zombie, drops, zombie.getItemStackFromSlot(EntityEquipmentSlot.FEET), ConfigZombieDropItem.FeetDamageFactor);

addDamagedItemToDrops(zombie, drops, zombie.getHeldItemMainhand(), ConfigZombieDropItem.HandItemDamageFactor);
}
}

/**
*
* @param _zombie
* @param _drops
* @param _originalItem
* @param damageFactor
*/
private void addDamagedItemToDrops(EntityZombie _zombie, List<EntityItem> _drops, ItemStack _originalItem, double damageFactor)
{
if (_originalItem.getItem() != Items.AIR)
{
if (new Random().nextDouble() < ConfigZombieDropItem.BreakItem)
{
return;
}

ItemStack damagedItem = _originalItem.copy();
int maxDamage = damagedItem.getMaxDamage();

if (maxDamage > 0)
{
Random rand = new Random();
int minDamage = (int)(maxDamage * damageFactor);

int damageSpread = (int)(maxDamage * ConfigZombieDropItem.DamageSpreadFactor);
int randomDamage = minDamage + rand.nextInt(damageSpread);

damagedItem.setItemDamage(randomDamage);
}

for (EntityItem item : _drops)
{
ItemStack stack = item.getItem();

if (stack.isItemEqualIgnoreDurability(damagedItem))
{
return;
}
}

_drops.add(new EntityItem(_zombie.world, _zombie.posX, _zombie.posY, _zombie.posZ, damagedItem));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,40 @@ public static void init(FMLPreInitializationEvent event)
{
try
{
Log.writeDataToLogFile(Log.TypeLog[0], "---------------------------------------------");
Log.writeDataToLogFile(Log.TypeLog[0], "Start reading class: " + configClass.getName());

if (!hasConstructorWithParameter(configClass, String.class))
{
throw new NoSuchMethodException("Class " + configClass.getName() + " does not have a constructor with a String parameter.");
}

Object configInstance = configClass.getConstructor(String.class).newInstance(configClass.getSimpleName());

((IConfig)configInstance).init(event, configClass.getSimpleName());

Log.writeDataToLogFile(Log.TypeLog[0], String.format("configInstance (%s)", configInstance));
Log.writeDataToLogFile(Log.TypeLog[0], String.format("Config instance created: %s", configInstance));

Log.writeDataToLogFile(Log.TypeLog[0], "End reading class: " + configClass.getName());
Log.writeDataToLogFile(Log.TypeLog[0], "---------------------------------------------");
}
catch (Exception exception)
{
Log.writeDataToLogFile(Log.TypeLog[2], "Exception in class: " + configClass.getName() + " - " + exception.getMessage());
}
}
}

private static boolean hasConstructorWithParameter(Class<?> clazz, Class<?>... parameterTypes)
{
try
{
clazz.getConstructor(parameterTypes);
return true;
}
catch (NoSuchMethodException e)
{
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraftforge.common.MinecraftForge;
import org.imesense.dynamicspawncontrol.gameplay.events.OnUpdateTorchLogic;
import org.imesense.dynamicspawncontrol.technical.customlibrary.Log;
import org.imesense.dynamicspawncontrol.technical.eventprocessor.single.OnDropZombieItems;

/**
*
Expand All @@ -14,7 +15,8 @@ public final class RegisterGameplayClasses
*/
private static final Class<?>[] EVENT_CLASSES =
{
OnUpdateTorchLogic.class
OnUpdateTorchLogic.class,
OnDropZombieItems.class
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public void postInit(FMLPostInitializationEvent event)
{
CodeGenericUtils.checkObjectNotNull(ConfigLogFile, "ConfigLogFile").save();
CodeGenericUtils.checkObjectNotNull(ConfigGameDebugger, "ConfigGameDebugger").save();
CodeGenericUtils.checkObjectNotNull(ConfigDebugSingleEvents, "ConfigDebugSingleEvents").save();
CodeGenericUtils.checkObjectNotNull(ConfigOreGeneratorFile, "ConfigOreGeneratorFile").save();
CodeGenericUtils.checkObjectNotNull(ConfigNights, "ConfigNights").save();
CodeGenericUtils.checkObjectNotNull(ConfigWorldTime, "ConfigWorldTime").save();
CodeGenericUtils.checkObjectNotNull(ConfigPlayer, "ConfigPlayer").save();
CodeGenericUtils.checkObjectNotNull(ConfigZombieDropItem, "ConfigZombieDropItem").save();
CodeGenericUtils.checkObjectNotNull(ConfigDebugSingleEvents, "ConfigDebugSingleEvents").save();
}

/**
Expand Down

0 comments on commit 319e481

Please sign in to comment.