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

Optional Projectile Damage Support, Multiple Bug Fixes, Version Bumps #214

Merged
merged 4 commits into from
May 11, 2023
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
16 changes: 13 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ repositories {
maven {
url 'https://jitpack.io'
}
maven {
name = 'Modrinth'
url = 'https://api.modrinth.com/maven'
content {
includeGroup 'maven.modrinth'
}
}
repositories {
flatDir{
dirs 'localdeps'
Expand Down Expand Up @@ -59,15 +66,18 @@ dependencies {
// Clumps
modImplementation "curse.maven:clumps-256717:3900783"

// Projectile Damage
modImplementation "maven.modrinth:projectile-damage-attribute:${project.projectile_damage_version}-fabric"

// Cloth Config
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
exclude(group: "net.fabricmc.fabric-api")
}

// Mixin Extras
implementation("com.github.LlamaLad7:MixinExtras:0.2.0-beta.2")
annotationProcessor("com.github.LlamaLad7:MixinExtras:0.2.0-beta.2")
include "com.github.LlamaLad7:MixinExtras:0.2.0-beta.2"
implementation("com.github.LlamaLad7:MixinExtras:${project.mixin_extras_version}")
annotationProcessor("com.github.LlamaLad7:MixinExtras:${project.mixin_extras_version}")
include "com.github.LlamaLad7:MixinExtras:${project.mixin_extras_version}"

}

Expand Down
10 changes: 6 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://fabricmc.net/develop/
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.14.14
loader_version=0.14.19

# Mod Properties
mod_version=5.0.8-1.19
mod_version=5.0.9-1.19
maven_group=chronosacaria
archives_base_name=mcdw

# Dependencies
# check this on https://fabricmc.net/develop/
fabric_version=0.73.2+1.19.2
fabric_version=0.76.0+1.19.2
reach_entity_attributes_version=2.3.0
cloth_config_version=7.0.72
cloth_config_version=7.0.72
mixin_extras_version=0.2.0-beta.6
projectile_damage_version=3.1.0+1.19
1 change: 1 addition & 0 deletions src/main/java/chronosacaria/mcdw/Mcdw.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void onInitialize() {
McdwEnchantGiverConfig.appendEnchants();
SummonedEntityRegistry.register();
StatusEffectsRegistry.init();
EnchantmentRestrictionsRegistry.init();
CompatRegistry.init();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package chronosacaria.mcdw.api.util;

import com.google.common.collect.ArrayListMultimap;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.item.ItemStack;

import java.util.ArrayList;

/**
* This code is used with the permission of <a href = "https://github.com/ZsoltMolnarrr">Daedelus</a>. <br />
* The original code is from SpellEngine and can be found <a href = "https://github.com/ZsoltMolnarrr/SpellEngine/blob/1.19.2/common/src/main/java/net/spell_engine/api/enchantment/EnchantmentRestriction.java">here</a>.
*/

public final class EnchantmentRestriction {
public interface Condition {
boolean isAcceptableItem(ItemStack itemStack);
}

public interface TypeCondition {
boolean isAcceptableItem(Enchantment enchantment, ItemStack itemStack);
}
private static ArrayListMultimap<Enchantment, Condition> permissions = ArrayListMultimap.create();
private static ArrayList<TypeCondition> permissibleTargets = new ArrayList<>();
private static ArrayListMultimap<Enchantment, Condition> prohibitions = ArrayListMultimap.create();
private static ArrayList<TypeCondition> prohibitedTargets = new ArrayList<>();


public static void permit(Enchantment enchantment, Condition condition) {
permissions.put(enchantment, condition);
}

public static void permitTarget(TypeCondition typeCondition) {
permissibleTargets.add(typeCondition);
}

public static void prohibit(Enchantment enchantment, Condition condition) {
prohibitions.put(enchantment, condition);
}

public static void prohibitTarget(TypeCondition typeCondition) {
prohibitedTargets.add(typeCondition);
}

public static boolean isPermitted(Enchantment enchantment, ItemStack itemStack) {
var conditions = permissions.get(enchantment);
for(var condition: conditions) {
if (condition.isAcceptableItem(itemStack)) {
return true;
}
}
for(var condition: permissibleTargets) {
if (condition.isAcceptableItem(enchantment, itemStack)) {
return true;
}
}
return false;
}

public static boolean isProhibited(Enchantment enchantment, ItemStack itemStack) {
var conditions = prohibitions.get(enchantment);
for(var condition: conditions) {
if (condition.isAcceptableItem(itemStack)) {
return true;
}
}
for(var condition: prohibitedTargets) {
if (condition.isAcceptableItem(enchantment, itemStack)) {
return true;
}
}
return false;
}
}
80 changes: 74 additions & 6 deletions src/main/java/chronosacaria/mcdw/bases/McdwSword.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,30 @@
import chronosacaria.mcdw.api.util.RarityHelper;
import chronosacaria.mcdw.enums.SwordsID;
import chronosacaria.mcdw.registries.ItemsRegistry;
import com.google.common.collect.BiMap;
import net.fabricmc.fabric.mixin.content.registry.AxeItemAccessor;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.block.*;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.tag.BlockTags;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;

import java.util.List;
import java.util.Locale;
import java.util.Optional;

@SuppressWarnings("rawtypes")
public class McdwSword extends SwordItem {
String[] repairIngredient;

Expand All @@ -32,7 +43,65 @@ public boolean canRepair(ItemStack stack, ItemStack ingredient) {
return CleanlinessHelper.canRepairCheck(repairIngredient, ingredient);
}

@Override
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
World world = context.getWorld();
BlockPos blockPos = context.getBlockPos();
PlayerEntity playerEntity = context.getPlayer();
BlockState blockState = world.getBlockState(blockPos);
Optional<BlockState> strippedState = this.getStrippedState(blockState);
Optional<BlockState> decreasedOxidationState = Oxidizable.getDecreasedOxidationState(blockState);
Optional<BlockState> blockStateOptional = Optional.ofNullable((Block)((BiMap)HoneycombItem.WAXED_TO_UNWAXED_BLOCKS.get()).get(blockState.getBlock())).map((block) -> block.getStateWithProperties(blockState));
ItemStack itemStack = context.getStack();
Optional<BlockState> empty = Optional.empty();
if (context.getStack().isOf(SwordsID.SWORD_MECHANIZED_SAWBLADE.getItem())) {
if (strippedState.isPresent()) {
world.playSound(playerEntity, blockPos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
empty = strippedState;
} else if (decreasedOxidationState.isPresent()) {
world.playSound(playerEntity, blockPos, SoundEvents.ITEM_AXE_SCRAPE, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.syncWorldEvent(playerEntity, 3005, blockPos, 0);
empty = decreasedOxidationState;
} else if (blockStateOptional.isPresent()) {
world.playSound(playerEntity, blockPos, SoundEvents.ITEM_AXE_WAX_OFF, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.syncWorldEvent(playerEntity, 3004, blockPos, 0);
empty = blockStateOptional;
}

if (empty.isPresent()) {
if (playerEntity instanceof ServerPlayerEntity) {
Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity)playerEntity, blockPos, itemStack);
}

world.setBlockState(blockPos, empty.get(), 11);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Emitter.of(playerEntity, empty.get()));
if (playerEntity != null) {
itemStack.damage(1, playerEntity, (p) -> p.sendToolBreakStatus(context.getHand()));
}

return ActionResult.success(world.isClient);
} else {
return ActionResult.PASS;
}
}
return ActionResult.PASS;
}

@Override
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
if (stack.isOf(SwordsID.SWORD_MECHANIZED_SAWBLADE.getItem())) {
if (state.isIn(BlockTags.AXE_MINEABLE))
return 8.0F;
}
return super.getMiningSpeedMultiplier(stack, state);
}

@SuppressWarnings("UnstableApiUsage")
private Optional<BlockState> getStrippedState(BlockState state) {
return Optional.ofNullable(AxeItemAccessor.getStrippedBlocks().get(state.getBlock())).map((block) -> block.getDefaultState().with(PillarBlock.AXIS, state.get(PillarBlock.AXIS)));
}

@Override
public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext tooltipContext){
super.appendTooltip(stack, world, tooltip, tooltipContext);
int i = 1;
Expand All @@ -50,5 +119,4 @@ public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, Tool
tooltip.add(Text.translatable("tooltip_info_item.mcdw.diamond_sword_3").formatted(Formatting.ITALIC));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public McdwEnchantmentsConfig(){

for (EnchantmentsID enchantmentsID : EnchantmentsID.values())
ENABLE_VILLAGER_TRADING.put(enchantmentsID, true);
ENABLE_VILLAGER_TRADING.replace(EnchantmentsID.BURST_BOWSTRING, false);
ENABLE_VILLAGER_TRADING.replace(EnchantmentsID.DYNAMO, false);
ENABLE_VILLAGER_TRADING.replace(EnchantmentsID.SHARED_PAIN, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ protected IMeleeWeaponID.MeleeStats advancedMeleeWeaponStats(IMeleeWeaponID iMel
return meleeWeaponStats(materialToString(iMeleeWeaponID.getMaterial()), iMeleeWeaponID.getDamage(), iMeleeWeaponID.getAttackSpeed(), iMeleeWeaponID.getRepairIngredient(), iMeleeWeaponID);
}

protected IRangedWeaponID.RangedStats rangedWeaponStats(String material, int drawSpeed, float range, String[] repairIngredient, IRangedWeaponID iRangedWeaponID) {
return iRangedWeaponID.getWeaponItemStats(this).rangedStats(material, drawSpeed, range, repairIngredient);
protected IRangedWeaponID.RangedStats rangedWeaponStats(String material, double projectileDamage, int drawSpeed, float range, String[] repairIngredient, IRangedWeaponID iRangedWeaponID) {
return iRangedWeaponID.getWeaponItemStats(this).rangedStats(material, projectileDamage, drawSpeed, range, repairIngredient);
}
protected IRangedWeaponID.RangedStats advancedRangedWeaponStats(IRangedWeaponID iRangedWeaponID) {
return rangedWeaponStats(materialToString(iRangedWeaponID.getMaterial()), iRangedWeaponID.getDrawSpeed(), iRangedWeaponID.getRange(), iRangedWeaponID.getRepairIngredient(), iRangedWeaponID);
return rangedWeaponStats(materialToString(iRangedWeaponID.getMaterial()), iRangedWeaponID.getProjectileDamage(), iRangedWeaponID.getDrawSpeed(), iRangedWeaponID.getRange(), iRangedWeaponID.getRepairIngredient(), iRangedWeaponID);
}

protected IShieldID.ShieldStats shieldStats(String material, String[] repairIngredient, IShieldID iShieldID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.registry.Registry;

public class AccelerateEnchantment extends RangedEnchantment {
public class AccelerateEnchantment extends RangedEnchantment{
public AccelerateEnchantment(Rarity rarity, EnchantmentTarget enchantmentTarget, EquipmentSlot[] equipmentSlots) {
super(rarity, enchantmentTarget, equipmentSlots);
if (Mcdw.CONFIG.mcdwEnchantmentsConfig.ENABLE_ENCHANTMENTS.get(EnchantmentsID.ACCELERATE)) {
Expand Down Expand Up @@ -56,5 +56,4 @@ public int getMinPower(int level) {
public int getMaxPower(int level) {
return this.getMinPower(level) + 5;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public int getMaxLevel(){

@Override
protected boolean canAccept (Enchantment other){
return Mcdw.CONFIG.mcdwEnchantmentSettingsConfig.ENABLE_ENCHANTMENT_SETTINGS.get(SettingsID.ENABLE_OP_ENCHANTMENT_MIXING) ||
!(other instanceof AOEEnchantment || other instanceof DamageBoostEnchantment);
return Mcdw.CONFIG.mcdwEnchantmentSettingsConfig.ENABLE_ENCHANTMENT_SETTINGS.get(SettingsID.ENABLE_OP_ENCHANTMENT_MIXING)
|| !(other instanceof AOEEnchantment || other instanceof DamageBoostEnchantment)
|| other.isAcceptableItem(DaggersID.DAGGER_SWIFT_STRIKER.getItem().getDefaultStack());
}

@Override
Expand All @@ -52,7 +53,8 @@ public boolean isAcceptableItem(ItemStack stack) {
return stack.getItem() instanceof SwordItem
|| stack.getItem() instanceof AxeItem
|| stack.getItem() instanceof McdwCustomWeaponBase
|| stack.isOf(DaggersID.DAGGER_SWIFT_STRIKER.getItem()); }
|| stack.isOf(DaggersID.DAGGER_SWIFT_STRIKER.getItem());
}

@Override
public int getMinPower(int level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public int getMaxLevel() {
@Override
protected boolean canAccept (Enchantment other) {
return Mcdw.CONFIG.mcdwEnchantmentSettingsConfig.ENABLE_ENCHANTMENT_SETTINGS.get(SettingsID.ENABLE_OP_ENCHANTMENT_MIXING)
|| !(other instanceof AOEEnchantment || other instanceof DamageBoostEnchantment);
|| !(other instanceof AOEEnchantment || other instanceof DamageBoostEnchantment)
|| other.isAcceptableItem(DaggersID.DAGGER_SWIFT_STRIKER.getItem().getDefaultStack());
}

@Override
Expand All @@ -52,7 +53,8 @@ public boolean isAcceptableItem(ItemStack stack) {
return stack.getItem() instanceof SwordItem
|| stack.getItem() instanceof AxeItem
|| stack.getItem() instanceof McdwCustomWeaponBase
|| stack.isOf(DaggersID.DAGGER_SWIFT_STRIKER.getItem()); }
|| stack.isOf(DaggersID.DAGGER_SWIFT_STRIKER.getItem());
}

@Override
public int getMinPower(int level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.RangedWeaponItem;
import net.minecraft.util.registry.Registry;

public class GuardingStrikeEnchantment extends Enchantment {
Expand Down Expand Up @@ -33,6 +35,11 @@ public boolean isAvailableForEnchantedBookOffer() {
&& Mcdw.CONFIG.mcdwEnchantmentsConfig.ENABLE_VILLAGER_TRADING.get(EnchantmentsID.GUARDING_STRIKE);
}

@Override
public boolean isAcceptableItem(ItemStack stack) {
return !(stack.getItem() instanceof RangedWeaponItem);
}

@Override
public int getMinPower(int level) {
return 1 + level * 10;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/chronosacaria/mcdw/enums/AxesID.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import static chronosacaria.mcdw.Mcdw.CONFIG;

public enum AxesID implements IMcdwWeaponID, IMeleeWeaponID {
public enum AxesID implements IMeleeWeaponID {
AXE_ANCHOR(ToolMaterials.IRON,8, -3.4f, "minecraft:iron_ingot"),
AXE_AXE(ToolMaterials.IRON,6, -3.1f, "minecraft:iron_ingot"),
AXE_ENCRUSTED_ANCHOR(ToolMaterials.DIAMOND,8, -3.4f, "minecraft:diamond"),
Expand Down
Loading