-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added two new enchantments for Nether Gear (Obsidian Breaker and Ruby…
… Fire) (#253)
- Loading branch information
Showing
17 changed files
with
449 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/paulevs/betternether/enchantments/ObsidianBreaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
161
src/main/java/paulevs/betternether/enchantments/RubyFire.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/paulevs/betternether/interfaces/InitialStackStateProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.