Skip to content

Commit d767ceb

Browse files
Combatify 1.21.1 1.3.0 Fabric - me when major version did the bump
1 parent acf1152 commit d767ceb

19 files changed

Lines changed: 243 additions & 298 deletions

File tree

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx3G
33
org.gradle.parallel = true
44

55
# Mod Properties
6-
mod_version = 1.2.13
6+
mod_version = 1.3.0
77
maven_group = net.atlas
88
archives_base_name = combatify
99
sub_version = release
@@ -16,7 +16,7 @@ toml4j_version=0.7.2
1616
rhino_version=1.8.0
1717
sodium_version=mc1.21.1-0.6.13-fabric
1818
atlas_core_version=1.1.2.beta.4-1.21.x-Fabric
19-
defaulted_version=1.21-1.1.6-Fabric
19+
defaulted_version=1.2.1-1.21.1-Fabric
2020
viafabricplus_version=3.4.9
2121
modmenu_version=11.0.1
2222
cloth_config_version=15.0.127

src/main/java/net/atlas/combatify/CombatifyClient.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
package net.atlas.combatify;
22

33
import com.mojang.serialization.Codec;
4-
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
5-
import net.atlas.combatify.client.ShieldMaterial;
64
import net.atlas.combatify.config.DualAttackIndicatorStatus;
75
import net.atlas.combatify.config.ShieldIndicatorStatus;
86
import net.atlas.combatify.networking.ClientNetworkingHandler;
97
import net.fabricmc.api.ClientModInitializer;
10-
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
118
import net.fabricmc.fabric.api.util.TriState;
12-
import net.minecraft.Util;
139
import net.minecraft.client.AttackIndicatorStatus;
1410
import net.minecraft.client.OptionInstance;
15-
import net.minecraft.client.model.ShieldModel;
16-
import net.minecraft.client.model.geom.ModelLayerLocation;
1711
import net.minecraft.network.chat.CommonComponents;
1812
import net.minecraft.network.chat.Component;
1913
import net.minecraft.util.Mth;
20-
import net.minecraft.world.item.Tier;
21-
import net.minecraft.world.item.Tiers;
2214

2315
import java.util.Arrays;
2416
import java.util.Objects;
@@ -27,13 +19,6 @@
2719
import static net.minecraft.client.Options.percentValueLabel;
2820

2921
public class CombatifyClient implements ClientModInitializer {
30-
public static final ModelLayerLocation WOODEN_SHIELD_MODEL_LAYER = new ModelLayerLocation(Combatify.id("wooden_shield"),"main");
31-
public static final ModelLayerLocation IRON_SHIELD_MODEL_LAYER = new ModelLayerLocation(Combatify.id("iron_shield"),"main");
32-
public static final ModelLayerLocation GOLDEN_SHIELD_MODEL_LAYER = new ModelLayerLocation(Combatify.id("golden_shield"),"main");
33-
public static final ModelLayerLocation DIAMOND_SHIELD_MODEL_LAYER = new ModelLayerLocation(Combatify.id("diamond_shield"),"main");
34-
public static final ModelLayerLocation NETHERITE_SHIELD_MODEL_LAYER = new ModelLayerLocation(Combatify.id("netherite_shield"),"main");
35-
public static final Object2ObjectOpenHashMap<Tier, ModelLayerLocation> tieredShieldModelLayers = Util.make(new Object2ObjectOpenHashMap<>(), map -> map.defaultReturnValue(WOODEN_SHIELD_MODEL_LAYER));
36-
public static final Object2ObjectOpenHashMap<Tier, ShieldMaterial> tieredShieldMaterials = Util.make(new Object2ObjectOpenHashMap<>(), map -> map.defaultReturnValue(ShieldMaterial.WOODEN_SHIELD));
3722
public static final OptionInstance<Boolean> autoAttack = OptionInstance.createBoolean("options.autoAttack", true);
3823
public static final OptionInstance<Boolean> shieldCrouch = OptionInstance.createBoolean("options.shieldCrouch", true);
3924
public static final OptionInstance<TriState> rhythmicAttacks = new OptionInstance<>(
@@ -141,20 +126,5 @@ public void onInitializeClient() {
141126
Combatify.LOGGER.info("Client init started.");
142127
ClientNetworkingHandler.init();
143128
Combatify.markState(combatifyState::get);
144-
if (Combatify.CONFIG.tieredShields()) {
145-
EntityModelLayerRegistry.registerModelLayer(WOODEN_SHIELD_MODEL_LAYER, ShieldModel::createLayer);
146-
EntityModelLayerRegistry.registerModelLayer(IRON_SHIELD_MODEL_LAYER, ShieldModel::createLayer);
147-
EntityModelLayerRegistry.registerModelLayer(GOLDEN_SHIELD_MODEL_LAYER, ShieldModel::createLayer);
148-
EntityModelLayerRegistry.registerModelLayer(DIAMOND_SHIELD_MODEL_LAYER, ShieldModel::createLayer);
149-
EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, ShieldModel::createLayer);
150-
tieredShieldModelLayers.put(Tiers.IRON, IRON_SHIELD_MODEL_LAYER);
151-
tieredShieldModelLayers.put(Tiers.GOLD, GOLDEN_SHIELD_MODEL_LAYER);
152-
tieredShieldModelLayers.put(Tiers.DIAMOND, DIAMOND_SHIELD_MODEL_LAYER);
153-
tieredShieldModelLayers.put(Tiers.NETHERITE, NETHERITE_SHIELD_MODEL_LAYER);
154-
tieredShieldMaterials.put(Tiers.IRON, ShieldMaterial.IRON_SHIELD);
155-
tieredShieldMaterials.put(Tiers.GOLD, ShieldMaterial.GOLDEN_SHIELD);
156-
tieredShieldMaterials.put(Tiers.DIAMOND, ShieldMaterial.DIAMOND_SHIELD);
157-
tieredShieldMaterials.put(Tiers.NETHERITE, ShieldMaterial.NETHERITE_SHIELD);
158-
}
159129
}
160130
}

src/main/java/net/atlas/combatify/client/ShieldMaterial.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import net.minecraft.client.renderer.texture.TextureAtlas;
44
import net.minecraft.client.resources.model.Material;
5-
import net.minecraft.client.resources.model.ModelBakery;
65
import net.minecraft.resources.ResourceLocation;
76

87
public record ShieldMaterial(Material base, Material baseNoPattern) {
9-
public static final ShieldMaterial WOODEN_SHIELD = new ShieldMaterial(ModelBakery.SHIELD_BASE, ModelBakery.NO_PATTERN_SHIELD);
108
public static final ShieldMaterial IRON_SHIELD = new ShieldMaterial(new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.withDefaultNamespace("combatify/iron_shield_base")), new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.withDefaultNamespace("combatify/iron_shield_base_nopattern")));
119
public static final ShieldMaterial GOLDEN_SHIELD = new ShieldMaterial(new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.withDefaultNamespace("combatify/golden_shield_base")), new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.withDefaultNamespace("combatify/golden_shield_base_nopattern")));
1210
public static final ShieldMaterial DIAMOND_SHIELD = new ShieldMaterial(new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.withDefaultNamespace("combatify/diamond_shield_base")), new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.withDefaultNamespace("combatify/diamond_shield_base_nopattern")));

src/main/java/net/atlas/combatify/component/generators/WeaponStatsGenerator.java

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import net.minecraft.world.item.component.ItemAttributeModifiers;
2626
import net.minecraft.world.item.component.ItemAttributeModifiers.Entry;
2727

28-
public record WeaponStatsGenerator(List<WeaponLevelBasedValue> damage, List<WeaponLevelBasedValue> speed, List<WeaponLevelBasedValue> reach, Optional<ResourceLocation> damageIdOverride, Optional<ResourceLocation> speedIdOverride, Optional<ResourceLocation> reachIdOverride, List<ItemAttributeModifiers.Entry> additionalModifiers, boolean tieredDamage, boolean persistPrevious) implements PatchGenerator {
28+
public record WeaponStatsGenerator(Optional<WeaponLevelBasedValue> damage, Optional<WeaponLevelBasedValue> speed, Optional<WeaponLevelBasedValue> reach, Optional<ResourceLocation> damageIdOverride, Optional<ResourceLocation> speedIdOverride, Optional<ResourceLocation> reachIdOverride, List<ItemAttributeModifiers.Entry> additionalModifiers, boolean tieredDamage, boolean persistPrevious) implements PatchGenerator {
2929
public static final MapCodec<WeaponStatsGenerator> CODEC = RecordCodecBuilder.mapCodec(instance ->
30-
instance.group(WeaponLevelBasedValue.CODEC.optionalFieldOf("attack_damage", Collections.emptyList()).forGetter(WeaponStatsGenerator::damage),
31-
WeaponLevelBasedValue.CODEC.optionalFieldOf("attack_speed", Collections.emptyList()).forGetter(WeaponStatsGenerator::speed),
32-
WeaponLevelBasedValue.CODEC.optionalFieldOf("attack_reach", Collections.emptyList()).forGetter(WeaponStatsGenerator::reach),
30+
instance.group(WeaponLevelBasedValue.CODEC.optionalFieldOf("attack_damage").forGetter(WeaponStatsGenerator::damage),
31+
WeaponLevelBasedValue.CODEC.optionalFieldOf("attack_speed").forGetter(WeaponStatsGenerator::speed),
32+
WeaponLevelBasedValue.CODEC.optionalFieldOf("attack_reach").forGetter(WeaponStatsGenerator::reach),
3333
ResourceLocation.CODEC.optionalFieldOf("damage_id_override").forGetter(WeaponStatsGenerator::damageIdOverride),
3434
ResourceLocation.CODEC.optionalFieldOf("speed_id_override").forGetter(WeaponStatsGenerator::speedIdOverride),
3535
ResourceLocation.CODEC.optionalFieldOf("reach_id_override").forGetter(WeaponStatsGenerator::reachIdOverride),
@@ -49,21 +49,21 @@ public void patchDataComponentMap(Item item, PatchedDataComponentMap patchedData
4949
ResourceLocation reachID = reachIdOverride.orElse(WeaponType.BASE_ATTACK_REACH_ID);
5050
AttributeModifier attackDamage = null;
5151
boolean hasDamage = false;
52-
if (!damage.isEmpty()) {
52+
if (damage.isPresent()) {
5353
hasDamage = true;
54-
attackDamage = new AttributeModifier(damageID, getTierModifier(toolMaterialWrapper, true, damage) + damageModifier, AttributeModifier.Operation.ADD_VALUE);
54+
attackDamage = new AttributeModifier(damageID, damage.get().getResult(toolMaterialWrapper.weaponLevel(), toolMaterialWrapper.attackDamageBonus(), tieredDamage) + damageModifier, AttributeModifier.Operation.ADD_VALUE);
5555
}
5656
AttributeModifier attackSpeed = null;
5757
boolean hasSpeed = false;
58-
if (!speed.isEmpty()) {
58+
if (speed.isPresent()) {
5959
hasSpeed = true;
60-
attackSpeed = new AttributeModifier(speedID, getTierModifier(toolMaterialWrapper, false, speed), AttributeModifier.Operation.ADD_VALUE);
60+
attackSpeed = new AttributeModifier(speedID, speed.get().getResult(toolMaterialWrapper.speedLevel(), true), AttributeModifier.Operation.ADD_VALUE);
6161
}
6262
AttributeModifier attackReach = null;
6363
boolean hasReach = false;
64-
if (!reach.isEmpty()) {
64+
if (reach.isPresent()) {
6565
hasReach = true;
66-
attackReach = new AttributeModifier(reachID, getTierModifier(toolMaterialWrapper, false, reach), AttributeModifier.Operation.ADD_VALUE);
66+
attackReach = new AttributeModifier(reachID, reach.get().getResult(toolMaterialWrapper.weaponLevel(), true), AttributeModifier.Operation.ADD_VALUE);
6767
}
6868
if (!(hasDamage || hasSpeed)) return;
6969

@@ -89,22 +89,6 @@ private boolean isSpeed(Entry entry, ResourceLocation speedID) {
8989
return baseRet;
9090
}
9191

92-
private double getTierModifier(ToolMaterialWrapper tier, boolean forDamage, List<WeaponLevelBasedValue> list) {
93-
if (forDamage)
94-
for (WeaponLevelBasedValue value : list) {
95-
if (value instanceof WeaponLevelBasedValue.Unconditional unconditional) return unconditional.value() + (tieredDamage ? tier.attackDamageBonus() : 0);
96-
else {
97-
Float res = value.getResult(tier.weaponLevel(), tieredDamage);
98-
if (res != null) return res;
99-
}
100-
}
101-
else for (WeaponLevelBasedValue value : list) {
102-
Float res = value.getResult(tier.weaponLevel(), true);
103-
if (res != null) return res;
104-
}
105-
return 0;
106-
}
107-
10892
@Override
10993
public MapCodec<? extends PatchGenerator> codec() {
11094
return CODEC;

src/main/java/net/atlas/combatify/config/JSImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public JSImpl(String fileName) {
3434
try {
3535
reader = new BufferedReader(new FileReader(FabricLoader.getInstance().getConfigDirectory().getAbsolutePath() + "/" + fileName + ".js"));
3636
readFileData = Kit.readReader(reader);
37+
String defineVariables = readFileData.substring(0, readFileData.indexOf("function"));
38+
readFileData = readFileData.substring(readFileData.indexOf("function"));
39+
if (!defineVariables.isBlank()) CONTEXT.get().evaluateString(scope, defineVariables, "", 0, null);
3740
} catch (IOException e) {
3841
Combatify.JS_LOGGER.error("Error parsing JS File " + fileName + ". Exception: {}", e);
3942
readFileData = "";

src/main/java/net/atlas/combatify/config/wrapper/EntityWrapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121
import java.util.Objects;
2222
import java.util.Optional;
23+
import java.util.UUID;
2324

2425
public class EntityWrapper<E extends Entity> implements GenericAPIWrapper<E> {
2526
public final E value;
@@ -36,6 +37,10 @@ public final String getType() {
3637
return BuiltInRegistries.ENTITY_TYPE.getKey(value.getType()).toString();
3738
}
3839

40+
public final UUID getUUID() {
41+
return value.getUUID();
42+
}
43+
3944
public final boolean isLivingEntity() {
4045
return value instanceof LivingEntity;
4146
}

src/main/java/net/atlas/combatify/config/wrapper/LivingEntityWrapper.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,28 @@ public final boolean isOnCooldown(ItemStackWrapper itemStackWrapper) {
1818
return MethodHandler.isItemOnCooldown(value, itemStackWrapper.value());
1919
}
2020

21+
public final void resetAttackStrengthTicker(boolean hit) {
22+
value.combatify$resetAttackStrengthTicker(hit);
23+
}
24+
25+
public final void resetAttackStrengthTicker(boolean hit, boolean force) {
26+
value.combatify$resetAttackStrengthTicker(hit, force);
27+
}
28+
29+
public final void swingInHand(String hand) {
30+
value.swing(InteractionHand.valueOf(hand.toUpperCase()));
31+
}
32+
33+
public final void swingInHand(String hand, boolean force) {
34+
value.swing(InteractionHand.valueOf(hand.toUpperCase()), force);
35+
}
36+
2137
public final ItemStackWrapper getItemInHand(String hand) {
22-
return new ItemStackWrapper(value.getItemInHand(InteractionHand.valueOf(hand)));
38+
return new ItemStackWrapper(value.getItemInHand(InteractionHand.valueOf(hand.toUpperCase())));
2339
}
2440

2541
public final ItemStackWrapper getItemInSlot(String slot) {
26-
return new ItemStackWrapper(value.getItemBySlot(EquipmentSlot.valueOf(slot)));
42+
return new ItemStackWrapper(value.getItemBySlot(EquipmentSlot.valueOf(slot.toUpperCase())));
2743
}
2844

2945
public final FakeUseItemWrapper getBlockingItem() {
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package net.atlas.combatify.config.wrapper;
22

3+
import net.atlas.combatify.Combatify;
34
import net.atlas.combatify.util.MethodHandler;
4-
import net.minecraft.world.InteractionHand;
55
import net.minecraft.world.entity.player.Player;
66

77
public class PlayerWrapper<P extends Player> extends LivingEntityWrapper<P> {
@@ -13,6 +13,19 @@ public final ItemStackWrapper getInventoryItem(int slotID) {
1313
return new ItemStackWrapper(value.getInventory().getItem(slotID));
1414
}
1515

16+
public final boolean isAttackAvailable(float baseTime) {
17+
return value.combatify$isAttackAvailable(baseTime);
18+
}
19+
20+
// Respect future versions
21+
public final boolean isAttackAvailable(float baseTime, ItemStackWrapper stack) {
22+
return value.combatify$isAttackAvailable(baseTime);
23+
}
24+
25+
public final boolean isChargeAttack(float baseTime) {
26+
return value.getAttackStrengthScale(baseTime) > (Combatify.CONFIG.chargedAttacks() ? 1.95 : 0.9);
27+
}
28+
1629
public final float getAttackStrengthScale(float baseTime) {
1730
return value.getAttackStrengthScale(baseTime);
1831
}
@@ -21,16 +34,22 @@ public final double getCurrentAttackReach(float baseTime) {
2134
return MethodHandler.getCurrentAttackReach(value, baseTime);
2235
}
2336

24-
public final void resetAttackStrengthTicker(boolean hit) {
25-
value.combatify$resetAttackStrengthTicker(hit);
37+
public final void attack(EntityWrapper<?> entityWrapper) {
38+
value.attack(entityWrapper.value);
2639
}
2740

28-
public final void attack(EntityWrapper<?> entityWrapper) {
41+
public final void stabAttack(String slot, EntityWrapper<?> entityWrapper, float damage, boolean dealDamage, boolean dealKnockback, boolean dismountTarget) {
42+
// Don't crash, but just do a normal attack instead
2943
value.attack(entityWrapper.value);
44+
Combatify.JS_LOGGER.warn("Attempted to call stabAttack() on version before Mounts of Mayhem! Falling back to standard attack.");
3045
}
3146

3247
public final void attackAir() {
33-
value.swing(InteractionHand.MAIN_HAND);
3448
value.combatify$attackAir();
3549
}
50+
51+
public final void lungeForwardMaybe() {
52+
// Do nothing, just let the game not crash
53+
Combatify.JS_LOGGER.warn("Attempted to call lungeForwardMaybe() on version before Mounts of Mayhem!");
54+
}
3655
}

src/main/java/net/atlas/combatify/extensions/PlayerExtensions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.atlas.combatify.extensions;
22

33
import net.minecraft.world.InteractionHand;
4+
import net.minecraft.world.damagesource.DamageSource;
5+
import net.minecraft.world.entity.LivingEntity;
46

57
public interface PlayerExtensions extends ClientInformationHolder {
68
default void combatify$customSwing(InteractionHand interactionHand) {
@@ -14,4 +16,8 @@ public interface PlayerExtensions extends ClientInformationHolder {
1416
default void combatify$attackAir() {
1517
throw new IllegalStateException("Extension has not been applied");
1618
}
19+
20+
default float combatify$enchantedDamageForSweep(LivingEntity livingEntity, float damage, DamageSource damageSource) {
21+
throw new IllegalStateException("Extension has not been applied");
22+
}
1723
}

src/main/java/net/atlas/combatify/mixin/LivingEntityMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public LivingEntityMixin(EntityType<?> entityType, Level level) {
7575
@Inject(method = "tick", at = @At(value = "RETURN"))
7676
public void tickCooldowns(CallbackInfo ci) {
7777
fallbackCooldowns.tick();
78-
if (!(LivingEntity.class.cast(this) instanceof Player))
78+
if (!(thisEntity instanceof Player))
7979
attackStrengthTicker++;
8080
}
8181

0 commit comments

Comments
 (0)