mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-30 16:28:00 +01:00
The bag of holding will now affect the player's gravity (weight)
This commit is contained in:
parent
5b7f298147
commit
1260f0486c
7 changed files with 41 additions and 23 deletions
|
@ -54,7 +54,7 @@ class GravityCommand {
|
||||||
|
|
||||||
Pony iplayer = Pony.of(player);
|
Pony iplayer = Pony.of(player);
|
||||||
|
|
||||||
iplayer.getPhysics().setGravityModifier(gravity);
|
iplayer.getPhysics().setBaseGravityModifier(gravity);
|
||||||
iplayer.setDirty();
|
iplayer.setDirty();
|
||||||
|
|
||||||
if (isSelf) {
|
if (isSelf) {
|
||||||
|
|
|
@ -30,33 +30,34 @@ public class EntityPhysics<T extends Ponylike<?> & Owned<? extends Entity>> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double calcGravity(double worldConstant) {
|
public double calcGravity(double worldConstant) {
|
||||||
return worldConstant * gravity;
|
return worldConstant * getGravityModifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockPos getHeadPosition() {
|
public BlockPos getHeadPosition() {
|
||||||
|
|
||||||
pony.getOwner().onGround = false;
|
Entity entity = pony.getOwner();
|
||||||
|
|
||||||
int i = MathHelper.floor(pony.getOwner().getX());
|
entity.onGround = false;
|
||||||
int j = MathHelper.floor(pony.getOwner().getY() + pony.getOwner().getHeight() + 0.20000000298023224D);
|
|
||||||
int k = MathHelper.floor(pony.getOwner().getZ());
|
|
||||||
|
|
||||||
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()) {
|
if (entity.world.getBlockState(pos).isAir()) {
|
||||||
BlockPos blockPos2 = blockPos.down();
|
BlockPos below = pos.down();
|
||||||
BlockState blockState = pony.getOwner().world.getBlockState(blockPos2);
|
Block block = entity.world.getBlockState(below).getBlock();
|
||||||
Block block = blockState.getBlock();
|
|
||||||
if (block.matches(BlockTags.FENCES) || block.matches(BlockTags.WALLS) || block instanceof FenceGateBlock) {
|
if (block.matches(BlockTags.FENCES) || block.matches(BlockTags.WALLS) || block instanceof FenceGateBlock) {
|
||||||
pony.getOwner().onGround = true;
|
entity.onGround = true;
|
||||||
return blockPos2;
|
return below;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pony.getOwner().onGround = true;
|
pony.getOwner().onGround = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return blockPos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,7 +75,7 @@ public class EntityPhysics<T extends Ponylike<?> & Owned<? extends Entity>> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGravityModifier(float constant) {
|
public void setBaseGravityModifier(float constant) {
|
||||||
gravity = constant;
|
gravity = constant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ public interface Physics extends NbtSerialisable {
|
||||||
|
|
||||||
float getGravityModifier();
|
float getGravityModifier();
|
||||||
|
|
||||||
void setGravityModifier(float constant);
|
void setBaseGravityModifier(float constant);
|
||||||
|
|
||||||
boolean isFlying();
|
boolean isFlying();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.minelittlepony.unicopia.entity.player;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
import com.minelittlepony.unicopia.container.HeavyInventory;
|
|
||||||
import com.minelittlepony.unicopia.mixin.Walker;
|
import com.minelittlepony.unicopia.mixin.Walker;
|
||||||
|
|
||||||
import net.minecraft.entity.attribute.ClampedEntityAttribute;
|
import net.minecraft.entity.attribute.ClampedEntityAttribute;
|
||||||
|
@ -25,12 +24,11 @@ class PlayerAttributes {
|
||||||
private static final EntityAttributeModifier PEGASUS_REACH =
|
private static final EntityAttributeModifier PEGASUS_REACH =
|
||||||
new EntityAttributeModifier(UUID.fromString("707b50a8-03e8-40f4-8553-ecf67025fd6d"), "Pegasus Reach", 1.5, Operation.ADDITION);
|
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) {
|
((Walker)entity.abilities).setWalkSpeed(0.1F - (float)pony.getInventory().getCarryingWeight());
|
||||||
loadStrength = HeavyInventory.getContentsTotalWorth(entity.inventory, false);
|
|
||||||
|
|
||||||
((Walker)entity.abilities).setWalkSpeed(0.1F - (float)(loadStrength / 100000));
|
|
||||||
|
|
||||||
toggleAttribute(entity, EntityAttributes.ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth());
|
toggleAttribute(entity, EntityAttributes.ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth());
|
||||||
toggleAttribute(entity, EntityAttributes.KNOCKBACK_RESISTANCE, EARTH_PONY_STRENGTH, race.canUseEarth());
|
toggleAttribute(entity, EntityAttributes.KNOCKBACK_RESISTANCE, EARTH_PONY_STRENGTH, race.canUseEarth());
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.minelittlepony.unicopia.container.HeavyInventory;
|
||||||
import com.minelittlepony.unicopia.item.MagicGemItem;
|
import com.minelittlepony.unicopia.item.MagicGemItem;
|
||||||
import com.minelittlepony.unicopia.magic.AddictiveMagicalItem;
|
import com.minelittlepony.unicopia.magic.AddictiveMagicalItem;
|
||||||
import com.minelittlepony.unicopia.magic.MagicalItem;
|
import com.minelittlepony.unicopia.magic.MagicalItem;
|
||||||
|
@ -23,6 +24,8 @@ public class PlayerInventory implements Tickable, NbtSerialisable {
|
||||||
|
|
||||||
private final Pony player;
|
private final Pony player;
|
||||||
|
|
||||||
|
private double carryingWeight;
|
||||||
|
|
||||||
PlayerInventory(Pony player) {
|
PlayerInventory(Pony player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
@ -67,6 +70,7 @@ public class PlayerInventory implements Tickable, NbtSerialisable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void tick() {
|
public synchronized void tick() {
|
||||||
|
carryingWeight = HeavyInventory.getContentsTotalWorth(player.getOwner().inventory, false);
|
||||||
|
|
||||||
Iterator<Map.Entry<AddictiveMagicalItem, Entry>> iterator = dependencies.entrySet().iterator();
|
Iterator<Map.Entry<AddictiveMagicalItem, Entry>> iterator = dependencies.entrySet().iterator();
|
||||||
|
|
||||||
|
@ -106,6 +110,10 @@ public class PlayerInventory implements Tickable, NbtSerialisable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getCarryingWeight() {
|
||||||
|
return carryingWeight / 100000D;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toNBT(CompoundTag compound) {
|
public void toNBT(CompoundTag compound) {
|
||||||
ListTag items = new ListTag();
|
ListTag items = new ListTag();
|
||||||
|
@ -115,6 +123,7 @@ public class PlayerInventory implements Tickable, NbtSerialisable {
|
||||||
}
|
}
|
||||||
|
|
||||||
compound.put("dependencies", items);
|
compound.put("dependencies", items);
|
||||||
|
compound.putDouble("weight", carryingWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -130,6 +139,7 @@ public class PlayerInventory implements Tickable, NbtSerialisable {
|
||||||
dependencies.put(entry.item, entry);
|
dependencies.put(entry.item, entry);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
carryingWeight = compound.getDouble("weight");
|
||||||
}
|
}
|
||||||
|
|
||||||
class Entry implements Tickable, NbtSerialisable {
|
class Entry implements Tickable, NbtSerialisable {
|
||||||
|
|
|
@ -42,6 +42,15 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
dimensions = new PlayerDimensions(pony, this);
|
dimensions = new PlayerDimensions(pony, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getGravityModifier() {
|
||||||
|
float modifier = super.getGravityModifier();
|
||||||
|
|
||||||
|
modifier *= (1 + pony.getInventory().getCarryingWeight() * 3);
|
||||||
|
|
||||||
|
return modifier;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean checkCanFly() {
|
private boolean checkCanFly() {
|
||||||
if (pony.getOwner().abilities.creativeMode) {
|
if (pony.getOwner().abilities.creativeMode) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -246,7 +246,7 @@ public class Pony implements Caster<PlayerEntity>, Ponylike<PlayerEntity>, Trans
|
||||||
mana.addExertion(-1);
|
mana.addExertion(-1);
|
||||||
mana.addEnergy(-1);
|
mana.addEnergy(-1);
|
||||||
|
|
||||||
attributes.applyAttributes(entity, getSpecies());
|
attributes.applyAttributes(this);
|
||||||
|
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
sendCapabilities(true);
|
sendCapabilities(true);
|
||||||
|
|
Loading…
Reference in a new issue