Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement scribe tool #49

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ dependencies {
implementation fg.deobf("com.teamabnormals:blueprint:${minecraft_version}-${blueprint_version}")
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"

compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1"))
implementation(jarJar("io.github.llamalad7:mixinextras-forge:${mixin_extras_version}")) {
jarJar.ranged(it, "[${mixin_extras_version},)")
}

// Compatibilities
runtimeOnly(fg.deobf("maven.modrinth:create:${create_version}"))
implementation(fg.deobf("maven.modrinth:farmers-delight:${farmersdelight_version}"))
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ forge_version=47.1.3
# Mixin
mixingradle_version=0.7-SNAPSHOT
mixin_version=0.8.5
mixin_extras_version=0.4.1

# Other Dependencies
blueprint_version=7.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2024-08-28T12:15:19.543716 oreganized Item Models
// 1.20.1 2024-08-28T12:35:31.5287616 oreganized Item Models
18fcb236eeab67fa16a0014d9af5ba7dd6f9e7c8 assets/oreganized/models/item/black_crystal_glass.json
30bbb36792cb2d3f0a8a399f25238120cdf7e659 assets/oreganized/models/item/black_crystal_glass_pane.json
8dcab59e8c34403761c4aec2c3357b7db80b3f0b assets/oreganized/models/item/blue_crystal_glass.json
Expand Down Expand Up @@ -121,6 +121,7 @@ f7c411b709a3af883b55ceb15524a116468ee0b4 assets/oreganized/models/item/purple_cr
0eb2d49665d43c865870beb62e13499299fd7174 assets/oreganized/models/item/raw_silver_block.json
848e82277b2a6223f4d24e6e8e53fd2769263be0 assets/oreganized/models/item/red_crystal_glass.json
1cbba207d199088dd85850ea56d55d5976e15f3c assets/oreganized/models/item/red_crystal_glass_pane.json
4c384b6c9ca85ea3aa0aca55eea89363d8355bd7 assets/oreganized/models/item/scribe.json
2f15086e7865fc768aa268ec9b3797e818976165 assets/oreganized/models/item/shrapnel_bomb.json
0a859cda7510d7756a43cfdf4bac94b2ed57ddb6 assets/oreganized/models/item/shrapnel_bomb_minecart.json
13ffab906a6704c68eb4fef73382a7b0e0a5d5be assets/oreganized/models/item/silver_ingot.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2024-07-22T22:02:00.7201533 Oreganized Block Tags
// 1.20.1 2024-08-28T12:35:31.5287616 Oreganized Block Tags
7a2d68d81bc5ee59f9a2f4ba68ddb39bfd9c875d data/forge/tags/blocks/glass.json
d96b4f83e03abe39a1b97d92b7818c8f6b2e5c68 data/forge/tags/blocks/glass_panes.json
d062c23ad5308b7de0b2e86f6531ea724530f898 data/forge/tags/blocks/melts_lead.json
Expand Down Expand Up @@ -30,4 +30,5 @@ a4acb3623320f801e89e3451f8b7d9e2246f99d0 data/minecraft/tags/blocks/walls.json
81fb1b18afaa14ae90800b23c32de565d1389bb3 data/oreganized/tags/blocks/crystal_glass.json
f1dfddab1e3f2dec1e7ed1c3fbf9f6a7f261cf08 data/oreganized/tags/blocks/crystal_glass_panes.json
6b73bb0ce38222c428d54ee64e82ffa1d96c64d7 data/oreganized/tags/blocks/fire_source.json
81e3d74d8e9abfe57f1388c75a381dd419a44695 data/oreganized/tags/blocks/mineable/scribe.json
3112fb4a1df2953e2c3572fa47f886bf8e5bd679 data/oreganized/tags/blocks/stone_types/glance.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2024-08-28T12:15:19.5367066 Recipes
// 1.20.1 2024-08-28T12:49:10.1978323 Recipes
c27d3499944bf522a573dc8987582db2d7349b41 data/oreganized/advancements/recipes/brewing/poisonous_potato_from_lead.json
ee5e42ab2e9ac549022fadf1c2cbf9faebc2c53c data/oreganized/advancements/recipes/building_blocks/black_crystal_glass_pane.json
40700c3f2f5c78c617650fdd16e2ba248967353f data/oreganized/advancements/recipes/building_blocks/blue_crystal_glass_pane.json
Expand Down Expand Up @@ -139,6 +139,7 @@ fea94b2bd9d8d2a9ef8e130ad2eb404691da858d data/oreganized/advancements/recipes/re
716ef31e308f24d22ef6dae98e96fe9b16169e9b data/oreganized/advancements/recipes/redstone/lead_trapdoor.json
d8d4342744c72378bf0e7430305569819e8eeef1 data/oreganized/advancements/recipes/redstone/shrapnel_bomb.json
430e8110352b21c77fe0b3cb175b5b3fc4c6e4fd data/oreganized/advancements/recipes/tools/bush_hammer.json
4a68b65b81f872d9396798417f3ff5be886ce70c data/oreganized/advancements/recipes/tools/scribe.json
57cf50f8e6ff4069b2fdc5fcf0e5092b68377468 data/oreganized/advancements/recipes/tools/silver_mirror.json
bd88fa660d3a40c321d3288b127cfe99e795cb6f data/oreganized/advancements/recipes/transportation/shrapnel_bomb_minecart.json
ee154313df45723058ea98bd9cbc74eeb3e1293f data/oreganized/recipes/black_crystal_glass.json
Expand Down Expand Up @@ -227,6 +228,7 @@ de027e6a84b7854012960c27c03f18c22de4cc78 data/oreganized/recipes/raw_lead_block.
7c161f552218843de6033c84fdbcda9f024de464 data/oreganized/recipes/raw_silver_from_block.json
2deee8e79dab0cc6a48f66589d44f3e2ee6df545 data/oreganized/recipes/red_crystal_glass.json
f143419602a22f529db20cea44e5e370e8e4d868 data/oreganized/recipes/red_crystal_glass_pane.json
06ea07eed909dbcff647ac8724355430c1817e0e data/oreganized/recipes/scribe.json
194a5e4bfb1acbb98161ddeb6c0af5b21917e508 data/oreganized/recipes/shrapnel_bomb.json
cedc682018d184f9f9f384afe3b157e6cbfff4b1 data/oreganized/recipes/shrapnel_bomb_minecart.json
07595b3d623aafa3ef700093ec0449ebafa1ed27 data/oreganized/recipes/silver_block.json
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/oreganized/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"item.oreganized.netherite_nugget": "Netherite Nugget",
"item.oreganized.raw_lead": "Raw Lead",
"item.oreganized.raw_silver": "Raw Silver",
"item.oreganized.scribe": "Scribe",
"item.oreganized.shrapnel_bomb_minecart": "Minecart with Shrapnel Bomb",
"item.oreganized.silver_ingot": "Silver Ingot",
"item.oreganized.silver_mirror": "Silver Mirror",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "oreganized:item/scribe"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_amethyst": {
"conditions": {
"items": [
{
"items": [
"minecraft:amethyst_shard"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_silver": {
"conditions": {
"items": [
{
"tag": "forge:ingots/silver"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "oreganized:scribe"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_silver",
"has_amethyst",
"has_the_recipe"
]
],
"rewards": {
"recipes": [
"oreganized:scribe"
]
},
"sends_telemetry_event": false
}
21 changes: 21 additions & 0 deletions src/generated/resources/data/oreganized/recipes/scribe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:crafting_shaped",
"category": "equipment",
"key": {
"A": {
"item": "minecraft:amethyst_shard"
},
"S": {
"tag": "forge:ingots/silver"
}
},
"pattern": [
"A",
"S",
"S"
],
"result": {
"item": "oreganized:scribe"
},
"show_notification": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"values": [
"#forge:glass",
"#forge:obsidian",
"#minecraft:ice",
"#forge:storage_blocks/amethyst"
]
}
1 change: 1 addition & 0 deletions src/main/java/galena/oreganized/Oreganized.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public void buildCreativeModeTabContents(BuildCreativeModeTabContentsEvent event
putBefore(entries, Items.SPYGLASS, OItems.SILVER_MIRROR);
putAfter(entries, Items.TNT_MINECART, OItems.SHRAPNEL_BOMB_MINECART);
putBefore(entries, Items.MUSIC_DISC_5, OItems.MUSIC_DISC_STRUCTURE);
putAfter(entries, Items.SHEARS, OItems.SCRIBE);
}
if (tab == CreativeModeTabs.COMBAT) {
putBefore(entries, Items.NETHERITE_SWORD, OItems.ELECTRUM_SWORD);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package galena.oreganized.content.item;

import com.google.common.collect.ImmutableMap;
import galena.oreganized.OreganizedConfig;
import galena.oreganized.index.OTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/galena/oreganized/content/item/ScribeItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package galena.oreganized.content.item;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

import static galena.oreganized.index.OTags.Blocks.MINEABLE_WITH_SCRIBE;

public class ScribeItem extends Item {

public ScribeItem(Properties properties) {
super(properties);
}

public boolean mineBlock(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity user) {
if (!level.isClientSide && state.getDestroySpeed(level, pos) != 0F) {
stack.hurtAndBreak(1, user, it -> {
it.broadcastBreakEvent(EquipmentSlot.MAINHAND);
});
}

return true;
}

@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
return isCorrectToolForDrops(stack, state) ? 32F : 3F;
}

@Override
public boolean isCorrectToolForDrops(BlockState state) {
return state.is(MINEABLE_WITH_SCRIBE);
}

}
8 changes: 8 additions & 0 deletions src/main/java/galena/oreganized/data/OBlockTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static galena.oreganized.index.OTags.Blocks.CRYSTAL_GLASS_PANES;
import static galena.oreganized.index.OTags.Blocks.FIRE_SOURCE;
import static galena.oreganized.index.OTags.Blocks.MELTS_LEAD;
import static galena.oreganized.index.OTags.Blocks.MINEABLE_WITH_SCRIBE;
import static galena.oreganized.index.OTags.Blocks.ORES_LEAD;
import static galena.oreganized.index.OTags.Blocks.ORES_SILVER;
import static galena.oreganized.index.OTags.Blocks.STONE_TYPES_GLANCE;
Expand All @@ -40,6 +41,7 @@ public OBlockTags(PackOutput output, CompletableFuture<HolderLookup.Provider> fu
return "Oreganized Block Tags";
}

@SuppressWarnings("unchecked")
@Override
protected void addTags(HolderLookup.Provider provider) {
// Oreganized
Expand Down Expand Up @@ -163,5 +165,11 @@ protected void addTags(HolderLookup.Provider provider) {
.add(Blocks.MAGMA_BLOCK)
.addTags(BlockTags.CAMPFIRES)
.addTags(BlockTags.FIRE);

tag(MINEABLE_WITH_SCRIBE)
.addTags(Tags.Blocks.GLASS)
.addTags(Tags.Blocks.OBSIDIAN)
.addTags(BlockTags.ICE)
.addTags(Tags.Blocks.STORAGE_BLOCKS_AMETHYST);
}
}
1 change: 1 addition & 0 deletions src/main/java/galena/oreganized/data/OItemModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected void registerModels() {
normalItem(OItems.LEAD_BOLT);

toolItem(OItems.BUSH_HAMMER);
toolItem(OItems.SCRIBE);
toolItem(OItems.ELECTRUM_SWORD);
toolItem(OItems.ELECTRUM_SHOVEL);
toolItem(OItems.ELECTRUM_PICKAXE);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/galena/oreganized/data/ORecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,15 @@ protected void buildRecipes(Consumer<FinishedRecipe> consumer) {
.pattern("###")
.unlockedBy("has_lead", has(OTags.Items.INGOTS_LEAD))
.save(consumer);

ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, OItems.SCRIBE.get())
.define('A', Items.AMETHYST_SHARD)
.define('S', OTags.Items.INGOTS_SILVER)
.pattern("A")
.pattern("S")
.pattern("S")
.unlockedBy("has_silver", has(OTags.Items.INGOTS_SILVER))
.unlockedBy("has_amethyst", has(Items.AMETHYST_SHARD))
.save(consumer);
}
}
2 changes: 2 additions & 0 deletions src/main/java/galena/oreganized/index/OItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import galena.oreganized.content.item.LeadBoltItem;
import galena.oreganized.content.item.MinecartShrapnelBombItem;
import galena.oreganized.content.item.OSmithingTemplateItem;
import galena.oreganized.content.item.ScribeItem;
import galena.oreganized.content.item.SilverMirrorItem;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.item.ArmorItem;
Expand Down Expand Up @@ -58,6 +59,7 @@ public static Supplier<? extends Item> compat(String modid, Supplier<? extends I

// Tools
public static final RegistryObject<Item> BUSH_HAMMER = HELPER.createItem("bush_hammer", () -> new BushHammerItem(OItemTiers.LEAD, 2.5F, -2.8F, (new Item.Properties()).stacksTo(1)));
public static final RegistryObject<Item> SCRIBE = HELPER.createItem("scribe", () -> new ScribeItem(new Item.Properties().stacksTo(1)));

public static final RegistryObject<Item> ELECTRUM_SWORD = HELPER.createItem("electrum_sword", () -> new SwordItem(OItemTiers.ELECTRUM, 3, -2.2F, (new Item.Properties())));
public static final RegistryObject<Item> ELECTRUM_SHOVEL = HELPER.createItem("electrum_shovel", () -> new ShovelItem(OItemTiers.ELECTRUM, 1.5F, -2.8F, (new Item.Properties())));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/galena/oreganized/index/OTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private static TagKey<Item> forgeTag(String name) {
public static class Blocks {

public static final TagKey<Block> MINEABLE_WITH_BUSH_HAMMER = tag("mineable/bush_hammer");
public static final TagKey<Block> MINEABLE_WITH_SCRIBE = tag("mineable/scribe");
public static final TagKey<Block> ENGRAVABLE = tag("engravable");
public static final TagKey<Block> ENGRAVABLE_NEEDS_PLATE = tag("engravable/needs_plate");
public static final TagKey<Block> FIRE_SOURCE = tag("fire_source");
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/galena/oreganized/mixin/BlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package galena.oreganized.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import galena.oreganized.content.item.ScribeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(Block.class)
public class BlockMixin {

@ModifyVariable(
method = "getDrops(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)Ljava/util/List;",
at = @At(value = "STORE")
)
private static LootParams.Builder modifyLootBuilder(LootParams.Builder builder, @Local BlockState state, @Local ItemStack stack) {
if (stack.getItem() instanceof ScribeItem scribe && scribe.isCorrectToolForDrops(stack, state)) {
var virtual = stack.copy();
virtual.enchant(Enchantments.SILK_TOUCH, 1);
return builder.withParameter(LootContextParams.TOOL, virtual);
}
return builder;
}

}
30 changes: 30 additions & 0 deletions src/main/java/galena/oreganized/mixin/IceBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package galena.oreganized.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import galena.oreganized.content.item.ScribeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.IceBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(IceBlock.class)
public class IceBlockMixin {

@Redirect(
method = "playerDestroy(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/item/ItemStack;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper;getItemEnchantmentLevel(Lnet/minecraft/world/item/enchantment/Enchantment;Lnet/minecraft/world/item/ItemStack;)I")
)
private int modifyLootBuilder(Enchantment enchantment, ItemStack stack, @Local BlockState state) {
if (stack.getItem() instanceof ScribeItem scribe && scribe.isCorrectToolForDrops(stack, state)) {
return 1;
}
return EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, stack);
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/main/resources/oreganized.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"minVersion": "0.8",
"package": "galena.oreganized.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": ["AbstractArrowMixin", "CrossbowMixin", "DispenserBlockMixin", "PlayerMixin"],
"mixins": [
"AbstractArrowMixin", "BlockMixin", "CrossbowMixin", "DispenserBlockMixin", "IceBlockMixin", "PlayerMixin"
],
"client": [
"client.HumanoidArmorLayerAccessor", "client.HumanoidArmorLayerMixin"
],
Expand Down
Loading