The bag of holding will now affect the player's gravity (weight)

This commit is contained in:
Sollace 2020-05-10 19:52:43 +02:00
parent 5b7f298147
commit 1260f0486c
7 changed files with 41 additions and 23 deletions

View file

@ -54,7 +54,7 @@ class GravityCommand {
Pony iplayer = Pony.of(player);
iplayer.getPhysics().setGravityModifier(gravity);
iplayer.getPhysics().setBaseGravityModifier(gravity);
iplayer.setDirty();
if (isSelf) {

View file

@ -30,33 +30,34 @@ public class EntityPhysics<T extends Ponylike<?> & Owned<? extends Entity>> impl
@Override
public double calcGravity(double worldConstant) {
return worldConstant * gravity;
return worldConstant * getGravityModifier();
}
@Override
public BlockPos getHeadPosition() {
pony.getOwner().onGround = false;
Entity entity = pony.getOwner();
int i = MathHelper.floor(pony.getOwner().getX());
int j = MathHelper.floor(pony.getOwner().getY() + pony.getOwner().getHeight() + 0.20000000298023224D);
int k = MathHelper.floor(pony.getOwner().getZ());
entity.onGround = false;
BlockPos blockPos = new BlockPos(i, j, k);
BlockPos pos = new BlockPos(
MathHelper.floor(entity.getX()),
MathHelper.floor(entity.getY() + entity.getHeight() + 0.20000000298023224D),
MathHelper.floor(entity.getZ())
);
if (pony.getOwner().world.getBlockState(blockPos).isAir()) {
BlockPos blockPos2 = blockPos.down();
BlockState blockState = pony.getOwner().world.getBlockState(blockPos2);
Block block = blockState.getBlock();
if (entity.world.getBlockState(pos).isAir()) {
BlockPos below = pos.down();
Block block = entity.world.getBlockState(below).getBlock();
if (block.matches(BlockTags.FENCES) || block.matches(BlockTags.WALLS) || block instanceof FenceGateBlock) {
pony.getOwner().onGround = true;
return blockPos2;
entity.onGround = true;
return below;
}
} else {
pony.getOwner().onGround = true;
}
return blockPos;
return pos;
}
@Override
@ -74,7 +75,7 @@ public class EntityPhysics<T extends Ponylike<?> & Owned<? extends Entity>> impl
}
@Override
public void setGravityModifier(float constant) {
public void setBaseGravityModifier(float constant) {
gravity = constant;
}

View file

@ -10,7 +10,7 @@ public interface Physics extends NbtSerialisable {
float getGravityModifier();
void setGravityModifier(float constant);
void setBaseGravityModifier(float constant);
boolean isFlying();

View file

@ -3,7 +3,6 @@ package com.minelittlepony.unicopia.entity.player;
import java.util.UUID;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.container.HeavyInventory;
import com.minelittlepony.unicopia.mixin.Walker;
import net.minecraft.entity.attribute.ClampedEntityAttribute;
@ -25,12 +24,11 @@ class PlayerAttributes {
private static final EntityAttributeModifier PEGASUS_REACH =
new EntityAttributeModifier(UUID.fromString("707b50a8-03e8-40f4-8553-ecf67025fd6d"), "Pegasus Reach", 1.5, Operation.ADDITION);
private double loadStrength = 0;
public void applyAttributes(Pony pony) {
PlayerEntity entity = pony.getOwner();
Race race = pony.getSpecies();
public void applyAttributes(PlayerEntity entity, Race race) {
loadStrength = HeavyInventory.getContentsTotalWorth(entity.inventory, false);
((Walker)entity.abilities).setWalkSpeed(0.1F - (float)(loadStrength / 100000));
((Walker)entity.abilities).setWalkSpeed(0.1F - (float)pony.getInventory().getCarryingWeight());
toggleAttribute(entity, EntityAttributes.ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth());
toggleAttribute(entity, EntityAttributes.KNOCKBACK_RESISTANCE, EARTH_PONY_STRENGTH, race.canUseEarth());

View file

@ -4,6 +4,7 @@ import java.util.Iterator;
import java.util.Map;
import com.google.common.collect.Maps;
import com.minelittlepony.unicopia.container.HeavyInventory;
import com.minelittlepony.unicopia.item.MagicGemItem;
import com.minelittlepony.unicopia.magic.AddictiveMagicalItem;
import com.minelittlepony.unicopia.magic.MagicalItem;
@ -23,6 +24,8 @@ public class PlayerInventory implements Tickable, NbtSerialisable {
private final Pony player;
private double carryingWeight;
PlayerInventory(Pony player) {
this.player = player;
}
@ -67,6 +70,7 @@ public class PlayerInventory implements Tickable, NbtSerialisable {
@Override
public synchronized void tick() {
carryingWeight = HeavyInventory.getContentsTotalWorth(player.getOwner().inventory, false);
Iterator<Map.Entry<AddictiveMagicalItem, Entry>> iterator = dependencies.entrySet().iterator();
@ -106,6 +110,10 @@ public class PlayerInventory implements Tickable, NbtSerialisable {
return false;
}
public double getCarryingWeight() {
return carryingWeight / 100000D;
}
@Override
public void toNBT(CompoundTag compound) {
ListTag items = new ListTag();
@ -115,6 +123,7 @@ public class PlayerInventory implements Tickable, NbtSerialisable {
}
compound.put("dependencies", items);
compound.putDouble("weight", carryingWeight);
}
@Override
@ -130,6 +139,7 @@ public class PlayerInventory implements Tickable, NbtSerialisable {
dependencies.put(entry.item, entry);
}
});
carryingWeight = compound.getDouble("weight");
}
class Entry implements Tickable, NbtSerialisable {

View file

@ -42,6 +42,15 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
dimensions = new PlayerDimensions(pony, this);
}
@Override
public float getGravityModifier() {
float modifier = super.getGravityModifier();
modifier *= (1 + pony.getInventory().getCarryingWeight() * 3);
return modifier;
}
private boolean checkCanFly() {
if (pony.getOwner().abilities.creativeMode) {
return true;

View file

@ -246,7 +246,7 @@ public class Pony implements Caster<PlayerEntity>, Ponylike<PlayerEntity>, Trans
mana.addExertion(-1);
mana.addEnergy(-1);
attributes.applyAttributes(entity, getSpecies());
attributes.applyAttributes(this);
if (dirty) {
sendCapabilities(true);