Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MerchantPug committed Dec 4, 2023
1 parent 06daa03 commit 2b89689
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.github.edwinmindcraft.apoli.api.configuration.FieldConfiguration;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredPower;
import io.github.edwinmindcraft.apoli.common.ApoliCommon;
import io.github.edwinmindcraft.apoli.common.network.S2CPlayerDismount;
import io.github.edwinmindcraft.apoli.common.network.S2CSyncAttacker;
import io.github.edwinmindcraft.apoli.common.power.*;
import io.github.edwinmindcraft.apoli.common.power.configuration.ActionOnItemUseConfiguration;
Expand All @@ -21,6 +22,7 @@
import io.github.edwinmindcraft.apoli.common.util.LivingDamageCache;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.CombatRules;
Expand Down Expand Up @@ -233,6 +235,14 @@ private void allowFreezingPower(CallbackInfoReturnable<Boolean> cir) {
if (IPowerContainer.hasPower(this, ApoliPowers.FREEZE.get())) cir.setReturnValue(true);
}

// Moved from PlayerEntityMixin.
@Inject(method = "stopRiding", at = @At("HEAD"))
private void sendPlayerDismountPacket(CallbackInfo ci) {
if (!this.level().isClientSide() && this.getVehicle() instanceof ServerPlayer player) {
ApoliCommon.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), new S2CPlayerDismount(this.getId()));
}
}

// SetEntityGroupPower
@Inject(at = @At("HEAD"), method = "getMobType", cancellable = true)
public void getGroup(CallbackInfoReturnable<MobType> info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
import io.github.apace100.apoli.access.ModifiableFoodEntity;
import io.github.edwinmindcraft.apoli.api.component.IPowerContainer;
import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredPower;
import io.github.edwinmindcraft.apoli.common.ApoliCommon;
import io.github.edwinmindcraft.apoli.common.network.S2CPlayerDismount;
import io.github.edwinmindcraft.apoli.common.power.ModifyFoodPower;
import io.github.edwinmindcraft.apoli.common.power.configuration.ModifyFoodConfiguration;
import io.github.edwinmindcraft.apoli.common.registry.ApoliPowers;
import io.github.edwinmindcraft.apoli.common.util.CoreUtils;
import io.github.edwinmindcraft.apoli.common.util.LivingDamageCache;
import net.minecraft.commands.CommandSource;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Nameable;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.*;
Expand All @@ -22,7 +19,6 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.network.PacketDistributor;
import org.apache.commons.lang3.mutable.MutableObject;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -87,13 +83,6 @@ private ItemStack modifyEatenItemStack(ItemStack original) {
return stack.getValue();
}

@Inject(method = "removeVehicle", at = @At("HEAD"))
private void sendPlayerDismountPacket(CallbackInfo ci) {
if (!this.level().isClientSide() && this.getVehicle() instanceof ServerPlayer player) {
ApoliCommon.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), new S2CPlayerDismount(this.getId()));
}
}

// ModifyExhaustion
@ModifyVariable(at = @At("HEAD"), method = "causeFoodExhaustion", ordinal = 0, name = "exhaustion", argsOnly = true)
private float modifyExhaustion(float exhaustionIn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

import io.github.edwinmindcraft.apoli.api.configuration.NoConfiguration;
import io.github.edwinmindcraft.apoli.api.power.factory.BiEntityAction;
import io.github.edwinmindcraft.apoli.common.ApoliCommon;
import io.github.edwinmindcraft.apoli.common.network.S2CPlayerMount;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.TamableAnimal;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.network.PacketDistributor;

import java.util.function.BiConsumer;

public class SimpleBiEntityAction extends BiEntityAction<NoConfiguration> {

public static void mount(Entity actor, Entity target) {
actor.startRiding(target, true);
// The below is unnecessary as the client will execute the above before the server.
/*
if (!actor.level().isClientSide() && target instanceof ServerPlayer player) {
ApoliCommon.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), new S2CPlayerMount(actor.getId(), target.getId()));
}
*/
}

public static void setInLove(Entity actor, Entity target) {
Expand Down
32 changes: 32 additions & 0 deletions src/test/resources/data/apoliforge/powers/dismount.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"type": "apoli:active_self",
"cooldown": 1,
"key": {
"key": "key.use",
"continuous": false
},
"entity_action": {
"type": "apoli:passenger_action",
"bientity_action": {
"type": "apoli:and",
"actions": [
{
"type": "apoli:actor_action",
"action": {
"type": "apoli:dismount"
}
},
{
"type": "apoli:target_action",
"action": {
"type": "apoli:swing_hand",
"hand": "MAIN_HAND"
}
}
]
}
},
"condition": {
"type": "apoli:sneaking"
}
}
19 changes: 19 additions & 0 deletions src/test/resources/data/apoliforge/powers/pick_up.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "apoli:action_on_entity_use",
"bientity_action": {
"type": "apoli:invert",
"action": {
"type": "apoli:mount"
}
},
"item_condition": {
"type": "apoli:empty"
},
"hands": [
"main_hand"
],
"condition": {
"type": "apoli:sneaking",
"inverted": true
}
}

0 comments on commit 2b89689

Please sign in to comment.