Skip to content

Commit

Permalink
Combatify 1.2.0 1.20.5+ Beta 7 - Everything I did, I did for YOU
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra-Myers committed May 3, 2024
1 parent c7d27a4 commit 142cd36
Show file tree
Hide file tree
Showing 8 changed files with 525 additions and 414 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation include("net.atlas:atlas-lib:1.0.1")
modImplementation include("net.atlas:atlas-lib:1.0.2")
modApi "com.terraformersmc:modmenu:10.0.0-alpha.1"
modApi "me.shedaniel.cloth:cloth-config-fabric:14.0.125"

Expand Down
Binary file modified libs/atlas-lib.jar
Binary file not shown.
35 changes: 27 additions & 8 deletions src/main/java/net/atlas/combatify/Combatify.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.atlas.combatify.config.CombatifyBetaConfig;
import net.atlas.combatify.config.ItemConfig;
import net.atlas.combatify.enchantment.DefendingEnchantment;
import net.atlas.combatify.extensions.ExtendedTier;
import net.atlas.combatify.item.CombatifyItemTags;
import net.atlas.combatify.item.ItemRegistry;
import net.atlas.combatify.item.TieredShieldItem;
Expand All @@ -20,11 +21,16 @@
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.*;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.DispenserBlock;
import org.apache.logging.log4j.LogManager;

import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static net.minecraft.world.item.Items.NETHERITE_SWORD;

Expand All @@ -38,20 +44,22 @@ public class Combatify implements ModInitializer {
public static final List<UUID> unmoddedPlayers = new ArrayListExtensions<>();
public static final List<UUID> moddedPlayers = new ArrayListExtensions<>();
public static final Map<UUID, Boolean> isPlayerAttacking = new HashMap<>();
public static final Map<String, WeaponType> defaultWeaponTypes = new HashMap<>();
public static final Map<String, BlockingType> defaultTypes = new HashMap<>();
public static final BiMap<String, Tier> defaultTiers = HashBiMap.create();
public static Map<String, WeaponType> registeredWeaponTypes = new HashMap<>();
public static Map<String, BlockingType> registeredTypes = new HashMap<>();
public static BiMap<String, Tier> tiers = HashBiMap.create();
public static final PrefixLogger LOGGER = new PrefixLogger(LogManager.getLogger("Combatify"));
public static final BlockingType SWORD = registerBlockingType(new SwordBlockingType("sword").setToolBlocker(true).setDisablement(false).setCrouchable(false).setBlockHit(true).setRequireFullCharge(false).setSwordBlocking(true).setDelay(false));
public static final BlockingType SHIELD = registerBlockingType(new ShieldBlockingType("shield"));
public static final BlockingType CURRENT_SHIELD = registerBlockingType(new CurrentShieldBlockingType("current_shield"));
public static final BlockingType NEW_SHIELD = registerBlockingType(new NewShieldBlockingType("new_shield").setKbMechanics(false));
public static final BlockingType SWORD = defineDefaultBlockingType(new SwordBlockingType("sword").setToolBlocker(true).setDisablement(false).setCrouchable(false).setBlockHit(true).setRequireFullCharge(false).setSwordBlocking(true).setDelay(false));
public static final BlockingType SHIELD = defineDefaultBlockingType(new ShieldBlockingType("shield"));
public static final BlockingType CURRENT_SHIELD = defineDefaultBlockingType(new CurrentShieldBlockingType("current_shield"));
public static final BlockingType NEW_SHIELD = defineDefaultBlockingType(new NewShieldBlockingType("new_shield").setKbMechanics(false));
public static final BlockingType EMPTY = new EmptyBlockingType("empty").setDisablement(false).setCrouchable(false).setRequireFullCharge(false).setKbMechanics(false);

@Override
public void onInitialize() {
if (registeredWeaponTypes.isEmpty())
WeaponType.init();
WeaponType.init();
networkingHandler = new NetworkingHandler();
LOGGER.info("Init started.");
CombatifyItemTags.init();
Expand Down Expand Up @@ -84,4 +92,15 @@ public static <T extends BlockingType> T registerBlockingType(T blockingType) {
public static ResourceLocation id(String path) {
return new ResourceLocation(MOD_ID, path);
}
public static void defineDefaultWeaponType(WeaponType type) {
defaultWeaponTypes.put(type.name, type);
}
public static <T extends BlockingType> T defineDefaultBlockingType(T blockingType) {
defaultTypes.put(blockingType.getName(), blockingType);
return registerBlockingType(blockingType);
}
public static void defineDefaultTier(String name, ExtendedTier tier) {
defaultTiers.put(name, tier);
tiers.put(name, tier);
}
}
110 changes: 110 additions & 0 deletions src/main/java/net/atlas/combatify/config/ConfigurableItemData.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,121 @@
package net.atlas.combatify.config;

import net.atlas.combatify.Combatify;
import net.atlas.combatify.item.WeaponType;
import net.atlas.combatify.util.BlockingType;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.crafting.Ingredient;

import static net.atlas.combatify.Combatify.registeredWeaponTypes;
import static net.atlas.combatify.config.ItemConfig.getTier;
import static net.atlas.combatify.config.ItemConfig.getTierName;

public class ConfigurableItemData {
public static final StreamCodec<RegistryFriendlyByteBuf, ConfigurableItemData> ITEM_DATA_STREAM_CODEC = StreamCodec.of((buf, configurableItemData) -> {
buf.writeDouble(configurableItemData.damage == null ? -10 : configurableItemData.damage);
buf.writeDouble(configurableItemData.speed == null ? -10 : configurableItemData.speed);
buf.writeDouble(configurableItemData.reach == null ? -10 : configurableItemData.reach);
buf.writeDouble(configurableItemData.chargedReach == null ? -10 : configurableItemData.chargedReach);
buf.writeVarInt(configurableItemData.stackSize == null ? -10 : configurableItemData.stackSize);
buf.writeVarInt(configurableItemData.durability == null ? -10 : configurableItemData.durability);
buf.writeInt(configurableItemData.cooldown == null ? -10 : configurableItemData.cooldown);
if(configurableItemData.cooldown != null)
buf.writeBoolean(configurableItemData.cooldownAfter);
buf.writeUtf(configurableItemData.type == null ? "empty" : configurableItemData.type.name);
buf.writeUtf(configurableItemData.blockingType == null ? "blank" : configurableItemData.blockingType.getName());
buf.writeDouble(configurableItemData.blockStrength == null ? -10 : configurableItemData.blockStrength);
buf.writeDouble(configurableItemData.blockKbRes == null ? -10 : configurableItemData.blockKbRes);
buf.writeInt(configurableItemData.enchantability == null ? -10 : configurableItemData.enchantability);
buf.writeInt(configurableItemData.isEnchantable == null ? -10 : configurableItemData.isEnchantable ? 1 : 0);
buf.writeInt(configurableItemData.hasSwordEnchants == null ? -10 : configurableItemData.hasSwordEnchants ? 1 : 0);
buf.writeInt(configurableItemData.isPrimaryForSwordEnchants == null ? -10 : configurableItemData.isPrimaryForSwordEnchants ? 1 : 0);
buf.writeInt(configurableItemData.useDuration == null ? -10 : configurableItemData.useDuration);
buf.writeDouble(configurableItemData.piercingLevel == null ? -10 : configurableItemData.piercingLevel);
buf.writeInt(configurableItemData.canSweep == null ? -10 : configurableItemData.canSweep ? 1 : 0);
buf.writeUtf(configurableItemData.tier == null ? "empty" : getTierName(configurableItemData.tier));
buf.writeInt(configurableItemData.defense == null ? -10 : configurableItemData.defense);
buf.writeDouble(configurableItemData.toughness == null ? -10 : configurableItemData.toughness);
buf.writeDouble(configurableItemData.armourKbRes == null ? -10 : configurableItemData.armourKbRes);
buf.writeBoolean(configurableItemData.repairIngredient == null);
if (configurableItemData.repairIngredient != null)
Ingredient.CONTENTS_STREAM_CODEC.encode(buf, configurableItemData.repairIngredient);
}, buf -> {
Double damage = buf.readDouble();
Double speed = buf.readDouble();
Double reach = buf.readDouble();
Double chargedReach = buf.readDouble();
Integer stackSize = buf.readVarInt();
Integer durability = buf.readVarInt();
Integer cooldown = buf.readInt();
Boolean cooldownAfter = null;
if (cooldown != -10)
cooldownAfter = buf.readBoolean();
String weaponType = buf.readUtf();
WeaponType type = null;
String blockingType = buf.readUtf();
BlockingType bType = Combatify.registeredTypes.get(blockingType);
Double blockStrength = buf.readDouble();
Double blockKbRes = buf.readDouble();
Integer enchantlevel = buf.readInt();
int isEnchantableAsInt = buf.readInt();
int hasSwordEnchantsAsInt = buf.readInt();
int isPrimaryForSwordEnchantsAsInt = buf.readInt();
Boolean isEnchantable = null;
Boolean hasSwordEnchants = null;
Boolean isPrimaryForSwordEnchants = null;
Integer useDuration = buf.readInt();
Double piercingLevel = buf.readDouble();
int canSweepAsInt = buf.readInt();
Boolean canSweep = null;
Tier tier = getTier(buf.readUtf());
Integer defense = buf.readInt();
Double toughness = buf.readDouble();
Double armourKbRes = buf.readDouble();
Ingredient ingredient = buf.readBoolean() ? null : Ingredient.CONTENTS_STREAM_CODEC.decode(buf);
if (damage == -10)
damage = null;
if (speed == -10)
speed = null;
if (reach == -10)
reach = null;
if (chargedReach == -10)
chargedReach = null;
if (stackSize == -10)
stackSize = null;
if (durability == -10)
durability = null;
if (cooldown == -10)
cooldown = null;
if (blockStrength == -10)
blockStrength = null;
if (blockKbRes == -10)
blockKbRes = null;
if (enchantlevel == -10)
enchantlevel = null;
if (isEnchantableAsInt != -10)
isEnchantable = isEnchantableAsInt == 1;
if (hasSwordEnchantsAsInt != -10)
hasSwordEnchants = hasSwordEnchantsAsInt == 1;
if (isPrimaryForSwordEnchantsAsInt != -10)
isPrimaryForSwordEnchants = isPrimaryForSwordEnchantsAsInt == 1;
if (useDuration == -10)
useDuration = null;
if (piercingLevel == -10)
piercingLevel = null;
if (canSweepAsInt != -10)
canSweep = canSweepAsInt == 1;
if (registeredWeaponTypes.containsKey(weaponType))
type = WeaponType.fromID(weaponType);
if (defense == -10)
defense = null;
if (toughness == -10)
toughness = null;
if (armourKbRes == -10)
armourKbRes = null;
return new ConfigurableItemData(damage, speed, reach, chargedReach, stackSize, cooldown, cooldownAfter, type, bType, blockStrength, blockKbRes, enchantlevel, isEnchantable, hasSwordEnchants, isPrimaryForSwordEnchants, useDuration, piercingLevel, canSweep, tier, durability, defense, toughness, armourKbRes, ingredient);
});
public final Double damage;
public final Double speed;
public final Double reach;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,55 @@
package net.atlas.combatify.config;

import net.atlas.combatify.Combatify;
import net.atlas.combatify.util.BlockingType;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;

public class ConfigurableWeaponData {
public static final StreamCodec<RegistryFriendlyByteBuf, ConfigurableWeaponData> WEAPON_DATA_STREAM_CODEC = StreamCodec.of((buf, configurableWeaponData) -> {
buf.writeDouble(configurableWeaponData.damageOffset == null ? -10 : configurableWeaponData.damageOffset);
buf.writeDouble(configurableWeaponData.speed == null ? -10 : configurableWeaponData.speed);
buf.writeDouble(configurableWeaponData.reach == null ? -10 : configurableWeaponData.reach);
buf.writeDouble(configurableWeaponData.chargedReach == null ? -10 : configurableWeaponData.chargedReach);
buf.writeBoolean(configurableWeaponData.tierable);
buf.writeUtf(configurableWeaponData.blockingType == null ? "blank" : configurableWeaponData.blockingType.getName());
buf.writeInt(configurableWeaponData.hasSwordEnchants == null ? -10 : configurableWeaponData.hasSwordEnchants ? 1 : 0);
buf.writeInt(configurableWeaponData.isPrimaryForSwordEnchants == null ? -10 : configurableWeaponData.isPrimaryForSwordEnchants ? 1 : 0);
buf.writeDouble(configurableWeaponData.piercingLevel == null ? -10 : configurableWeaponData.piercingLevel);
buf.writeInt(configurableWeaponData.canSweep == null ? -10 : configurableWeaponData.canSweep ? 1 : 0);
}, buf -> {
Double damageOffset = buf.readDouble();
Double speed = buf.readDouble();
Double reach = buf.readDouble();
Double chargedReach = buf.readDouble();
Boolean tierable = buf.readBoolean();
String blockingType = buf.readUtf();
BlockingType bType = Combatify.registeredTypes.get(blockingType);
int hasSwordEnchantsAsInt = buf.readInt();
Boolean hasSwordEnchants = null;
int isPrimaryForSwordEnchantsAsInt = buf.readInt();
Boolean isPrimaryForSwordEnchants = null;
Double piercingLevel = buf.readDouble();
int canSweepAsInt = buf.readInt();
Boolean canSweep = null;
if (damageOffset == -10)
damageOffset = null;
if (speed == -10)
speed = null;
if (reach == -10)
reach = null;
if (chargedReach == -10)
chargedReach = null;
if (hasSwordEnchantsAsInt != -10)
hasSwordEnchants = hasSwordEnchantsAsInt == 1;
if (isPrimaryForSwordEnchantsAsInt != -10)
isPrimaryForSwordEnchants = isPrimaryForSwordEnchantsAsInt == 1;
if (piercingLevel == -10)
piercingLevel = null;
if (canSweepAsInt != -10)
canSweep = canSweepAsInt == 1;
return new ConfigurableWeaponData(damageOffset, speed, reach, chargedReach, tierable, bType, hasSwordEnchants, isPrimaryForSwordEnchants, piercingLevel, canSweep);
});
public final Double damageOffset;
public final Double speed;
public final Double reach;
Expand Down
Loading

0 comments on commit 142cd36

Please sign in to comment.