Skip to content

Commit

Permalink
fixed post-compile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Sep 8, 2023
1 parent 3a659c6 commit 7251d99
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 41 deletions.
47 changes: 31 additions & 16 deletions src/main/java/dev/marston/randomloot/loot/LootCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javax.annotation.Nullable;

import dev.marston.randomloot.RandomLootMod;
import dev.marston.randomloot.loot.modifiers.Modifier;
import net.minecraft.ChatFormatting;
import net.minecraft.core.particles.ParticleTypes;
Expand Down Expand Up @@ -35,32 +36,46 @@ public boolean isFoil(ItemStack stack) {
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack lootCase = player.getItemInHand(hand);
lootCase.shrink(1); // removing case from inventory


if (player instanceof ServerPlayer) {
ServerPlayer sPlayer = (ServerPlayer) player;
StatType<Item> itemUsed = Stats.ITEM_USED;

sPlayer.getStats().increment(sPlayer, itemUsed.get(LootRegistry.CaseItem), 1);
}

Modifier.TrackEntityParticle(level, player, ParticleTypes.CLOUD);

Thread thread = new Thread() {
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
LootUtils.generateTool(player, level); // generate tool and give it to the player

if (!level.isClientSide) {
RandomLootMod.LOGGER.info("Generating tool...");
boolean success = LootUtils.generateTool(player, level); // generate tool and give it to the player
if (success) {
RandomLootMod.LOGGER.info("tool generation complete.");
}
};
// Thread thread = new Thread() {
// public void run() {
// RandomLootMod.LOGGER.info("Starting tool generation thread...");
// try {
// Thread.sleep(100);
// } catch (InterruptedException e) {
// RandomLootMod.LOGGER.error(e.getStackTrace().toString());
// }
// boolean success = LootUtils.generateTool(player, level); // generate tool and give it to the player
// if (success) {
// RandomLootMod.LOGGER.info("tool generation complete.");
// }
// }
// };
//
// thread.start();
}

thread.start();
player.awardStat(Stats.ITEM_USED.get(this));
if (!player.getAbilities().instabuild) {
lootCase.shrink(1);
}

return InteractionResultHolder.success(lootCase);
return InteractionResultHolder.sidedSuccess(lootCase, level.isClientSide());
}

@Override
Expand Down
57 changes: 32 additions & 25 deletions src/main/java/dev/marston/randomloot/loot/LootUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import java.util.Map.Entry;
import java.util.Set;

import javax.json.Json;
import javax.json.JsonObject;
import com.google.gson.JsonObject;

import dev.marston.randomloot.RandomLootMod;
import dev.marston.randomloot.loot.LootItem.ToolType;
import dev.marston.randomloot.loot.modifiers.Modifier;
import dev.marston.randomloot.loot.modifiers.ModifierRegistry;
Expand Down Expand Up @@ -37,18 +37,26 @@ public class LootUtils {
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();
JsonObject value = new JsonObject();

value.addProperty("text", text);
value.addProperty("color", color);
value.addProperty("italic", false);

StringTag nbtName = StringTag.valueOf(value.toString());

lore.add(nbtName);
}

public static void setItemName(ItemStack stack, String name, String color) {
JsonObject value = Json.createObjectBuilder().add("text", name).add("color", color).add("italic", false)
.build();
JsonObject value = new JsonObject();

value.addProperty("text", name);
value.addProperty("color", color);
value.addProperty("italic", false);



StringTag nbtName = StringTag.valueOf(value.toString());

CompoundTag display = stack.getOrCreateTagElement("display");
Expand All @@ -74,22 +82,19 @@ public static String getItemLore(ItemStack stack) {

public static int getMaxXP(int level) {
int starting = 500;
starting = 10;

int xp = (int) (starting * Math.pow(2, level));
return xp;
}

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

float stats = getStats(item);
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);


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

return item;
}
Expand All @@ -112,9 +117,6 @@ public static ItemStack addXp(ItemStack item, LivingEntity holder, int amount) {
item = levelUp(item, holder);
}




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

Expand Down Expand Up @@ -343,7 +345,9 @@ public static void generateInitialTraits(ItemStack stack, ToolType type, int cou
}
}

public static void generateTool(Player player, Level level) {
public static boolean generateTool(Player player, Level level) {
RandomLootMod.LOGGER.info("creating tool with the LootUtils structure...");

ItemStack lootItem = new ItemStack(LootRegistry.ToolItem);

/**
Expand All @@ -359,12 +363,13 @@ public static void generateTool(Player player, Level level) {
* new ones have a clean XP slate so they can level faster again.
*/
int count = 0;
if (player instanceof ServerPlayer) {
ServerPlayer sPlayer = (ServerPlayer) player;
StatType<Item> itemUsed = Stats.ITEM_USED;

count = sPlayer.getStats().getValue(itemUsed.get(LootRegistry.CaseItem));
if (level.isClientSide) {
RandomLootMod.LOGGER.info("won't run on client.");
return false;
}
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

Expand Down Expand Up @@ -412,18 +417,20 @@ public static void generateTool(Player player, Level level) {

generateInitialTraits(lootItem, m, traits);

generateLore(lootItem, level, player);
generateLore(lootItem, level, sPlayer);

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

boolean added = player.addItem(lootItem);
RandomLootMod.LOGGER.info("adding item to inventory...");
boolean added = sPlayer.getInventory().add(lootItem);
if (!added) {
ItemEntity dropItem = new ItemEntity(EntityType.ITEM, level);
dropItem.setItem(lootItem);
dropItem.setPos(player.position());
dropItem.setPos(sPlayer.position());

level.addFreshEntity(dropItem);
}
return true;
}

}

0 comments on commit 7251d99

Please sign in to comment.