Skip to content

Commit

Permalink
fixing some traits
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Sep 8, 2023
1 parent 8ef5844 commit 5772bc9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/main/java/dev/marston/randomloot/loot/LootItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlo
}

@Override
public boolean hurtEnemy(ItemStack itemstack, LivingEntity p_43279_, LivingEntity p_43280_) {
public boolean hurtEnemy(ItemStack itemstack, LivingEntity hurtee, LivingEntity hurter) {

ToolType type = LootUtils.getToolType(itemstack);

if (type == ToolType.AXE || type == ToolType.SWORD) {
LootUtils.addXp(itemstack, 1);
LootUtils.addXp(itemstack, hurter, 1);

}

Expand All @@ -198,11 +198,11 @@ public boolean hurtEnemy(ItemStack itemstack, LivingEntity p_43279_, LivingEntit
if (mod instanceof EntityHurtModifier) {
EntityHurtModifier ehm = (EntityHurtModifier) mod;

ehm.hurtEnemy(itemstack, p_43279_, p_43280_);
ehm.hurtEnemy(itemstack, hurtee, hurter);
}
}

itemstack.hurtAndBreak(1, p_43280_, (p_43296_) -> {
itemstack.hurtAndBreak(1, hurter, (p_43296_) -> {
p_43296_.broadcastBreakEvent(EquipmentSlot.MAINHAND);
});
return true;
Expand Down Expand Up @@ -230,7 +230,7 @@ public boolean mineBlock(ItemStack stack, Level level, BlockState blockState, Bl
p_40992_.broadcastBreakEvent(EquipmentSlot.MAINHAND);
});

LootUtils.addXp(stack, 1);
LootUtils.addXp(stack, player, 1);

}

Expand Down
42 changes: 26 additions & 16 deletions src/main/java/dev/marston/randomloot/loot/LootUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.stats.StatType;
import net.minecraft.stats.Stats;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
Expand All @@ -28,13 +30,12 @@
import net.minecraft.world.level.biome.Biome;

public class LootUtils {

private static int PICKAXE_COUNT = 18;
private static int AXE_COUNT = 12;
private static int SHOVEL_COUNT = 9;
private static int SWORD_COUNT = 47;


public static void addLoreLine(ListTag lore, String text, String color) {
JsonObject value = Json.createObjectBuilder().add("text", text).add("color", color).add("italic", false)
.build();
Expand Down Expand Up @@ -72,20 +73,28 @@ public static String getItemLore(ItemStack stack) {
}

public static int getMaxXP(int level) {
int xp = (int) (500 * Math.pow(2, level));
int starting = 500;
starting = 10;

int xp = (int) (starting * Math.pow(2, level));
return xp;
}
public static ItemStack levelUp(ItemStack item) {

public static ItemStack levelUp(ItemStack item, LivingEntity holder ) {

float stats = getStats(item);
stats = stats * 1.05f;
stats = stats * 1.1f;
setStats(item, stats);



holder.level().playSound(null, holder.getX(), holder.getY(), holder.getZ(), SoundEvents.PLAYER_LEVELUP, holder.getSoundSource(), 1.0f, 1.0f);


return item;
}

public static ItemStack addXp(ItemStack item, int amount) {
public static ItemStack addXp(ItemStack item, LivingEntity holder, int amount) {

CompoundTag tag = item.getOrCreateTagElement("XP");

Expand All @@ -100,9 +109,12 @@ public static ItemStack addXp(ItemStack item, int amount) {
while (xp >= max) {
xp = xp - max;
level++;
item = levelUp(item);
item = levelUp(item, holder);
}




tag.putInt("level", level);
tag.putInt("xp", xp);

Expand Down Expand Up @@ -161,7 +173,7 @@ public static List<Modifier> getModifiers(ItemStack item) {
if (finalModifier == null) {
continue;
}

tags.add(finalModifier);

}
Expand Down Expand Up @@ -350,15 +362,14 @@ public static void generateTool(Player player, Level level) {
if (player instanceof ServerPlayer) {
ServerPlayer sPlayer = (ServerPlayer) player;
StatType<Item> itemUsed = Stats.ITEM_USED;

count = sPlayer.getStats().getValue(itemUsed.get(LootRegistry.CaseItem));
}

float goodness = (float) Math.sqrt(count + 1); // keeping track of items stats through a "goodness" curve

int traits = (int) (Math.floor(goodness / 2.0f)); // how many traits the tool should be created with


LootUtils.setStats(lootItem, goodness);

int toolType = (int) (Math.random() * 4);
Expand All @@ -379,8 +390,8 @@ public static void generateTool(Player player, Level level) {
yield ToolType.PICKAXE;
}
};
int textureCount = switch (m) {

int textureCount = switch (m) {
case PICKAXE: {
yield PICKAXE_COUNT;
}
Expand All @@ -405,13 +416,12 @@ public static void generateTool(Player player, Level level) {

LootUtils.setTexture(lootItem, (int) (Math.random() * textureCount));


boolean added = player.addItem(lootItem);
if (!added) {
ItemEntity dropItem = new ItemEntity(EntityType.ITEM, level);
dropItem.setItem(lootItem);
dropItem.setPos(player.position());

level.addFreshEntity(dropItem);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class ModifierRegistry {
public static Modifier CHARGING = register(new Charging());
public static Modifier COMBO = register(new Combo());
public static Modifier DRAINING = register(new Draining());
public static Modifier POISONOUS = register(new HurtEffect("Poisonous", "poison", 2, MobEffects.POISON));
public static Modifier WITHERING = register(new HurtEffect("Withering", "wither", 1, MobEffects.WITHER));
public static Modifier BLINDING = register(new HurtEffect("Blinding", "blinding", 3, MobEffects.BLINDNESS));
public static Modifier POISONOUS = register(new HurtEffect("Poisonous", "poison", 5, MobEffects.POISON));
public static Modifier WITHERING = register(new HurtEffect("Withering", "wither", 3, MobEffects.WITHER));
public static Modifier BLINDING = register(new HurtEffect("Blinding", "blinding", 4, MobEffects.BLINDNESS));

public static Modifier HASTY = register(new Hasty());
public static Modifier FILLING = register(new Effect("Filling", "filling", 2, MobEffects.SATURATION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public boolean forTool(ToolType type) {
public void hurtEnemy(ItemStack itemstack, LivingEntity hurtee, LivingEntity hurter) {
float damage = LootItem.getAttackDamage(itemstack, LootUtils.getToolType(itemstack));

hurter.heal(damage * 0.10f);
hurter.heal(damage * 0.25f);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public boolean forTool(ToolType type) {

@Override
public void hurtEnemy(ItemStack itemstack, LivingEntity hurtee, LivingEntity hurter) {
MobEffectInstance eff = new MobEffectInstance(effect, duration * 20, 0, false, false);
MobEffectInstance eff = new MobEffectInstance(effect, duration * 20, 1, false, false);


hurtee.addEffect(eff);

Expand Down

0 comments on commit 5772bc9

Please sign in to comment.