Skip to content

Commit

Permalink
Beta 32 - Tiered Shields and a bunch of content stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra-Myers committed Sep 13, 2023
1 parent 98ad89b commit 7d5cc09
Show file tree
Hide file tree
Showing 70 changed files with 1,661 additions and 26 deletions.
7 changes: 7 additions & 0 deletions src/main/java/net/atlas/combatify/Combatify.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.atlas.combatify.enchantment.PiercingEnchantment;
import net.atlas.combatify.extensions.ItemExtensions;
import net.atlas.combatify.item.ItemRegistry;
import net.atlas.combatify.item.TieredShieldItem;
import net.atlas.combatify.networking.NetworkingHandler;
import net.atlas.combatify.util.*;
import net.fabricmc.api.ModInitializer;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class Combatify implements ModInitializer {
public static ItemConfig ITEMS;
public static ResourceLocation modDetectionNetworkChannel = id("networking");
public NetworkingHandler networkingHandler;
public static final List<TieredShieldItem> shields = new ArrayListExtensions<>();
public static final List<UUID> unmoddedPlayers = new ArrayListExtensions<>();
public static final Map<UUID, Boolean> isPlayerAttacking = new HashMap<>();
public static final Map<UUID, Boolean> finalizingAttack = new HashMap<>();
Expand Down Expand Up @@ -64,6 +66,11 @@ public void onInitialize() {
Event<ItemGroupEvents.ModifyEntries> event = ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.COMBAT);
event.register(entries -> entries.addAfter(NETHERITE_SWORD, ItemRegistry.WOODEN_KNIFE, ItemRegistry.STONE_KNIFE, ItemRegistry.IRON_KNIFE, ItemRegistry.GOLD_KNIFE, ItemRegistry.DIAMOND_KNIFE, ItemRegistry.NETHERITE_KNIFE, ItemRegistry.WOODEN_LONGSWORD, ItemRegistry.STONE_LONGSWORD, ItemRegistry.IRON_LONGSWORD, ItemRegistry.GOLD_LONGSWORD, ItemRegistry.DIAMOND_LONGSWORD, ItemRegistry.NETHERITE_LONGSWORD));
}
if (CONFIG.tieredShields()) {
TieredShieldItem.init();
Event<ItemGroupEvents.ModifyEntries> event = ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.COMBAT);
event.register(entries -> entries.addAfter(Items.SHIELD, TieredShieldItem.WOODEN_SHIELD, TieredShieldItem.IRON_SHIELD, TieredShieldItem.GOLD_SHIELD, TieredShieldItem.DIAMOND_SHIELD, TieredShieldItem.NETHERITE_SHIELD));
}
if(CONFIG.piercer()) {
PiercingEnchantment.registerEnchants();
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/atlas/combatify/CombatifyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@
import net.atlas.combatify.extensions.IOptions;
import net.atlas.combatify.networking.ClientNetworkingHandler;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import net.minecraft.client.OptionInstance;
import net.minecraft.client.model.ShieldModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;

import java.util.Arrays;
import java.util.Objects;

import static net.minecraft.client.Options.genericValueLabel;

public class CombatifyClient implements ClientModInitializer {
public static final ModelLayerLocation WOODEN_SHIELD_MODEL_LAYER = new ModelLayerLocation(new ResourceLocation("combatify", "wooden_shield"),"main");
public static final ModelLayerLocation IRON_SHIELD_MODEL_LAYER = new ModelLayerLocation(new ResourceLocation("combatify", "iron_shield"),"main");
public static final ModelLayerLocation GOLDEN_SHIELD_MODEL_LAYER = new ModelLayerLocation(new ResourceLocation("combatify", "golden_shield"),"main");
public static final ModelLayerLocation DIAMOND_SHIELD_MODEL_LAYER = new ModelLayerLocation(new ResourceLocation("combatify", "diamond_shield"),"main");
public static final ModelLayerLocation NETHERITE_SHIELD_MODEL_LAYER = new ModelLayerLocation(new ResourceLocation("combatify", "netherite_shield"),"main");
public static final OptionInstance<Boolean> autoAttack = OptionInstance.createBoolean("options.autoAttack", true);
public static final OptionInstance<Boolean> shieldCrouch = OptionInstance.createBoolean("options.shieldCrouch", true);
public static final OptionInstance<Boolean> rhythmicAttacks = OptionInstance.createBoolean("options.rhythmicAttack",true);
Expand Down Expand Up @@ -44,5 +53,12 @@ public class CombatifyClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
clientNetworkingHandler = new ClientNetworkingHandler();
if (Combatify.CONFIG.tieredShields()) {
EntityModelLayerRegistry.registerModelLayer(WOODEN_SHIELD_MODEL_LAYER, ShieldModel::createLayer);
EntityModelLayerRegistry.registerModelLayer(IRON_SHIELD_MODEL_LAYER, ShieldModel::createLayer);
EntityModelLayerRegistry.registerModelLayer(GOLDEN_SHIELD_MODEL_LAYER, ShieldModel::createLayer);
EntityModelLayerRegistry.registerModelLayer(DIAMOND_SHIELD_MODEL_LAYER, ShieldModel::createLayer);
EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, ShieldModel::createLayer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class CombatifyConfigModel {
@RestartRequired
public boolean configOnlyWeapons = false;
@RestartRequired
public boolean tieredShields = false;
@RestartRequired
public boolean piercer = false;
@RestartRequired
public boolean defender = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ConfigurableItemData {
public final BlockingType blockingType;
public final Double blockStrength;
public final Double blockKbRes;
ConfigurableItemData(Double attackDamage, Double attackSpeed, Double attackReach, Double chargedReach, Integer stackSize, Integer cooldown, Boolean cooldownAfter, WeaponType weaponType, BlockingType blockingType, Double blockStrength, Double blockKbRes) {
public final Integer enchantability;
ConfigurableItemData(Double attackDamage, Double attackSpeed, Double attackReach, Double chargedReach, Integer stackSize, Integer cooldown, Boolean cooldownAfter, WeaponType weaponType, BlockingType blockingType, Double blockStrength, Double blockKbRes, Integer enchantability) {
damage = clamp(attackDamage, -10, 1000);
speed = clamp(attackSpeed, -1, 7.5);
reach = clamp(attackReach, 0, 1024);
Expand All @@ -27,6 +28,7 @@ public class ConfigurableItemData {
this.blockingType = blockingType;
this.blockStrength = clamp(blockStrength, 0, 1000);
this.blockKbRes = clamp(blockKbRes, 0, 1);
this.enchantability = clamp(enchantability, 0, 1000);
}
public static Integer clamp(Integer i, int j, int k) {
if (i == null)
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/net/atlas/combatify/config/ItemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public void loadFromNetwork(FriendlyByteBuf buf) {
BlockingType bType = Combatify.registeredTypes.get(ResourceLocation.tryParse(blockingType));
Double blockStrength = buf1.readDouble();
Double blockKbRes = buf1.readDouble();
Integer enchantlevel = buf1.readInt();
if(damage == -100)
damage = null;
if(speed == -10)
Expand All @@ -330,7 +331,7 @@ public void loadFromNetwork(FriendlyByteBuf buf) {
switch (weaponType) {
case "SWORD", "LONGSWORD", "AXE", "PICKAXE", "HOE", "SHOVEL", "KNIFE", "TRIDENT" -> type = WeaponType.fromID(weaponType);
}
return new ConfigurableItemData(damage, speed, reach, chargedReach, stackSize, cooldown, cooldownAfter, type, bType, blockStrength, blockKbRes);
return new ConfigurableItemData(damage, speed, reach, chargedReach, stackSize, cooldown, cooldownAfter, type, bType, blockStrength, blockKbRes, enchantlevel);
});
configuredWeapons = buf.readMap(buf1 -> WeaponType.fromID(buf1.readUtf()), buf1 -> {
Double damageOffset = buf1.readDouble();
Expand Down Expand Up @@ -378,6 +379,7 @@ public void saveToNetwork(FriendlyByteBuf buf) {
buf12.writeUtf(configurableItemData.blockingType == null ? "blank" : configurableItemData.blockingType.getName().toString());
buf12.writeDouble(configurableItemData.blockStrength == null ? -10 : configurableItemData.blockStrength);
buf12.writeDouble(configurableItemData.blockKbRes == null ? -10 : configurableItemData.blockKbRes);
buf12.writeInt(configurableItemData.enchantability == null ? -10 : configurableItemData.enchantability);
});
buf.writeMap(configuredWeapons, (buf1, type) -> buf1.writeUtf(type.name()), (buf12, configurableWeaponData) -> {
buf12.writeDouble(configurableWeaponData.damageOffset == null ? -10 : configurableWeaponData.damageOffset);
Expand All @@ -401,6 +403,7 @@ public void parseItemConfig(Item item, JsonObject jsonObject) {
BlockingType blockingType = null;
Double blockStrength = null;
Double blockKbRes = null;
Integer enchantment_level = null;
if (jsonObject.has("damage"))
damage = getDouble(jsonObject, "damage");
if (jsonObject.has("speed"))
Expand Down Expand Up @@ -450,7 +453,9 @@ public void parseItemConfig(Item item, JsonObject jsonObject) {
blockStrength = getDouble(jsonObject, "damage_protection");
if (jsonObject.has("block_knockback_resistance"))
blockKbRes = getDouble(jsonObject, "block_knockback_resistance");
ConfigurableItemData configurableItemData = new ConfigurableItemData(damage, speed, reach, chargedReach, stack_size, cooldown, cooldownAfterUse, type, blockingType, blockStrength, blockKbRes);
if (jsonObject.has("enchantment_level"))
cooldown = getInt(jsonObject, "enchantment_level");
ConfigurableItemData configurableItemData = new ConfigurableItemData(damage, speed, reach, chargedReach, stack_size, cooldown, cooldownAfterUse, type, blockingType, blockStrength, blockKbRes, enchantment_level);
configuredItems.put(item, configurableItemData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public int getMaxCost(int level) {

@Override
public boolean canEnchant(ItemStack stack) {
return stack.getItem() instanceof ItemExtensions;
return !((ItemExtensions) stack.getItem()).getBlockingType().isEmpty();
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/atlas/combatify/extensions/Tierable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.atlas.combatify.extensions;

import net.minecraft.world.item.Tier;

public interface Tierable {
Tier getTier();
}
95 changes: 95 additions & 0 deletions src/main/java/net/atlas/combatify/item/TieredShieldItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package net.atlas.combatify.item;

import net.atlas.combatify.Combatify;
import net.atlas.combatify.config.ConfigurableItemData;
import net.atlas.combatify.config.ConfigurableWeaponData;
import net.atlas.combatify.extensions.ItemExtensions;
import net.atlas.combatify.extensions.LivingEntityExtensions;
import net.atlas.combatify.extensions.Tierable;
import net.atlas.combatify.util.BlockingType;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.*;

import static net.atlas.combatify.Combatify.id;
import static net.atlas.combatify.Combatify.shields;
import static net.atlas.combatify.item.ItemRegistry.registerItem;

public class TieredShieldItem extends ShieldItem implements Tierable, ItemExtensions {
public final Tier tier;
public static final Item WOODEN_SHIELD = registerItem(id("wooden_shield"), new TieredShieldItem(Tiers.WOOD, new Item.Properties().durability(Tiers.WOOD.getUses() * 6)));
public static final Item IRON_SHIELD = registerItem(id("iron_shield"), new TieredShieldItem(Tiers.IRON, new Item.Properties().durability(Tiers.IRON.getUses() * 6)));
public static final Item GOLD_SHIELD = registerItem(id("golden_shield"), new TieredShieldItem(Tiers.GOLD, new Item.Properties().durability(Tiers.GOLD.getUses() * 6)));
public static final Item DIAMOND_SHIELD = registerItem(id("diamond_shield"), new TieredShieldItem(Tiers.DIAMOND, new Item.Properties().durability(Tiers.DIAMOND.getUses() * 6)));
public static final Item NETHERITE_SHIELD = registerItem(id("netherite_shield"), new TieredShieldItem(Tiers.NETHERITE, new Item.Properties().durability(Tiers.NETHERITE.getUses() * 6).fireResistant()));

public TieredShieldItem(Tier tier, Properties properties) {
super(properties);
this.tier = tier;
shields.add(this);
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT)
registerModelPredicate();
}

private void registerModelPredicate() {
ItemProperties.register(this, new ResourceLocation("blocking"), (itemStack, clientWorld, livingEntity, i) ->
livingEntity != null && livingEntity.isUsingItem() && ((LivingEntityExtensions)livingEntity).getBlockingItem() == itemStack ? 1.0F : 0.0F);
}


public int getEnchantmentValue() {
return this.tier.getEnchantmentValue();
}

public boolean isValidRepairItem(ItemStack itemStack, ItemStack itemStack2) {
return this.tier.getRepairIngredient().test(itemStack2);
}

@Override
public Tier getTier() {
return tier;
}
public static void init() {

}

@Override
public void setStackSize(int stackSize) {
this.maxStackSize = stackSize;
}

@Override
public double getChargedAttackBonus() {
Item item = this;
double chargedBonus = 1.0;
if(Combatify.ITEMS.configuredItems.containsKey(item)) {
ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(item);
if (configurableItemData.type != null)
if (Combatify.ITEMS.configuredWeapons.containsKey(configurableItemData.type))
if (Combatify.ITEMS.configuredWeapons.get(configurableItemData.type).chargedReach != null)
chargedBonus = Combatify.ITEMS.configuredWeapons.get(configurableItemData.type).chargedReach;
if (configurableItemData.chargedReach != null)
chargedBonus = configurableItemData.chargedReach;
}
return chargedBonus;
}

@Override
public BlockingType getBlockingType() {
if(Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(this)) {
ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(this);
if (configurableItemData.blockingType != null) {
return configurableItemData.blockingType;
}
if (configurableItemData.type != null && Combatify.ITEMS.configuredWeapons.containsKey(configurableItemData.type)) {
ConfigurableWeaponData configurableWeaponData = Combatify.ITEMS.configuredWeapons.get(configurableItemData.type);
if (configurableWeaponData.blockingType != null) {
return configurableWeaponData.blockingType;
}
}
}
return Combatify.registeredTypes.get(new ResourceLocation("new_shield"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,49 @@

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import net.atlas.combatify.Combatify;
import net.atlas.combatify.config.ConfigurableItemData;
import net.atlas.combatify.extensions.CustomEnchantment;
import net.atlas.combatify.extensions.ItemExtensions;
import net.atlas.combatify.util.CustomEnchantmentHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@SuppressWarnings("unused")
@Mixin(EnchantmentHelper.class)
public abstract class EnchantmentHelperMixin implements CustomEnchantmentHelper {
@SuppressWarnings("unused")
@ModifyExpressionValue(method = "getAvailableEnchantmentResults", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentCategory;canEnchant(Lnet/minecraft/world/item/Item;)Z"))
private static boolean redirectCanEnchant(boolean original, @Local(ordinal = 0) Enchantment currentEnchantment, @Local(ordinal = 0) ItemStack itemStack) {
return currentEnchantment instanceof CustomEnchantment customEnchantment && itemStack != null ? customEnchantment.isAcceptibleConditions(itemStack) : original;
}

@ModifyExpressionValue(method = "getEnchantmentCost", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/Item;getEnchantmentValue()I"))
private static int getEnchantmentValue(int original, @Local(ordinal = 0) ItemStack stack) {
if(Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) {
ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem());
if (configurableItemData.enchantability != null) {
return configurableItemData.enchantability;
}
}
if(!((ItemExtensions)stack.getItem()).getBlockingType().isEmpty() && original == 0) {
return 14;
}
return original;
}
@ModifyExpressionValue(method = "selectEnchantment", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/Item;getEnchantmentValue()I"))
private static int getEnchantmentValue1(int original, @Local(ordinal = 0) ItemStack stack) {
if(Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) {
ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem());
if (configurableItemData.enchantability != null) {
return configurableItemData.enchantability;
}
}
if(!((ItemExtensions)stack.getItem()).getBlockingType().isEmpty() && original == 0) {
return 14;
}
return original;
}
}
9 changes: 9 additions & 0 deletions src/main/java/net/atlas/combatify/mixin/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public abstract class ItemStackMixin {
@Final
public static DecimalFormat ATTRIBUTE_MODIFIER_FORMAT;

@Shadow
public abstract boolean isEnchanted();

@Inject(method = "getTooltipLines", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;hasTag()Z", ordinal = 0))
public void addHoverText(@Nullable Player player, TooltipFlag tooltipFlag, CallbackInfoReturnable<List<Component>> cir, @Local(ordinal = 0) List<Component> tooltip) {
ItemExtensions item = (ItemExtensions) getItem();
Expand Down Expand Up @@ -173,6 +176,12 @@ public InteractionResult addBlockAbility(InteractionResult original, @Local(ordi
}
return original;
}

@ModifyReturnValue(method = "isEnchantable", at = @At(value = "RETURN"))
public boolean addEnchantability(boolean original) {
return (!((ItemExtensions)getItem()).getBlockingType().isEmpty() && !isEnchanted()) || original;
}

@ModifyReturnValue(method = "use", at = @At(value = "RETURN"))
public InteractionResultHolder<ItemStack> addBlockAbility(InteractionResultHolder<ItemStack> original, @Local(ordinal = 0) Level world, @Local(ordinal = 0) Player player, @Local(ordinal = 0) InteractionHand hand) {
InteractionResultHolder<ItemStack> holder = null;
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/net/atlas/combatify/mixin/PiglinAiMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.atlas.combatify.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.sugar.Local;
import net.atlas.combatify.item.TieredShieldItem;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.piglin.PiglinAi;
import net.minecraft.world.item.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@SuppressWarnings("unused")
@Mixin(PiglinAi.class)
public class PiglinAiMixin {
@ModifyReturnValue(method = "isWearingGold", at = @At(value = "RETURN"))
private static boolean includeHoldingShield(boolean original, @Local(ordinal = 0) LivingEntity livingEntity) {
boolean bl = false;
Iterable<ItemStack> iterable = livingEntity.getHandSlots();

for (ItemStack itemStack : iterable) {
Item item = itemStack.getItem();
if(item instanceof TieredShieldItem tieredShield && tieredShield.getTier() == Tiers.GOLD) {
bl = true;
}
}

return original || bl;
}
}
5 changes: 5 additions & 0 deletions src/main/java/net/atlas/combatify/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
import net.atlas.combatify.Combatify;
import net.atlas.combatify.item.NewAttributes;
import net.atlas.combatify.item.TieredShieldItem;
import net.atlas.combatify.util.CustomEnchantmentHelper;
import net.atlas.combatify.extensions.*;
import net.minecraft.core.particles.ParticleTypes;
Expand Down Expand Up @@ -130,6 +131,10 @@ public void blockUsingShield(@NotNull LivingEntity attacker, CallbackInfo ci) {
@Override
public boolean ctsShieldDisable(float damage, Item item) {
player.getCooldowns().addCooldown(item, (int)(damage * 20.0F));
if (item instanceof TieredShieldItem)
for (TieredShieldItem tieredShieldItem : Combatify.shields)
if (item != tieredShieldItem)
player.getCooldowns().addCooldown(tieredShieldItem, (int)(damage * 20.0F));
player.stopUsingItem();
player.level().broadcastEntityEvent(player, (byte)30);
return true;
Expand Down
Loading

0 comments on commit 7d5cc09

Please sign in to comment.