Skip to content

Commit

Permalink
adding trait crafting
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Jan 11, 2024
1 parent f87d3a0 commit 09c7e3e
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 25 deletions.
36 changes: 18 additions & 18 deletions MODIFIERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@ This is a full list of modifiers in the game and a description of what they do.
These effects are applied when breaking blocks.
### Magnetic
Upon breaking a block (allowed by tool type), all items at that block's position will teleport to you.
### Learning
After breaking 10 blocks as allowed by this tool, gain 3 experience points.
### Veiny
Breaking any block while crouching will cause all blocks of the same type adjacent to it to break up to 5 in each direction.
### Learning
After breaking 10 blocks as allowed by this tool, gain 3 experience points.
## Holders
These effects are applied when holding the tool.
### Detecting
While holding the tool, ores around you will glow.
### Rainy
While holding the tool in the rain, mine faster!
### Filling
While holding the tool, get the saturation effect.
### Hasty
While holding the tool, get the Haste effect.
### Rainy
While holding the tool in the rain, mine faster!
### Detecting
While holding the tool, ores around you will glow.
### Tomb Raider
While holding the spawners around you will glow.
### Appley
While holding the tool, get the absorption effect.
### Filling
While holding the tool, get the saturation effect.
## Users
These effects are applied when right clicking.
### Heartha's Grace
Right clicking on the top of a block with the tool in hand will place a dirt block and use 1 durability points.
### Spelunking
Right clicking on the top of a block with the tool in hand will place a torch and use 10 durability points.
### Heartha's Grace
Right clicking on the top of a block with the tool in hand will place a dirt block and use 1 durability points.
### Fire Starter
Right clicking on the top of a block while crouching with the tool in hand will start a fire and use 2 durability points.
## Hurters
These effects are applied when hurting enemies.
### Withering
When attacking with tool, apply the wither effect to the target.
### Charged
After 7 seconds, hitting and enemy will summon a lightning bolt and empty the charge meter.
### Dexterous
Hitting enemies within 2 seconds after hitting them deals an extra 25% damage.
### Poisonous
When attacking with tool, apply the poison effect to the target.
### Charged
After 7 seconds, hitting and enemy will summon a lightning bolt and empty the charge meter.
### Withering
When attacking with tool, apply the wither effect to the target.
### Blinding
When attacking with tool, apply the blindness effect to the target.
### Necrotic
Heals 10% of damage dealt to target.
### Dexterous
Hitting enemies within 2 seconds after hitting them deals an extra 25% damage.
### Flaming
Sets enemy on fire for 2 seconds.
### Blinding
When attacking with tool, apply the blindness effect to the target.
### Critical
Always critically strikes enemy.
44 changes: 37 additions & 7 deletions src/main/java/dev/marston/randomloot/RandomLootMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@

import dev.marston.randomloot.loot.LootRegistry;
import dev.marston.randomloot.loot.LootUtils;
import dev.marston.randomloot.recipes.Recipies;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.FireworkStarRecipe;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
Expand All @@ -40,20 +46,43 @@ public class RandomLootMod {

public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister
.create(Registries.CREATIVE_MODE_TAB, MODID);

public static final DeferredRegister<RecipeSerializer<?>> RECIPE_SERIALIZERS = DeferredRegister
.create(Registries.RECIPE_SERIALIZER, MODID);

static RandomLootMod INSTANCE;


public RandomLootMod() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

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

ModLootModifiers.register(modEventBus);


if (INSTANCE != null) {
throw new IllegalStateException();
}
INSTANCE = this;

IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();



bus.addListener((RegisterEvent event) -> {
if (!event.getRegistryKey().equals(Registries.BLOCK)) {
return;
}
Recipies.init(ForgeRegistries.RECIPE_SERIALIZERS);
});


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

MinecraftForge.EVENT_BUS.register(this);

ModLootModifiers.register(bus);

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.SPEC);

GenWiki.genWiki();

}

private void commonSetup(final FMLCommonSetupEvent event) {
Expand Down Expand Up @@ -105,6 +134,7 @@ public static void registerItems(RegisterEvent event) {
});

}


}
}
4 changes: 4 additions & 0 deletions src/main/java/dev/marston/randomloot/loot/LootItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ public float getDestroySpeed(ItemStack stack, BlockState block) {
return block.is(blocks) ? getDigSpeed(stack, type) : 1.0F;
}

@Override
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
return true;
}

@Override
public boolean isRepairable(ItemStack stack) {
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/dev/marston/randomloot/loot/LootUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ public static float getTexture(ItemStack stack) {

return index;
}


public static int getTextureIndex(ItemStack stack) {
CompoundTag cosmeticTag = stack.getOrCreateTagElement("cosmetics");

int texture = cosmeticTag.getInt("texture");

return texture;
}

private static void generateLore(ItemStack lootItem, Level level, Player player) {
Holder<Biome> biome = level.getBiome(player.blockPosition());
Expand Down Expand Up @@ -344,6 +353,43 @@ public static void generateInitialTraits(ItemStack stack, ToolType type, int cou
generateNewTrait(stack, getToolType(stack));
}
}

public static int getToolMaxTextures(ItemStack stack) {
ToolType m = getToolType(stack);

return switch (m) {
case PICKAXE: {
yield PICKAXE_COUNT;
}
case AXE: {
yield AXE_COUNT;
}
case SHOVEL: {
yield SHOVEL_COUNT;
}
case SWORD: {
yield SWORD_COUNT;
}
default:
yield 0;
};

}

public static int addToolTextures(ItemStack stack, int count) {
int max = getToolMaxTextures(stack);

int current = getTextureIndex(stack);

int newTexture = (current + count) % max;

return newTexture;

}

public static void addTexture(ItemStack stack, int count) {
setTexture(stack, addToolTextures(stack, count));
}

public static boolean generateTool(Player player, Level level) {
RandomLootMod.LOGGER.info("creating tool with the LootUtils structure...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public void hold(ItemStack stack, Level level, Entity holder) {
}

int size = 10;


for(int i = -size; i < size; i ++) {
for(int j = -size; j < size; j ++) {
for(int k = -size; k < size; k ++) {
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/dev/marston/randomloot/recipes/Recipies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dev.marston.randomloot.recipes;

import dev.marston.randomloot.RandomLootMod;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraftforge.registries.IForgeRegistry;

public final class Recipies {

private Recipies() {

}



public static void init(IForgeRegistry<RecipeSerializer<?>> recipeSerializers) {
RandomLootMod.LOGGER.info("registering recipes!");
register(recipeSerializers, new ResourceLocation(RandomLootMod.MODID, "texture_change_recipe"), TextureChangeRecipe.getMySerializer());
register(recipeSerializers, new ResourceLocation(RandomLootMod.MODID, "trait_poison"), TraitAdditionRecipe.getMySerializer());

}

private static void register(IForgeRegistry<RecipeSerializer<?>> registry, ResourceLocation id,
RecipeSerializer<?> serializer) {
registry.register(id, serializer);
}
}

108 changes: 108 additions & 0 deletions src/main/java/dev/marston/randomloot/recipes/TextureChangeRecipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package dev.marston.randomloot.recipes;

import dev.marston.randomloot.RandomLootMod;
import dev.marston.randomloot.loot.LootRegistry;
import dev.marston.randomloot.loot.LootUtils;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.CraftingBookCategory;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
import net.minecraft.world.level.Level;

public class TextureChangeRecipe extends CustomRecipe {
public static SimpleCraftingRecipeSerializer<TextureChangeRecipe> SERIALIZER = null;

private static final Ingredient CHANGE_TEXTURE_INGREDIENT = Ingredient.of(Items.AMETHYST_SHARD);
private static final Item ITEM = LootRegistry.ToolItem;

public TextureChangeRecipe(ResourceLocation name, CraftingBookCategory cat) {
super(name, cat);
}

@Override
public boolean matches(CraftingContainer inv, Level level) {
return !this.getOutput(inv).isEmpty();
}

private ItemStack getOutput(Container inv) {
RandomLootMod.LOGGER.info("Checking recipe output!");
int size = inv.getContainerSize();

int modCount = 0;
ItemStack toolItem = null;

for(int i = 0; i < size; i ++) {
ItemStack item = inv.getItem(i);
if (item.isEmpty()) { // skip empty items
RandomLootMod.LOGGER.info("skipping empty item");
continue;
}

if (ITEM == item.getItem()) {
if (toolItem != null) {
RandomLootMod.LOGGER.info("can't have two tools");
return ItemStack.EMPTY;
}
RandomLootMod.LOGGER.info("found our tool!");
toolItem = item.copy();
continue;
}

if (CHANGE_TEXTURE_INGREDIENT.test(item)) {
modCount ++;
}


}

if (toolItem == null) {
RandomLootMod.LOGGER.info("needs to have at least one tool");
return ItemStack.EMPTY;
}

if (modCount == 0 ) {
RandomLootMod.LOGGER.info("no modifiers");
return ItemStack.EMPTY;
}

LootUtils.addTexture(toolItem, modCount);

return toolItem;

}

@Override
public ItemStack assemble(CraftingContainer inv, RegistryAccess registryAccess) {
return this.getOutput(inv);
}

@Override
public boolean canCraftInDimensions(int width, int height) {
return false;
}



@Override
public RecipeSerializer<?> getSerializer() {
return getMySerializer();
}

public static RecipeSerializer<?> getMySerializer() {
RandomLootMod.LOGGER.info("Getting TextureChange Serializer!!!");
if (SERIALIZER == null) {
SERIALIZER = new SimpleCraftingRecipeSerializer<TextureChangeRecipe>(
(name, category) -> new TextureChangeRecipe(name, category));
}
return SERIALIZER;
}

}
Loading

0 comments on commit 09c7e3e

Please sign in to comment.