Skip to content

Commit

Permalink
Add Zombie Weapon Chance config option
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Sep 3, 2022
1 parent b0d898f commit aeea74d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.silvercatcher.reforged.api.IZombieEquippable;
import org.silvercatcher.reforged.proxy.CommonProxy;
import org.silvercatcher.reforged.util.Helpers;

public class ReforgedMonsterArmourer {

Expand All @@ -23,11 +25,12 @@ public class ReforgedMonsterArmourer {
*/
private static Item[] zombieWeapons;

private final Random random = new Random();

private void equipZombie(EntityZombie zombie) {
if (zombie.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && random.nextInt(10) == 0) {
Item item = randomFrom(zombieWeapons);
Random random = zombie.world.rand;
int chance = CommonProxy.zombieSpawn;
if (chance != 0 && zombie.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty()
&& random.nextInt(chance) == 0) {
Item item = Helpers.randomFrom(random, zombieWeapons);
zombie.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(item));

zombie.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE)
Expand Down Expand Up @@ -61,7 +64,4 @@ public void onWorldLoad(WorldEvent.Load e) {
zombieWeapons = list.toArray(new Item[0]);
}

private Item randomFrom(Item[] selection) {
return selection[random.nextInt(selection.length)];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class GlobalValues {
public static final boolean KATANA = CommonProxy.katana;
public static final boolean KNIFE = CommonProxy.knife;
public static final boolean MUSKET = CommonProxy.musket;
public static final boolean NEST_OF_BEES = CommonProxy.nest_of_bees;
public static final boolean NEST_OF_BEES = CommonProxy.nestOfBees;
public static final boolean SABRE = CommonProxy.sabre;
public static final boolean KERIS = CommonProxy.keris;
public static final boolean CALTROP = CommonProxy.caltrop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean isOpaqueCube(IBlockState state) {
public void onEntityCollision(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
if (entityIn instanceof EntityLivingBase) {
EntityLivingBase e = (EntityLivingBase) entityIn;
e.attackEntityFrom(new DamageSource("caltrop").setDamageBypassesArmor(), CommonProxy.damage_caltrop);
e.attackEntityFrom(new DamageSource("caltrop").setDamageBypassesArmor(), CommonProxy.damageCaltrop);
if (!worldIn.isRemote)
worldIn.setBlockToAir(pos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public EntityBulletMusket(World worldIn, EntityLivingBase throwerIn) {

@Override
protected float getImpactDamage(Entity target) {
return CommonProxy.damage_musket;
return CommonProxy.damageMusket;
}

@Override
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/org/silvercatcher/reforged/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ public class CommonProxy {
"crossbow_reload", "crossbow_shoot", "musket_shoot", "shotgun_reload", "shotgun_shoot"};

// Items for Config
public static boolean battleaxe, blowgun, boomerang, firerod, javelin, katana, knife, musket, nest_of_bees, sabre,
public static boolean battleaxe, blowgun, boomerang, firerod, javelin, katana, knife, musket, nestOfBees, sabre,
keris, caltrop, dynamite, crossbow, pike, mace, dirk/*, cannon*/;

// Floats for Config
public static float damage_musket, damage_caltrop;
// General stuff for Config
public static float damageMusket, damageCaltrop;
public static int zombieSpawn;

public static final String items = "Items", ids = "IDs", floats = "General";
public static final String items = "Items", ids = "IDs", general = "General";

public static SoundEvent getSound(String name) {
return SoundEvent.REGISTRY.getObject(new ResourceLocation(ReforgedMod.ID, name));
Expand Down Expand Up @@ -76,7 +77,7 @@ private void loadConfig(FMLPreInitializationEvent e) {
katana = config.getBoolean("Katana", items, true, "Enable the Katana");
knife = config.getBoolean("Knife", items, true, "Enable the Knife");
musket = config.getBoolean("Musket", items, true, "Enable the Musket and Blunderbuss");
nest_of_bees = config.getBoolean("Nest Of Bees", items, true, "Enable the Nest Of Bees");
nestOfBees = config.getBoolean("Nest Of Bees", items, true, "Enable the Nest Of Bees");
sabre = config.getBoolean("Sabre", items, true, "Enable the Sabre");
keris = config.getBoolean("Kris", items, true, "Enable the Kris");
caltrop = config.getBoolean("Caltrop", items, true, "Enable the Caltrop");
Expand All @@ -87,9 +88,12 @@ private void loadConfig(FMLPreInitializationEvent e) {
dirk = config.getBoolean("Dirk", items, true, "Enable the Dirk");
//cannon = config.getBoolean("Cannon", items, true, "Enable the Cannon");

// Floats
damage_musket = config.getFloat("Musket Damage", floats, 10, 1, 5000, "Damage of the Musket");
damage_caltrop = config.getFloat("Caltrop Damage", floats, 8, 1, 5000, "Damage of the Caltrop");
// General
damageMusket = config.getFloat("Musket Damage", general, 10, 1, 5000, "Damage of the Musket");
damageCaltrop = config.getFloat("Caltrop Damage", general, 8, 1, 5000, "Damage of the Caltrop");
zombieSpawn = config.getInt("Zombie Weapon Chance", general, 50, 0, 500000,
"Chance that a Zombie spawns with a Reforged weapon. Set to 0 to disable. A value of n means that a "
+ "Zombie has a chance of 1/n to hold a weapon.");

// Save config
config.save();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/silvercatcher/reforged/util/Helpers.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.silvercatcher.reforged.util;

import java.util.List;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
Expand Down Expand Up @@ -191,4 +192,8 @@ public static void playSound(World w, Entity e, String name, float volume, float
w.playSound(null, e.posX, e.posY, e.posZ, CommonProxy.getSound(name), SoundCategory.MASTER, volume, pitch);
}

public static <T> T randomFrom(Random random, T[] selection) {
return selection[random.nextInt(selection.length)];
}

}

0 comments on commit aeea74d

Please sign in to comment.