Skip to content

Commit

Permalink
Merge pull request #5 from Badtz13/bone_enchantments_R1
Browse files Browse the repository at this point in the history
Adds Hog, Greed, and Fiery effect
  • Loading branch information
Julia Lange authored Mar 2, 2024
2 parents a90769e + c9933f4 commit d066e44
Show file tree
Hide file tree
Showing 33 changed files with 179 additions and 74 deletions.
7 changes: 0 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "1.9.10"
}

version = project.mod_version
Expand Down Expand Up @@ -60,7 +59,6 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"
// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

Expand All @@ -79,11 +77,6 @@ tasks.withType(JavaCompile).configureEach {
it.options.release = 17
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = 17
}
}

task copyTask(type: Copy) {
from 'build/libs'
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ org.gradle.parallel=true
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.14.22
fabric_kotlin_version=1.10.10+kotlin.1.9.10

# Mod Properties
mod_version=1.0.0
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/me/woach/bone/Bone.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

import me.woach.bone.block.BlocksRegistry;
import me.woach.bone.block.entity.BlockEntityTypesRegistry;
import me.woach.bone.bonedata.BoneReloader;
import me.woach.bone.effects.BoneEffectRegistry;
import me.woach.bone.items.ItemsRegistry;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import me.woach.bone.bonedata.BoneReloader;
import net.minecraft.registry.RegistryKey;

import net.fabricmc.api.ModInitializer;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

public class Bone implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("Bone");
public static Identifier getId(String path) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/woach/bone/block/BlocksRegistry.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package me.woach.bone.block;

import java.util.function.Supplier;

import me.woach.bone.Bone;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.sound.BlockSoundGroup;

import java.util.function.Supplier;

public enum BlocksRegistry {
BONE_FORGE_BLOCK("bone_forge", BoneForgeBlock::new),
BONE_FIRE_BLOCK("bone_fire", BoneFireBlock::new),
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/me/woach/bone/block/BoneFireBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public class BoneFireBlock extends Block {
private final float damage;

public BoneFireBlock() {
super(AbstractBlock.Settings.create().mapColor(MapColor.LICHEN_GREEN).replaceable().noCollision().breakInstantly()
.luminance(state -> 15).sounds(BlockSoundGroup.WOOL).pistonBehavior(PistonBehavior.DESTROY).nonOpaque());
super(AbstractBlock.Settings.create().mapColor(MapColor.LICHEN_GREEN).replaceable().noCollision()
.breakInstantly()
.luminance(state -> 15).sounds(BlockSoundGroup.WOOL).pistonBehavior(PistonBehavior.DESTROY)
.nonOpaque());
this.damage = 2;
setDefaultState(getStateManager().getDefaultState().with(TYPE, EssenceItem.Types.EMPTY));
}
Expand All @@ -56,12 +58,13 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 1.0, 16.0);
}

@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).isSolidBlock(world,pos);
return world.getBlockState(pos.down()).isSolidBlock(world, pos);
}

public static void setEssenceState(World world, BlockPos pos, EssenceItem.Types essence) {
public static void setEssenceState(World world, BlockPos pos, EssenceItem.Types essence) {
switch (essence) {
case JORD:
case AEGIR:
Expand All @@ -85,7 +88,8 @@ public static void essenceCollision(World world, BlockPos pos, Entity entity) {

// Update bone forge to match
BlockEntity aboveFire = world.getBlockEntity(pos.up());
if (aboveFire != null && aboveFire.getType().equals(BlockEntityTypesRegistry.BONE_FORGE_BLOCK_ENTITY.get())) {
if (aboveFire != null
&& aboveFire.getType().equals(BlockEntityTypesRegistry.BONE_FORGE_BLOCK_ENTITY.get())) {
BoneForgeBlockEntity forge = (BoneForgeBlockEntity) aboveFire;

forge.attemptToForge();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.*;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/me/woach/bone/effects/BoneEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.woach.bone.effects;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.EquipmentSlot;

public abstract class BoneEffect extends Enchantment {
protected BoneEffect(Rarity weight, EnchantmentTarget target, EquipmentSlot... slotTypes) {
super(weight, target, slotTypes);
}

@Override
public boolean isAvailableForEnchantedBookOffer() {
return false;
}

@Override
public boolean isAvailableForRandomSelection() {
return false;
}
}
12 changes: 5 additions & 7 deletions src/main/java/me/woach/bone/effects/BoneEffectRegistry.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package me.woach.bone.effects;

import java.util.function.Supplier;

import me.woach.bone.Bone;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.enchantment.LuckEnchantment;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;

import java.util.function.Supplier;

public enum BoneEffectRegistry {
GREED("greed", GreedEffect::new);
GREED("greed", GreedEffect::new),
FIERY("firey", FieryEffect::new),
HOG("hog", HogEffect::new);

private final String path;
private final Supplier<Enchantment> effectSupplier;
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/me/woach/bone/effects/FieryEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.woach.bone.effects;

import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;

public class FieryEffect extends BoneEffect {

protected FieryEffect() {
super(Rarity.RARE, EnchantmentTarget.WEAPON, EquipmentSlot.MAINHAND);
}

@Override
public void onTargetDamaged(LivingEntity user, Entity target, int level) {
if (target instanceof LivingEntity) {
target.setFireTicks(4 * 20 * level);
}

super.onTargetDamaged(user, target, level);
}

}
9 changes: 7 additions & 2 deletions src/main/java/me/woach/bone/effects/GreedEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.EquipmentSlot;

public class GreedEffect extends Enchantment {
public class GreedEffect extends BoneEffect {
protected GreedEffect() {
super(Rarity.RARE, EnchantmentTarget.WEAPON, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
super(Rarity.RARE, EnchantmentTarget.WEAPON, EquipmentSlot.MAINHAND);
}
@Override
public boolean canAccept(Enchantment other) {
return super.canAccept(other) && other != Enchantments.LOOTING;
}
}
11 changes: 11 additions & 0 deletions src/main/java/me/woach/bone/effects/HogEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.woach.bone.effects;

import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.EquipmentSlot;

public class HogEffect extends BoneEffect{

protected HogEffect() {
super(Rarity.RARE, EnchantmentTarget.ARMOR_HEAD, EquipmentSlot.HEAD);
}
}
4 changes: 2 additions & 2 deletions src/main/java/me/woach/bone/items/EssenceItem.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.woach.bone.items;

import java.util.List;

import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.Item;
Expand All @@ -13,6 +11,8 @@
import net.minecraft.util.StringIdentifiable;
import net.minecraft.world.World;

import java.util.List;

public class EssenceItem extends Item {
public EssenceItem() {
super(new FabricItemSettings().maxCount(16).rarity(Rarity.EPIC));
Expand Down
16 changes: 4 additions & 12 deletions src/main/java/me/woach/bone/items/ItemsRegistry.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
package me.woach.bone.items;

import java.util.Arrays;
import java.util.function.Supplier;

import me.woach.bone.Bone;
import me.woach.bone.block.BlocksRegistry;
import me.woach.bone.material.BonesteelArmorMaterial;
import me.woach.bone.material.BonesteelToolMaterial;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.data.client.BlockStateVariantMap.QuadFunction;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.*;
import net.minecraft.item.ArmorItem.Type;
import net.minecraft.item.AxeItem;
import net.minecraft.item.BlockItem;
import net.minecraft.item.HoeItem;
import net.minecraft.item.Item;
import net.minecraft.item.PickaxeItem;
import net.minecraft.item.ShovelItem;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Rarity;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.function.Supplier;

public enum ItemsRegistry {
BONE_ITEM("bone", BoneItem::new),
BONE_FORGE_BLOCK_ITEM("bone_forge", () -> new BlockItem(BlocksRegistry.BONE_FORGE_BLOCK.get(),
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/me/woach/bone/mixin/EntitiesDropBones.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
import me.woach.bone.bonedata.AbstractBone;
import me.woach.bone.bonedata.BoneRegistry;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/me/woach/bone/mixin/greedMimicsLooting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package me.woach.bone.mixin;

import me.woach.bone.effects.BoneEffectRegistry;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.LivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(EnchantmentHelper.class)
public class greedMimicsLooting {

@Inject(method = "getLooting", at = @At("RETURN"), cancellable = true)
private static void useGreed(LivingEntity entity, CallbackInfoReturnable<Integer> cir) {
int greedLevel = EnchantmentHelper.getEquipmentLevel(BoneEffectRegistry.GREED.get(), entity);
if (greedLevel > cir.getReturnValue())
cir.setReturnValue(greedLevel);
}
}
41 changes: 41 additions & 0 deletions src/main/java/me/woach/bone/mixin/hogDecreasesEating.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package me.woach.bone.mixin;

import me.woach.bone.Bone;
import me.woach.bone.effects.BoneEffectRegistry;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(LivingEntity.class)
public abstract class hogDecreasesEating extends Entity {

@Shadow public abstract ItemStack getEquippedStack(EquipmentSlot var1);

@Shadow protected int itemUseTimeLeft;

public hogDecreasesEating(EntityType<?> type, World world) {
super(type, world);
}

@Inject(method = "tickItemStackUsage", at = @At("HEAD"))
private void extraTicksOnFoodWithHog(ItemStack stack, CallbackInfo ci) {
if (stack.isFood()) {
ItemStack helmet = this.getEquippedStack(EquipmentSlot.HEAD);
int hogLevel = EnchantmentHelper.getLevel(BoneEffectRegistry.HOG.get(), helmet);
if (hogLevel != 0) {
if (this.itemUseTimeLeft % (5 - hogLevel) == 0) {
this.itemUseTimeLeft -= 1;
}
}
}
}
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/bone/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
"item.bone.bone": "Bone",
"itemGroup.bone.bone": "Bone",
"item.bone.tier": "Tier %s",
"enchantment.minecraft.looting": "Greed"
"enchantment.bone.greed": "Greed",
"enchantment.bone.hog": "Hog",
"enchantment.bone.firey": "Firey"
}
4 changes: 3 additions & 1 deletion src/main/resources/bone.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"mixins": [
"LootPoolAccessor",
"EntitiesDropBones",
"FirePowersBoneForge"
"FirePowersBoneForge",
"greedMimicsLooting",
"hogDecreasesEating"
],
"injectors": {
"defaultRequire": 1
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/data/bone/bones/bat.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"enabled": true,
"effect": "bone:sonar",
"entity": "minecraft:entities/bat"
"entity": "minecraft/bat"
}
6 changes: 6 additions & 0 deletions src/main/resources/data/bone/bones/blaze.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"enabled": true,
"chance": 125,
"effect": "bone:firey",
"entity": "minecraft:blaze"
}
Loading

0 comments on commit d066e44

Please sign in to comment.