-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.ninni.spawn.mixin; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.player.Abilities; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import org.spongepowered.asm.mixin.Final; | ||
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(Player.class) | ||
public abstract class PlayerMixin extends LivingEntity { | ||
@Shadow private long timeEntitySatOnShoulder; | ||
@Shadow protected abstract void respawnEntityOnShoulder(CompoundTag compoundTag); | ||
@Shadow public abstract CompoundTag getShoulderEntityLeft(); | ||
@Shadow public abstract CompoundTag getShoulderEntityRight(); | ||
@Shadow protected abstract void setShoulderEntityLeft(CompoundTag compoundTag); | ||
@Shadow protected abstract void setShoulderEntityRight(CompoundTag compoundTag); | ||
|
||
@Shadow @Final private Abilities abilities; | ||
|
||
protected PlayerMixin(EntityType<? extends LivingEntity> entityType, Level level) { | ||
super(entityType, level); | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "removeEntitiesOnShoulder", cancellable = true) | ||
private void S$removeEntitiesOnShoulder(CallbackInfo ci) { | ||
ci.cancel(); | ||
} | ||
|
||
@Inject(at = @At("TAIL"), method = "aiStep") | ||
private void S$aiStep(CallbackInfo ci) { | ||
if (!this.level().isClientSide && this.isUnderWater() || this.abilities.flying || this.isSleeping() || this.isInPowderSnow) { | ||
this.newRemoveEntitiesOnShoulder(); | ||
} | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "jumpFromGround") | ||
private void S$jumpFromGround(CallbackInfo ci) { | ||
if (this.isShiftKeyDown()) this.newRemoveEntitiesOnShoulder(); | ||
} | ||
|
||
|
||
protected void newRemoveEntitiesOnShoulder() { | ||
if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) { | ||
this.respawnEntityOnShoulder(this.getShoulderEntityLeft()); | ||
this.setShoulderEntityLeft(new CompoundTag()); | ||
this.respawnEntityOnShoulder(this.getShoulderEntityRight()); | ||
this.setShoulderEntityRight(new CompoundTag()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/ninni/spawn/mixin/accessor/PlayerAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.ninni.spawn.mixin.accessor; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.entity.player.Player; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(Player.class) | ||
public interface PlayerAccessor { | ||
@Accessor | ||
long getTimeEntitySatOnShoulder(); | ||
|
||
@Invoker | ||
void callRespawnEntityOnShoulder(CompoundTag compoundTag); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters