Skip to content

Commit

Permalink
properly networked terrasteel
Browse files Browse the repository at this point in the history
  • Loading branch information
Partonetrain committed Aug 24, 2024
1 parent 808c3ac commit 308ccbc
Show file tree
Hide file tree
Showing 38 changed files with 314 additions and 211 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ This mod does the following:
- Adds additional post-Gaia weapon, the Gaia Greatsword, which can use all of your Patreon colors
- Buffs player-spawned pixies by making them always have the +2 damage bonus that would normally only be applied when the player is holding the Elementium Sword
- Adds Gaia Gifts: "secret" weapon(s) obtained by defeating Gaia II under specific conditions
- 2.2.0 Adds "Angry Angry Bozu", an "evil upgrade" to Botania's Teru Teru Bozu that can summon thunderstorms. Useful for Channeling Tridents and Thundercaller.
- Adds "Angry Angry Bozu", an "evil upgrade" to Botania's Teru Teru Bozu that can summon thunderstorms. Useful for Channeling Tridents and Thundercaller

If [Better Combat](https://www.curseforge.com/minecraft/mc-mods/better-combat-by-daedelus) is installed, it also does the following:

- Adds offhand pixie spawn chance attribute to Elementium weapons (including Elementium Sword)
- Adds pixie spawn chance attributes to the Elementium Axe
- Makes Terrasteel weapons (including Terra Blade) shoot a beam at the start of a BetterCombat swing; also works with offhand swings
- Makes Terrasteel weapons (including Terra Blade) shoot a beam during a BetterCombat swing; also works with offhand swings
- Makes Starcaller work similar to Terrasteel weapons
- Reduces Thundercaller attack range to 1.5 (from BetterCombat's default 2.5), electricity range is unaffected

If [Fabric Shield Lib](https://www.curseforge.com/minecraft/mc-mods/fabric-shield-lib) is installed, it also does the following:
Expand All @@ -28,20 +29,22 @@ If [Fabric Shield Lib](https://www.curseforge.com/minecraft/mc-mods/fabric-shiel
- Adds shield Gaia Gift

If [Ranged Weapon API](https://www.curseforge.com/minecraft/mc-mods/ranged-weapon-api) is installed, it also does the following:
- Adds Pull Time and Projectile Damage attributes to Botania's bows
- Adds Pull Time and Ranged Damage attributes to Botania's bows
- Adds Livingwood Crossbow
- Adds Crystal Crossbow
- Adds Ranged Damage attribute to Mana Blaster with Damage lens (which deals magic damage)
- Adds bow Gaia Gift

**NOTE**: To ensure that the Lexica and subtitles from Botania are accurate, this mod includes an enabled-by-default resource pack that overrides some of Botania's lang file.
This mod only supports en_us.json currently (translations wanted)
This mod only supports en_us.json currently (translations wanted).

Credits / Thanks:
- Unilock for [cleaning up the code and fixing compat with Sinytra Connector](https://github.com/Partonetrain/botaniacombat/pull/1)
- Daedulus_dev for making Ranged Weapon API
- arkosammy12 for helping with the Elementium Axe mixin
- Adarsh and everyone else on the Violet Moon forums giving me feedback and ideas
- June (of BasicWeapons) for letting me use that mod's method for dynamic item renders in the older versions
- brokenk3yboard for helping me understand Fabric networking API

If you like this mod, [consider supporting me on ko-fi](https://ko-fi.com/partonetrain) ^_^

Expand All @@ -59,7 +62,4 @@ It should, thanks to Unilock's PR. Support for it is lower priority than support
A couple of reasons, but mostly these are mods I already use myself, and I don't like doing mixin on vanilla when there's just a library I could use that does it

#### *Is there a config?*
Yes, and a quite extensive one at that. Values pertaining to BotaniaCombat weapons can be changed, and certain Botania items can be nerfed (or buffed) as well.

### *Why doesn't my Starcaller work like it should?*
WIP
Yes, and a quite extensive one at that. It can be configured via ModMenu. Values pertaining to BotaniaCombat weapons can be changed, and certain Botania items can be nerfed (or buffed) as well.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies {
modImplementation "maven.modrinth:ranged-weapon-api:${project.ranged_weapon_api_version}"

modImplementation "maven.modrinth:archers:${project.archers_version}"
include(implementation("com.github.ZsoltMolnarrr:TinyConfig:${project.tiny_config_version}"))
modImplementation("com.github.ZsoltMolnarrr:TinyConfig:${project.tiny_config_version}")

modApi("me.shedaniel.cloth:cloth-config-fabric:${project.clothconfig_version}") {
exclude(group: "net.fabricmc.fabric-api")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10
loader_version=0.15.7

# Mod Properties
mod_version=1.20.1-2.3.0
mod_version=1.20.1-3.0.0b
maven_group=info.partonetrain
archives_base_name=botaniacombat

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import info.partonetrain.botaniacombat.item.GaiaGreatswordItem;
import info.partonetrain.botaniacombat.item.TerrasteelWeaponItem;
import info.partonetrain.botaniacombat.network.StarcallerAttackHitHandler;
import info.partonetrain.botaniacombat.network.TerrasteelWeaponAttackHitHandler;
import info.partonetrain.botaniacombat.registry.BotaniaCombatShieldItems;
import info.partonetrain.botaniacombat.render.entity.BotaniaCombatEntityRenderers;
import net.bettercombat.api.AttackHand;
Expand Down Expand Up @@ -43,8 +44,7 @@ public void onInitializeClient() {
this.registerOptionalResourcePack(); //for botaniacombatlang respack

if (BotaniaCombat.BETTER_COMBAT_INSTALLED) {
BotaniaCombat.LOGGER.info("BetterCombat found, running client code");
BetterCombatClientEvents.ATTACK_START.register(this::checkBetterCombatSwing);
BetterCombatClientEvents.ATTACK_HIT.register(new TerrasteelWeaponAttackHitHandler());
BetterCombatClientEvents.ATTACK_HIT.register(new StarcallerAttackHitHandler());
}

Expand All @@ -70,18 +70,6 @@ public void onInitializeClient() {
}
}

public void checkBetterCombatSwing(LocalPlayer clientPlayerEntity, AttackHand attackHand) {
if (attackHand.itemStack().getItem() instanceof TerrasteelWeaponItem) {
TerrasteelWeaponItem.leftClick(attackHand.itemStack());
}
else if (attackHand.itemStack().getItem() instanceof GaiaGreatswordItem) {
GaiaGreatswordItem.leftClick(attackHand.itemStack());
}
else if (attackHand.itemStack().getItem() instanceof TerraBladeItem) {
TerraBladeItem.leftClick(attackHand.itemStack()); //the botania weapon
}
}

public void registerOptionalResourcePack() {
ResourceLocation folderName = new ResourceLocation(BotaniaCombat.MOD_ID, "botaniacombatlang");
Component displayName = Component.literal("BotaniaCombat Lang Fixes");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.partonetrain.botaniacombat.mixin.client;
package info.partonetrain.botaniacombat.mixin.client.vanillacombat;

import info.partonetrain.botaniacombat.item.GaiaGreatswordItem;
import info.partonetrain.botaniacombat.item.TerrasteelWeaponItem;
Expand All @@ -17,7 +17,6 @@ public abstract class MinecraftMixin {
@Nullable
public LocalPlayer player;

//this is not actually called when the player swings and BetterCombat is installed, but it's here in case you want to use the mod without BetterCombat or for misc compat
@Inject(method = "startAttack", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;resetAttackStrengthTicker()V"))
private void leftClickEmpty(CallbackInfoReturnable<Boolean> ci) {
TerrasteelWeaponItem.leftClick(player.getMainHandItem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

public class StarcallerAttackHitHandler implements BetterCombatClientEvents.PlayerAttackHit {
@Override
public void onPlayerAttackStart(LocalPlayer player, AttackHand attackHand, List<Entity> list, @Nullable Entity entity) {
ItemStack stack = attackHand.isOffHand() ? player.getOffhandItem() : player.getMainHandItem();
public void onPlayerAttackStart(LocalPlayer localPlayer, AttackHand attackHand, List<Entity> list, @Nullable Entity entity) {
ItemStack stack = attackHand.isOffHand() ? localPlayer.getOffhandItem() : localPlayer.getMainHandItem();
if (stack.isEmpty()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package info.partonetrain.botaniacombat.network;

import info.partonetrain.botaniacombat.ITerrasteelWeapon;
import info.partonetrain.botaniacombat.item.GaiaGreatswordItem;
import info.partonetrain.botaniacombat.item.TerrasteelWeaponItem;
import net.bettercombat.api.AttackHand;
import net.bettercombat.api.client.BetterCombatClientEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class TerrasteelWeaponAttackHitHandler implements BetterCombatClientEvents.PlayerAttackHit{
@Override
public void onPlayerAttackStart(LocalPlayer localPlayer, AttackHand attackHand, List<Entity> list, @Nullable Entity entity) {
ItemStack stack = attackHand.isOffHand() ? localPlayer.getOffhandItem() : localPlayer.getMainHandItem();
if (stack.isEmpty()) {
return;
}
Item item = stack.getItem();
if (item instanceof ITerrasteelWeapon) {
ClientPlayNetworking.send(new TerrasteelWeaponHitPacket(attackHand.isOffHand()));
}
}
}
2 changes: 1 addition & 1 deletion src/client/resources/botaniacombat.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"compatibilityLevel": "JAVA_17",
"client": [
"AbstractClientPlayerMixin",
"MinecraftMixin"
"vanillacombat.MinecraftMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/info/partonetrain/botaniacombat/BotaniaCombat.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import info.partonetrain.botaniacombat.item.TerrasteelWeaponItem;
import info.partonetrain.botaniacombat.item.shield.ElementiumBannerShieldItem;
import info.partonetrain.botaniacombat.network.StarcallerHitPacket;
import info.partonetrain.botaniacombat.network.TerrasteelWeaponHitPacket;
import info.partonetrain.botaniacombat.registry.*;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
Expand All @@ -27,17 +28,21 @@ public class BotaniaCombat implements ModInitializer {
public static final int MANA_PER_DAMAGE = 60;
public static final int MANA_PER_DAMAGE_TERRA = 100;

public static final ResourceLocation TERRASTEEL_WEAPON_PACKET_ID = new ResourceLocation(MOD_ID, "terrasteel_weapon");
public static final ResourceLocation STARCALLER_PACKET_ID = new ResourceLocation(MOD_ID, "starcaller");
public static final PacketType<StarcallerHitPacket> STARCALLER_HIT_PACKET_PACKET_TYPE = PacketType.create(STARCALLER_PACKET_ID, StarcallerHitPacket::new);
public static final PacketType<TerrasteelWeaponHitPacket> TERRASTEEL_WEAPON_PACKET_TYPE = PacketType.create(TERRASTEEL_WEAPON_PACKET_ID, TerrasteelWeaponHitPacket::new);

@Override
public void onInitialize() {
AutoConfig.register(BotaniaCombatConfig.class, JanksonConfigSerializer::new);
BotaniaCombatItems.init();
BotaniaNerfConfiguredValues.init(); //prevents loading issues; ensures autoconfig is registered before values are used

AttackEntityCallback.EVENT.register(TerrasteelWeaponItem::attackEntity); //fabric events for if BetterCombat is not installed
AttackEntityCallback.EVENT.register(GaiaGreatswordItem::attackEntity);
if(!BETTER_COMBAT_INSTALLED){ //fabric events for vanilla combat
AttackEntityCallback.EVENT.register(TerrasteelWeaponItem::attackEntity);
AttackEntityCallback.EVENT.register(GaiaGreatswordItem::attackEntity);
}

if (FABRIC_SHIELD_LIB_INSTALLED) {
BotaniaCombatShieldItems.init();
Expand All @@ -46,13 +51,16 @@ public void onInitialize() {
if (RANGED_WEAPON_API_INSTALLED) {
BotaniaCombatRangedItems.init();
}
if (BETTER_COMBAT_INSTALLED){
BotaniaCombatNetworking.initBetterCombat();
}

BotaniaCombatBlocks.init();
BotaniaCombatBlockEntities.init();

PsiContributorColors.get();

BotaniaCombatNetworking.init();

LOGGER.info("BotaniaCombat initialized");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BotaniaCombatConfig implements ConfigData {
@Comment("Modifier of dagger damage amount relative to tier damage")
public int daggerDamageModifier = -3;
@Comment("Modifier of dagger speed relative to default speed (4)")
public float daggerSpeed = -2.0f;
public float daggerSpeed = -1.6f;
@Comment("Whether or not the Slaughtersaw can ONLY hit entities in the #botaniacombat:meaty entity tag")
public boolean slaughtersawRestricted = false;
@Comment("Modifier of Slaughtersaw damage amount relative to Manasteel tier damage")
Expand All @@ -21,15 +21,15 @@ public class BotaniaCombatConfig implements ConfigData {
@Comment("Modifier of spear damage amount relative to tier damage")
public int spearDamageModifier = -1;
@Comment("Modifier of spear speed relative to default speed (4)")
public float spearSpeed = -2.8f;
public float spearSpeed = -2.6f;
@Comment("Modifier of Soulstaff damage amount relative to Manasteel tier damage")
public int soulstaffDamageModifier = -1;
@Comment("Modifier of Soulstaff speed relative to default speed (4)")
public float soulstaffSpeed = -2.3f;
@Comment("Modifier of Gaia Greatsword damage amount relative to Terrasteel tier damage")
public int greatswordDamageModifier = 3;
public int greatswordDamageModifier = 4;
@Comment("Modifier of Gaia Greatsword speed relative to default speed (4)")
public float greatswordSpeed = -3.4f;
public float greatswordSpeed = -3f;
@Comment("Modifier of Mjolnir damage relative to Terrasteel tier damage")
public int mjolinirDamageModifier = 4;
@Comment("Modifier of Mjolnir speed relative to default speed (4)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if(Arrays.asList(packageTree).contains("nerf")){
return true;
}
if (Arrays.asList(packageTree).contains("vanillacombat")) {
return !BotaniaCombat.BETTER_COMBAT_INSTALLED;
}
if (Arrays.asList(packageTree).contains("bettercombat")) {
return BotaniaCombat.BETTER_COMBAT_INSTALLED;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package info.partonetrain.botaniacombat;

import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

public interface IStarcaller {
void botaniacombat_summonStarBetterCombat(ItemStack stack, Level level, Player player);
void botaniacombat$summonStarBetterCombat(ItemStack stack, Level level, Player player, InteractionHand interactionHand);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package info.partonetrain.botaniacombat;

import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

public interface ITerrasteelWeapon {
void botaniacombat$summonBeamBetterCombat(ItemStack stack, Level level, Player player, InteractionHand interactionHand);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import info.partonetrain.botaniacombat.BotaniaCombat;
import info.partonetrain.botaniacombat.ColorContainer;
import info.partonetrain.botaniacombat.ITerrasteelWeapon;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand All @@ -18,54 +19,45 @@
import vazkii.botania.network.serverbound.LeftClickPacket;
import vazkii.botania.xplat.ClientXplatAbstractions;

public class GaiaGreatswordItem extends BotaniaCombatWeaponItem {
public class GaiaGreatswordItem extends BotaniaCombatWeaponItem implements ITerrasteelWeapon {
private static final int[] BURST_ANGLES = new int[]{-30, -20, -10, 0, 10, 20, 30};

public GaiaGreatswordItem(Tier mat, int attackDamageFromWeaponType, float attackSpeed, Properties props) {
super(mat, attackDamageFromWeaponType, attackSpeed, props);
}

public static void leftClick(ItemStack stack) {
public static void leftClick(ItemStack stack) { //vanilla combat ONLY
if (!stack.isEmpty() && stack.getItem() instanceof GaiaGreatswordItem) {
ClientXplatAbstractions.INSTANCE.sendToServer(LeftClickPacket.INSTANCE);
}
}

public static InteractionResult attackEntity(Player player, Level world, InteractionHand hand, Entity target, @Nullable EntityHitResult hit) {
if (!player.level().isClientSide() && !player.isSpectator()) {
if (!player.level().isClientSide() && !player.isSpectator()) { //vanilla combat ONLY
trySpawnBursts(player);
}

return InteractionResult.PASS;
}

public static void trySpawnBursts(Player player) {
public static void trySpawnBursts(Player player) { //vanilla combat ONLY
trySpawnBursts(player, player.getAttackStrengthScale(0F));
}

public static void trySpawnBursts(Player player, float attackStrength) {
public static void trySpawnBursts(Player player, float attackStrength) { //vanilla combat ONLY
if (!player.isSpectator()) {
//mainhand
if (!player.getMainHandItem().isEmpty()
&& player.getMainHandItem().getItem() instanceof GaiaGreatswordItem
&& attackStrength == 1) {
spawnBursts(player);
spawnSevenBursts(player);
player.getMainHandItem().hurtAndBreak(1, player, p -> p.broadcastBreakEvent(InteractionHand.MAIN_HAND));
player.level().playSound(null, player.getX(), player.getY(), player.getZ(), BotaniaSounds.terraBlade, SoundSource.PLAYERS, 1F, 1F);
}

//offhand
if (!player.getOffhandItem().isEmpty()
&& player.getOffhandItem().getItem() instanceof GaiaGreatswordItem
&& attackStrength == 1) {
spawnBursts(player);
player.getOffhandItem().hurtAndBreak(1, player, p -> p.broadcastBreakEvent(InteractionHand.OFF_HAND));
player.level().playSound(null, player.getX(), player.getY(), player.getZ(), BotaniaSounds.terraBlade, SoundSource.PLAYERS, 1F, 1F);
}
}
}

public static void spawnBursts(Player player) {
public static void spawnSevenBursts(Player player) {
final ItemStack DUMMY_TERRABLADE = new ItemStack(BotaniaItems.terraSword);
ColorContainer cc = new ColorContainer(player.getName().getString());

Expand Down Expand Up @@ -93,4 +85,16 @@ public static void spawnBursts(Player player) {
public int getManaPerDamage() {
return BotaniaCombat.MANA_PER_DAMAGE_TERRA * BURST_ANGLES.length;
}

@Override
public void botaniacombat$summonBeamBetterCombat(ItemStack stack, Level level, Player player, InteractionHand interactionHand) {
float attackStrength = player.getAttackStrengthScale(0F);
if (!player.isSpectator()
&& stack.getItem() instanceof ITerrasteelWeapon
&& attackStrength == 1) {
spawnSevenBursts(player);
stack.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(interactionHand));
player.level().playSound(null, player.getX(), player.getY(), player.getZ(), BotaniaSounds.terraBlade, SoundSource.PLAYERS, 1F, 1F);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public boolean hurtEnemy(ItemStack stack, LivingEntity entity, @NotNull LivingEn

for (int i = 0; i < hops; i++) {
List<Entity> entities = entity.level().getEntities(prevTarget, new AABB(prevTarget.getX() - range, prevTarget.getY() - range, prevTarget.getZ() - range, prevTarget.getX() + range, prevTarget.getY() + range, prevTarget.getZ() + range), selector);
if (entities.isEmpty()) {
if (entities.isEmpty() || dmg < 1) {
break;
}

Expand Down
Loading

0 comments on commit 308ccbc

Please sign in to comment.