Skip to content

Commit

Permalink
Added two new enchantments for Nether Gear (Obsidian Breaker and Ruby…
Browse files Browse the repository at this point in the history
… Fire) (#253)
  • Loading branch information
quiqueck committed Mar 4, 2022
1 parent 9470610 commit 58642d2
Show file tree
Hide file tree
Showing 17 changed files with 449 additions and 50 deletions.
4 changes: 0 additions & 4 deletions src/main/java/paulevs/betternether/blocks/BlockOre.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ public BlockOre(Item drop, int minCount, int maxCount, int experience, int minin
);
}

private static Item dropper(){
return NetherItems.AGAVE_LEAF;
}

@Override
public void addTags(List<TagAPI.TagLocation<Block>> blockTags, List<TagAPI.TagLocation<Item>> itemTags) {
blockTags.add(NamedMineableTags.PICKAXE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package paulevs.betternether.enchantments;

import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.DiggerItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import paulevs.betternether.registry.NetherBlocks;
import ru.bclib.api.tag.CommonBlockTags;

public class ObsidianBreaker extends Enchantment {
public ObsidianBreaker() {
super(Rarity.VERY_RARE, EnchantmentCategory.DIGGER, EquipmentSlot.values());
}

@Override
public int getMaxLevel() {
return 3;
}

@Override
public boolean isCurse() {
return true;
}

@Override
public boolean isTreasureOnly() {
return true;
}

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

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

public static float getDestroySpeedMultiplier(BlockState state, float baseSpeed, float level){
if ((state.is(CommonBlockTags.NETHER_STONES)
|| state.is(CommonBlockTags.NETHER_PORTAL_FRAME)
|| state.is(Blocks.OBSIDIAN)
|| state.is(Blocks.CRYING_OBSIDIAN)
|| state.is(NetherBlocks.BLUE_CRYING_OBSIDIAN)
|| state.is(NetherBlocks.WEEPING_OBSIDIAN)
|| state.is(NetherBlocks.BLUE_WEEPING_OBSIDIAN))) {
float speed = baseSpeed * level * 6;
return speed;
}
return baseSpeed;
}
}
161 changes: 161 additions & 0 deletions src/main/java/paulevs/betternether/enchantments/RubyFire.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package paulevs.betternether.enchantments;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ExperienceOrb;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TieredItem;
import net.minecraft.world.item.crafting.BlastingRecipe;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import paulevs.betternether.items.NetherArmor;
import paulevs.betternether.items.materials.BNToolMaterial;
import paulevs.betternether.registry.NetherEnchantments;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class RubyFire extends Enchantment {
private static final EquipmentSlot[] ARMOR_SLOTS = new EquipmentSlot[] {EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET};

public RubyFire() {
super(Rarity.VERY_RARE, EnchantmentCategory.BREAKABLE, ARMOR_SLOTS);
}

@Override
public boolean canEnchant(ItemStack itemStack) {
if (itemStack == null) return false;
final Item i = itemStack.getItem();

if (i instanceof TieredItem t) {
return t.getTier() == BNToolMaterial.NETHER_RUBY;
}

return i instanceof NetherArmor;
}

@Override
public boolean isCurse() {
return true;
}

@Override
public boolean isTreasureOnly() {
return true;
}

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

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

@Override
public void doPostHurt(LivingEntity player, Entity entity, int i) {
final Random random = player.getRandom();
Map.Entry<EquipmentSlot, ItemStack> entry = EnchantmentHelper.getRandomItemWith(NetherEnchantments.RUBY_FIRE, player);
if (shouldHit(i, random)) {
if (entity != null) {
entity.hurt(DamageSource.indirectMagic(entity, entity), getDamage(i, random));
entity.setRemainingFireTicks(100 + 50 * random.nextInt(3));
if (entity instanceof LivingEntity living){
living.knockback(1 + random.nextFloat(2.0f), player.getX() - living.getX(), player.getZ() - living.getZ());
}
}

if (entry != null) {
entry.getValue()
.hurtAndBreak(1, player, livingEntity -> livingEntity.broadcastBreakEvent(entry.getKey()));
}
}
}

private static boolean shouldHit(int i, Random random) {
if (i <= 0) return false;
return random.nextFloat() < 0.20f * i;
}

private static int getDamage(int i, Random random) {
if (i > 10) return i - 10;
return 2 + random.nextInt(5);
}


private static Map<Item, BlastingRecipe> FIRE_CONVERSIONS = new HashMap<>();
public static final ThreadLocal<List<ItemStack>> convertedDrops = ThreadLocal.withInitial(ArrayList<ItemStack>::new);

public static boolean getDrops(BlockState brokenBlock, ServerLevel level, BlockPos blockPos, Player player, ItemStack breakingItem) {
final int fireLevel = EnchantmentHelper.getItemEnchantmentLevel(NetherEnchantments.RUBY_FIRE, breakingItem);
if (fireLevel > 0) {
if (FIRE_CONVERSIONS.isEmpty()) buildConversionTable(level);

boolean didConvert = false;
int xpDrop = 0;
final List<ItemStack> drops = Block.getDrops(brokenBlock, level, blockPos, null, player, breakingItem);
convertedDrops.get().clear();

for (ItemStack stack : drops){
BlastingRecipe result = FIRE_CONVERSIONS.get(stack.getItem());
if (result != null) {
didConvert = true;
final ItemStack resultStack = result.getResultItem();
xpDrop += result.getExperience();
convertedDrops.get().add(new ItemStack(resultStack.getItem(), resultStack.getCount() * stack.getCount()));
} else {
convertedDrops.get().add(stack);
}
}

if (didConvert) {
if (xpDrop>0){
popExperience(level, blockPos, xpDrop);
}
convertedDrops.get().forEach(itemStack -> Block.popResource(level, blockPos, itemStack));
brokenBlock.spawnAfterBreak(level, blockPos, breakingItem);
convertedDrops.get().clear();
return true;
}
convertedDrops.get().clear();
}

return false;
}

private static void popExperience(ServerLevel level, BlockPos blockPos, int amount) {
if (level.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS)) {
ExperienceOrb.award(level, Vec3.atCenterOf(blockPos), amount);
}
}

private static void buildConversionTable(ServerLevel level) {
final List<BlastingRecipe> recipes = level.getRecipeManager()
.getAllRecipesFor(RecipeType.BLASTING);
for (BlastingRecipe r : recipes) {
for (Ingredient ingredient : r.getIngredients()) {
for (ItemStack stack : ingredient.getItems()) {
FIRE_CONVERSIONS.put(stack.getItem(), r);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package paulevs.betternether.interfaces;

import net.minecraft.world.item.ItemStack;

public interface InitialStackStateProvider {
public void initializeState(ItemStack stack);
}
25 changes: 24 additions & 1 deletion src/main/java/paulevs/betternether/items/NetherArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,34 @@

import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import paulevs.betternether.interfaces.InitialStackStateProvider;
import paulevs.betternether.items.materials.BNArmorMaterial;
import paulevs.betternether.registry.NetherEnchantments;
import paulevs.betternether.registry.NetherItems;
import ru.bclib.items.BaseArmorItem;

public class NetherArmor extends BaseArmorItem {
import java.util.HashMap;
import java.util.Map;

public class NetherArmor extends BaseArmorItem implements InitialStackStateProvider {
public NetherArmor(ArmorMaterial material, EquipmentSlot slot) {
super(material, slot, NetherItems.defaultSettings());
}

static final Map<Enchantment, Integer> DEFAULT_RUBY_ENCHANTS;

@Override
public void initializeState(ItemStack stack) {
if (material== BNArmorMaterial.NETHER_RUBY) {
EnchantmentHelper.setEnchantments(DEFAULT_RUBY_ENCHANTS, stack);
}
}

static {
DEFAULT_RUBY_ENCHANTS = new HashMap<>();
DEFAULT_RUBY_ENCHANTS.put(NetherEnchantments.RUBY_FIRE, 1);
}
}
13 changes: 12 additions & 1 deletion src/main/java/paulevs/betternether/items/NetherAxe.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import paulevs.betternether.interfaces.InitialStackStateProvider;
import paulevs.betternether.items.materials.BNArmorMaterial;
import paulevs.betternether.items.materials.BNToolMaterial;
import paulevs.betternether.registry.NetherItems;
import ru.bclib.interfaces.TagProvider;
import ru.bclib.items.tool.BaseAxeItem;

import java.util.List;

public class NetherAxe extends BaseAxeItem {
public class NetherAxe extends BaseAxeItem implements InitialStackStateProvider {
public NetherAxe(Tier material) {
super(material, 1, -2.8F, NetherItems.defaultSettings().fireResistant());
}
Expand All @@ -22,4 +26,11 @@ public NetherAxe(Tier material) {
public float getDestroySpeed(ItemStack stack, BlockState state) {
return super.getDestroySpeed(stack, state);
}

@Override
public void initializeState(ItemStack stack) {
if (getTier()== BNToolMaterial.NETHER_RUBY) {
EnchantmentHelper.setEnchantments(NetherArmor.DEFAULT_RUBY_ENCHANTS, stack);
}
}
}
12 changes: 11 additions & 1 deletion src/main/java/paulevs/betternether/items/NetherHoe.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import paulevs.betternether.interfaces.InitialStackStateProvider;
import paulevs.betternether.items.materials.BNToolMaterial;
import paulevs.betternether.registry.NetherItems;
import ru.bclib.interfaces.TagProvider;
import ru.bclib.items.tool.BaseHoeItem;

import java.util.List;

public class NetherHoe extends BaseHoeItem {
public class NetherHoe extends BaseHoeItem implements InitialStackStateProvider {

public NetherHoe(Tier material) {
super(material, 1, -2.8F, NetherItems.defaultSettings().fireResistant());
Expand All @@ -23,4 +26,11 @@ public NetherHoe(Tier material) {
public float getDestroySpeed(ItemStack stack, BlockState state) {
return super.getDestroySpeed(stack, state);
}

@Override
public void initializeState(ItemStack stack) {
if (getTier()== BNToolMaterial.NETHER_RUBY) {
EnchantmentHelper.setEnchantments(NetherArmor.DEFAULT_RUBY_ENCHANTS, stack);
}
}
}
39 changes: 23 additions & 16 deletions src/main/java/paulevs/betternether/items/NetherPickaxe.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,36 @@

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import paulevs.betternether.registry.NetherBlocks;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import paulevs.betternether.interfaces.InitialStackStateProvider;
import paulevs.betternether.items.materials.BNToolMaterial;
import paulevs.betternether.registry.NetherEnchantments;
import paulevs.betternether.registry.NetherItems;
import ru.bclib.api.tag.CommonBlockTags;
import ru.bclib.items.tool.BasePickaxeItem;

public class NetherPickaxe extends BasePickaxeItem {
import java.util.HashMap;
import java.util.Map;

public class NetherPickaxe extends BasePickaxeItem implements InitialStackStateProvider {
public NetherPickaxe(Tier material) {
super(material, 1, -2.8F, NetherItems.defaultSettings().fireResistant());
}

@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
if ((state.is(CommonBlockTags.NETHER_STONES)
|| state.is(CommonBlockTags.NETHER_PORTAL_FRAME)
|| state.is(Blocks.OBSIDIAN)
|| state.is(Blocks.CRYING_OBSIDIAN)
|| state.is(NetherBlocks.BLUE_CRYING_OBSIDIAN)
|| state.is(NetherBlocks.WEEPING_OBSIDIAN)
|| state.is(NetherBlocks.BLUE_WEEPING_OBSIDIAN)) && this.getTier().getLevel() > 2) {
return super.getDestroySpeed(stack, state) * 10;
public void initializeState(ItemStack stack) {
Map<Enchantment, Integer> defaultEnchants = new HashMap<>();

int obsidianLevel = 0;
if (this.getTier()== BNToolMaterial.CINCINNASITE_DIAMOND) obsidianLevel = 3;
else if (this.getTier()== BNToolMaterial.NETHER_RUBY) {
obsidianLevel = 2;
defaultEnchants.put(NetherEnchantments.RUBY_FIRE, 1);
}

if (obsidianLevel>0) {
defaultEnchants.put(NetherEnchantments.OBSIDIAN_BREAKER, obsidianLevel);
EnchantmentHelper.setEnchantments(defaultEnchants, stack);
}
return super.getDestroySpeed(stack, state);
}
}
Loading

0 comments on commit 58642d2

Please sign in to comment.