Items dropped by batponies whilst hanging from the ceiling no longer copy their gravity

This commit is contained in:
Sollace 2022-12-23 20:55:12 +01:00
parent 97fa83e42a
commit 077f0b8987
4 changed files with 33 additions and 23 deletions

View file

@ -26,9 +26,6 @@ public class PlayerAttributes implements Tickable {
private static final EntityAttributeModifier PEGASUS_REACH =
new EntityAttributeModifier(UUID.fromString("707b50a8-03e8-40f4-8553-ecf67025fd6d"), "Pegasus Reach", 1.5, Operation.ADDITION);
public static final EntityAttributeModifier BAT_HANGING =
new EntityAttributeModifier(UUID.fromString("a54f2595-521e-480b-b9d5-6e750577a564"), "Bat Pony Hanging", -2, Operation.MULTIPLY_TOTAL);
public static final UUID HEALTH_SWAPPING_MODIFIER_ID = UUID.fromString("7b93803e-4b25-11ed-951e-00155d43e0a2");
public static EntityAttributeModifier healthChange(float addition) {

View file

@ -79,6 +79,19 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
return dimensions;
}
public final float getPersistantGravityModifier() {
return super.getGravityModifier();
}
@Override
public float getGravityModifier() {
float modifier = getPersistantGravityModifier();
if (pony.isHanging()) {
modifier *= -0.05F;
}
return modifier;
}
@Override
public boolean isFlying() {
return isFlyingSurvival && !entity.isFallFlying() && !entity.hasVehicle();

View file

@ -40,7 +40,6 @@ import com.mojang.authlib.GameProfile;
import net.minecraft.block.BlockState;
import net.minecraft.entity.*;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.EntityDamageSource;
import net.minecraft.entity.data.DataTracker;
@ -65,6 +64,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
static final TrackedData<Float> ENERGY = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
static final TrackedData<Float> EXHAUSTION = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
static final TrackedData<Float> EXERTION = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
static final TrackedData<Optional<BlockPos>> HANGING_POSITION = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.OPTIONAL_BLOCK_POS);
static final TrackedData<Float> MANA = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
static final TrackedData<Float> XP = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
static final TrackedData<Integer> LEVEL = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER);
@ -92,7 +92,6 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
private boolean dirty;
private boolean speciesPersisted;
private Optional<BlockPos> hangingPosition = Optional.empty();
private int ticksHanging;
private float magicExhaustion = 0;
@ -118,6 +117,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
this.tickers = Lists.newArrayList(gravity, mana, attributes);
player.getDataTracker().startTracking(RACE, Race.DEFAULT_ID);
player.getDataTracker().startTracking(HANGING_POSITION, Optional.empty());
}
public static void registerAttributes(DefaultAttributeContainer.Builder builder) {
@ -329,31 +329,27 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
return false;
}
public Optional<BlockPos> getHangingPosition() {
return entity.getDataTracker().get(HANGING_POSITION);
}
public boolean isHanging() {
return entity.getAttributeInstance(UEntityAttributes.ENTITY_GRAVTY_MODIFIER).hasModifier(PlayerAttributes.BAT_HANGING);
return getHangingPosition().isPresent();
}
public void stopHanging() {
entity.getAttributeInstance(UEntityAttributes.ENTITY_GRAVTY_MODIFIER).removeModifier(PlayerAttributes.BAT_HANGING);
entity.getDataTracker().set(HANGING_POSITION, Optional.empty());
entity.calculateDimensions();
ticksHanging = 0;
hangingPosition = Optional.empty();
}
public void startHanging(BlockPos pos) {
hangingPosition = Optional.of(pos);
EntityAttributeInstance attr = entity.getAttributeInstance(UEntityAttributes.ENTITY_GRAVTY_MODIFIER);
if (!attr.hasModifier(PlayerAttributes.BAT_HANGING)) {
attr.addPersistentModifier(PlayerAttributes.BAT_HANGING);
}
entity.getDataTracker().set(HANGING_POSITION, Optional.of(pos));
entity.teleport(pos.getX() + 0.5, pos.getY() - 1, pos.getZ() + 0.5);
entity.setVelocity(Vec3d.ZERO);
entity.setSneaking(false);
entity.stopFallFlying();
getPhysics().cancelFlight(true);
setDirty();
}
public boolean canHangAt(BlockPos pos) {
@ -379,7 +375,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
if (isHanging()) {
((LivingEntityDuck)entity).setLeaningPitch(0);
if (!isClient() && (getObservedSpecies() != Race.BAT || (ticksHanging++ > 2 && hangingPosition.filter(getOrigin().down()::equals).filter(this::canHangAt).isEmpty()))) {
if (!isClient() && (getObservedSpecies() != Race.BAT || (ticksHanging++ > 2 && getHangingPosition().filter(getOrigin().down()::equals).filter(this::canHangAt).isEmpty()))) {
stopHanging();
}
} else {
@ -452,6 +448,13 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
return Optional.empty();
}
public void onDropItem(ItemEntity itemDropped) {
Equine.of(itemDropped).ifPresent(eq -> {
eq.setSpecies(getSpecies());
eq.getPhysics().setBaseGravityModifier(gravity.getPersistantGravityModifier());
});
}
public Optional<Float> onImpact(float distance, float damageMultiplier, DamageSource cause) {
float originalDistance = distance;
@ -556,7 +559,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
compound.putString("playerSpecies", Race.REGISTRY.getId(getActualSpecies()).toString());
compound.putFloat("magicExhaustion", magicExhaustion);
compound.putInt("ticksHanging", ticksHanging);
BLOCK_POS.writeOptional("hangingPosition", compound, hangingPosition);
BLOCK_POS.writeOptional("hangingPosition", compound, getHangingPosition());
compound.putInt("ticksInSun", ticksInSun);
compound.putBoolean("hasShades", hasShades);
compound.put("powers", powers.toNBT());
@ -589,7 +592,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
magicExhaustion = compound.getFloat("magicExhaustion");
ticksHanging = compound.getInt("ticksHanging");
hangingPosition = NbtSerialisable.BLOCK_POS.readOptional("hangingPosition", compound);
entity.getDataTracker().set(HANGING_POSITION, NbtSerialisable.BLOCK_POS.readOptional("hangingPosition", compound));
ticksInSun = compound.getInt("ticksInSun");
hasShades = compound.getBoolean("hasShades");

View file

@ -77,10 +77,7 @@ abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<P
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;",
at = @At("RETURN"))
private void onDropItem(ItemStack itemStack_1, boolean scatter, boolean retainOwnership, CallbackInfoReturnable<ItemEntity> info) {
Equine.of(info.getReturnValue()).ifPresent(eq -> {
eq.setSpecies(get().getSpecies());
eq.getPhysics().setBaseGravityModifier(get().getPhysics().getGravityModifier());
});
get().onDropItem(info.getReturnValue());
}
@Inject(method = "getActiveEyeHeight(Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntityDimensions;)F",