Compare commits

...

2 commits

5 changed files with 128 additions and 2 deletions

View file

@ -123,7 +123,7 @@ public class OfflinePlayerEntity extends LivingEntity {
@Override
public EntityDimensions getDimensions(Pose pose) {
return EntityDimensions.scalable(0.6F, 1.8F);
return EntityDimensions.scalable(0.6F, 0.6F);
}
public void setPlayerUUID(UUID uuid) {
@ -146,6 +146,11 @@ public class OfflinePlayerEntity extends LivingEntity {
return this.entityData.get(DATA_PLAYER_MODE_CUSTOMISATION);
}
@Override
public double getMyRidingOffset() {
return super.getMyRidingOffset() + 1;
}
public void setModelCustomisation(byte customisation) {
this.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, customisation);
}
@ -191,6 +196,18 @@ public class OfflinePlayerEntity extends LivingEntity {
}
}
@Override
public boolean startRiding(Entity p_19966_, boolean p_19967_) {
this.setPose(Pose.SLEEPING);
return super.startRiding(p_19966_, p_19967_);
}
@Override
public void dismountTo(double p_146825_, double p_146826_, double p_146827_) {
super.dismountTo(p_146825_, p_146826_, p_146827_);
this.setPose(Pose.SLEEPING);
}
@Override
public void tick() {
super.tick();

View file

@ -0,0 +1,58 @@
package xyz.illuc.neuralgiacore.events;
import net.adinvas.prototype_pain.PlayerHealthProvider;
import net.dries007.tfc.common.capabilities.food.TFCFoodData;
import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import xyz.illuc.neuralgiacore.NeuralgiaCoreMod;
import xyz.illuc.neuralgiacore.entities.OfflinePlayerEntity;
import xyz.illuc.neuralgiacore.interfaces.IPlayerHealthDataAccessor;
import static net.minecraft.world.entity.EntityType.PLAYER;
@Mod.EventBusSubscriber
public class PickUpUnconsciousPlayerEvent {
@SubscribeEvent
public static void onInteract(PlayerInteractEvent.EntityInteractSpecific event) {
Entity target = event.getTarget();
Entity source = event.getEntity();
if (target.getType() == PLAYER && source.isShiftKeyDown()) {
if (source instanceof ServerPlayer serverPlayer) {
target.getCapability(PlayerHealthProvider.PLAYER_HEALTH_DATA).ifPresent(h -> {
if (h.getContiousness() < 10f) {
target.startRiding(source, false);
}
});
}
} else if (target.getType() == NeuralgiaCoreMod.GHOST.get() && source.isShiftKeyDown()) {
target.startRiding(source);
}
}
@SubscribeEvent
public static void onLeftClick(PlayerInteractEvent.RightClickBlock event) {
if (!(event.getEntity() instanceof ServerPlayer)) return;
Entity source = event.getEntity();
Entity passenger = source.getFirstPassenger();
BlockPos pos = event.getPos();
if (passenger instanceof Player || passenger instanceof OfflinePlayerEntity) {
passenger.stopRiding();
passenger.dismountTo(pos.getX(), pos.getY()+1, pos.getZ());
}
}
}

View file

@ -0,0 +1,29 @@
package xyz.illuc.neuralgiacore.mixin.vanilla;
import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Entity.class)
public class MixinFixRiding {
//https://github.com/FaeWulf/piggyback/blob/1.20.1/common/src/main/java/xyz/faewulf/piggyback/mixin/EntityMixin.java
@Shadow
private Level level;
// Prevent client desync
@Inject(method = "removePassenger", at = @At("TAIL"))
private void onRemovePassenger(Entity passenger, CallbackInfo callbackInfo)
{
Entity entity = (Entity) (Object) this;
if(!this.level.isClientSide && entity instanceof ServerPlayer serverPlayer)
serverPlayer.connection.send(new ClientboundSetPassengersPacket(entity));
}
}

View file

@ -0,0 +1,20 @@
package xyz.illuc.neuralgiacore.mixin.vanilla;
import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ServerPlayer.class)
public class MixinFixServerRiding {
@Inject(method = "startRiding", at = @At("RETURN"))
private void startRidingInjectSyncPacket(Entity entity, boolean force, CallbackInfoReturnable<Boolean> cir) {
if (entity instanceof ServerPlayer playerEntity && cir.getReturnValue()) {
playerEntity.connection.send(new ClientboundSetPassengersPacket(playerEntity));
}
}
}

View file

@ -19,7 +19,9 @@
"Tfc.MixinFoodData",
"Tfc.MixinHealthBar",
"Tfc.MixinOptimizeClimateUpdate",
"TfcAmbiental.MixinDisableTemperatureDamage"
"TfcAmbiental.MixinDisableTemperatureDamage",
"vanilla.MixinFixRiding",
"vanilla.MixinFixServerRiding"
],
"client": [
"TfcAmbiental.MixinSkipVignette",