From 2d46cf5c9a1fd10c958f5b7ca8c1efc0e6c534cf Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 26 Sep 2018 00:03:14 +0200 Subject: [PATCH] A flying pegasus can fit through a 1-block gap --- .../com/minelittlepony/unicopia/Unicopia.java | 1 - .../unicopia/mixin/MixinEntity.java | 34 +++++++++++++++++++ .../player/PlayerGravityDelegate.java | 9 +++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/MixinEntity.java diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index ae69f42a..43f1957a 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -156,7 +156,6 @@ public class Unicopia { public static void onBlockHarvested(BlockEvent.HarvestDropsEvent event) { if (event.getState().getBlock() == Blocks.STONE) { int fortuneFactor = 1 + event.getFortuneLevel() * 15; - System.out.println(event.getFortuneLevel()); if (event.getWorld().rand.nextInt(500 / fortuneFactor) == 0) { for (int i = 0; i < 1 + event.getFortuneLevel(); i++) { diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntity.java new file mode 100644 index 00000000..0139875f --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntity.java @@ -0,0 +1,34 @@ +package com.minelittlepony.unicopia.mixin; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.MoverType; +import net.minecraft.util.math.AxisAlignedBB; + +// pseudo code for things forge can't do. +// @Mixin(Entity.class) +public interface MixinEntity { + + // @Accessor("setSize") + static void setSize(Entity self, float width, float height) { + if (self.width != width || self.height != height) { + float f = self.width; + self.width = width; + self.height = height; + + if (self.width < f) { + double d0 = width / 2; + self.setEntityBoundingBox(new AxisAlignedBB( + self.posX - d0, self.posY, self.posZ - d0, + self.posX + d0, self.posY + self.height, self.posZ + d0)); + return; + } + + AxisAlignedBB axisalignedbb = self.getEntityBoundingBox(); + self.setEntityBoundingBox(new AxisAlignedBB(axisalignedbb.minX, axisalignedbb.minY, axisalignedbb.minZ, axisalignedbb.minX + (double)self.width, axisalignedbb.minY + (double)self.height, axisalignedbb.minZ + (double)self.width)); + + if (self.width > f/* && !self.firstUpdate*/ && !self.world.isRemote) { + self.move(MoverType.SELF, (double)(f - self.width), 0, (double)(f - self.width)); + } + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java b/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java index 170266e7..d16c0030 100644 --- a/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java +++ b/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java @@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.player; import com.minelittlepony.unicopia.InbtSerialisable; import com.minelittlepony.unicopia.USounds; +import com.minelittlepony.unicopia.mixin.MixinEntity; import net.minecraft.block.Block; import net.minecraft.block.SoundType; @@ -35,6 +36,7 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtS @Override public void onUpdate(EntityPlayer entity) { + entity.capabilities.allowFlying = entity.capabilities.isCreativeMode || player.getPlayerSpecies().canFly(); if (!entity.capabilities.isCreativeMode) { @@ -43,6 +45,13 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtS isFlying = entity.capabilities.isFlying && !entity.capabilities.isCreativeMode; + if (isFlying) { + MixinEntity.setSize(entity, entity.width, 0.5F); + entity.eyeHeight = entity.height / 2; + } else { + entity.eyeHeight = entity.getDefaultEyeHeight(); + } + if (!entity.capabilities.isCreativeMode && !entity.isElytraFlying()) { if (isFlying && !entity.isRiding()) {