Skip to content

Commit

Permalink
Added some new modifiers, tweaked some old ones
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Sep 6, 2023
1 parent f6f25ed commit 967938a
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 38 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod_name=RandomLoot 2
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=1.0.0
mod_version=0.0.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/dev/marston/randomloot/RandomLootMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public RandomLootMod() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

modEventBus.addListener(this::commonSetup);
modEventBus.addListener(this::addCreative);

ModLootModifiers.register(modEventBus);

Expand All @@ -69,6 +70,12 @@ private void commonSetup(final FMLCommonSetupEvent event) {
LOGGER.info("RandomLoot Common Setup");

}

private void addCreative(BuildCreativeModeTabContentsEvent event)
{
if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES)
event.accept(LootRegistry.CaseItem);
}

@SubscribeEvent
public void onServerStarting(ServerStartingEvent event) {
Expand Down
57 changes: 34 additions & 23 deletions src/main/java/dev/marston/randomloot/loot/LootCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

import javax.annotation.Nullable;

import dev.marston.randomloot.RandomLootMod;
import dev.marston.randomloot.loot.modifiers.Modifier;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
Expand All @@ -21,42 +29,45 @@ public class LootCase extends Item {
public LootCase() {
super(new Properties().stacksTo(1));
}

@Override
public boolean isFoil(ItemStack stack) {
return true;
}
return true;
}

@Override
public InteractionResult useOn(UseOnContext useContext) {
ItemStack lootCase = useContext.getItemInHand();
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack lootCase = player.getItemInHand(hand);
lootCase.shrink(1); // removing case from inventory

LootUtils.generateTool(useContext.getPlayer(), useContext.getLevel()); // generate tool and give it to the
// player
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

}
};

thread.start();

return InteractionResult.SUCCESS;
return InteractionResultHolder.success(lootCase);
}




@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tipList, TooltipFlag flag) {

boolean show = Screen.hasShiftDown();

if (!show) {
return;
}


MutableComponent comp = MutableComponent.create(ComponentContents.EMPTY);
comp.append("Right-click for loot!");
comp = comp.withStyle(ChatFormatting.GRAY);

tipList.add(comp);

}




}
12 changes: 11 additions & 1 deletion src/main/java/dev/marston/randomloot/loot/LootUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.StatType;
import net.minecraft.stats.Stats;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -391,7 +393,15 @@ public static void generateTool(Player player, Level level) {

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

player.addItem(lootItem);

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

level.addFreshEntity(dropItem);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package dev.marston.randomloot.loot.modifiers;

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

import javax.annotation.Nullable;

import dev.marston.randomloot.loot.LootItem.ToolType;
import net.minecraft.ChatFormatting;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;


Expand Down Expand Up @@ -38,6 +41,28 @@ public static MutableComponent makeComp(Component compIn) {
return comp;
}

public static void TrackEntityParticle(Level level, Entity e, ParticleOptions particleType) {
if (!level.isClientSide) {
Random r = new Random();

ServerLevel sl = ((ServerLevel)level);

for(int i = 0; i < 32; ++i) {
double d0 = (double)(r.nextFloat() * 2.0F - 1.0F);
double d1 = (double)(r.nextFloat() * 2.0F - 1.0F);
double d2 = (double)(r.nextFloat() * 2.0F - 1.0F);
if (!(d0 * d0 + d1 * d1 + d2 * d2 > 1.0D)) {
double d3 = e.getX(d0 / 4.0D);
double d4 = e.getY(0.5D + d1 / 4.0D);
double d5 = e.getZ(d2 / 4.0D);
sl.sendParticles(particleType, d3, d4, d5, 1, d0, d1 + 0.2D, d2, 0.0D);
}
}


}
}

public static final String MODTAG = "modifiers";

static final String NAME = "name";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.marston.randomloot.loot.modifiers.holders.Effect;
import dev.marston.randomloot.loot.modifiers.holders.Hasty;
import dev.marston.randomloot.loot.modifiers.hurter.Charging;
import dev.marston.randomloot.loot.modifiers.hurter.Combo;
import dev.marston.randomloot.loot.modifiers.hurter.Critical;
import dev.marston.randomloot.loot.modifiers.hurter.Fire;
import dev.marston.randomloot.loot.modifiers.users.DirtPlace;
Expand All @@ -33,7 +34,8 @@ public class ModifierRegistry {
public static Modifier FLAMING = register(new Fire());
public static Modifier CRITICAL = register(new Critical());
public static Modifier CHARGING = register(new Charging());

public static Modifier COMBO = register(new Combo());

public static Modifier HASTY = register(new Hasty());
public static Modifier FILLING = register(new Effect("Filling", "filling", 2, MobEffects.SATURATION));
public static Modifier ABSORBTION = register(new Effect("Appley", "absorbtion", 10, MobEffects.ABSORPTION));
Expand All @@ -43,7 +45,7 @@ public class ModifierRegistry {

public static final Set<Modifier> BREAKERS = Set.of(EXPLODE, LEARNING, ATTRACTING);
public static final Set<Modifier> USERS = Set.of(TORCH_PLACE, DIRT_PLACE);
public static final Set<Modifier> HURTERS = Set.of(CRITICAL, CHARGING, FLAMING);
public static final Set<Modifier> HURTERS = Set.of(CRITICAL, CHARGING, FLAMING, COMBO);
public static final Set<Modifier> HOLDERS = Set.of(HASTY, ABSORBTION, FILLING);

public static Modifier register(Modifier modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Explode(String name, float power) {

public Explode() {
this.name = "Explosive";
this.power = 4.0f;
this.power = 2.0f;
}

public Modifier clone() {
Expand Down
Loading

0 comments on commit 967938a

Please sign in to comment.