Skip to content

Commit

Permalink
'steps on block': compensate for short blocks (slabs/snow/etc)
Browse files Browse the repository at this point in the history
also patch for fake_pickup, and error check for player.flying
  • Loading branch information
mcmonkey4eva committed Apr 23, 2022
1 parent f28f2f2 commit b9733e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Expand Up @@ -6,6 +6,7 @@
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
Expand Down Expand Up @@ -101,10 +102,14 @@ public void onPlayerStepsOn(PlayerMoveEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
if (LocationTag.isSameBlock(event.getFrom(), event.getTo())) {
if (event.getTo() == null) {
return;
}
location = new LocationTag(event.getTo().clone().subtract(0, 1, 0));
Location from = event.getFrom().clone().subtract(0, 0.05, 0), to = event.getTo().clone().subtract(0, 0.05, 0);
if (LocationTag.isSameBlock(from, to)) {
return;
}
location = new LocationTag(to);
if (!Utilities.isLocationYSafe(location)) {
return;
}
Expand Down
Expand Up @@ -1704,7 +1704,7 @@ else if (mtr.angle == BlockFace.EAST) {
if (!object.getBukkitEntity().isOnGround()) {
return null;
}
Location loc = object.getBukkitEntity().getLocation().clone().subtract(0, 0.05f, 0);
Location loc = object.getBukkitEntity().getLocation().clone().subtract(0, 0.05, 0);
return new LocationTag(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
});

Expand Down Expand Up @@ -4099,6 +4099,8 @@ else if (getBukkitEntity() instanceof Creeper) {
// @input EntityTag
// @description
// Makes it look like this entity (usually a player) has picked up another entity (item, arrow, or XP orb).
// This technically also works with any entity type.
// Note that the original entity doesn't actually get picked up, it's still there, just invisible now.
// -->
if (mechanism.matches("fake_pickup") && mechanism.requireObject(EntityTag.class)) {
Entity ent = mechanism.valueAsType(EntityTag.class).getBukkitEntity();
Expand All @@ -4109,6 +4111,9 @@ else if (getBukkitEntity() instanceof Creeper) {
for (Player player : NMSHandler.entityHelper.getPlayersThatSee(getBukkitEntity())) {
NMSHandler.packetHelper.sendCollectItemEntity(player, getBukkitEntity(), ent, amount);
}
if (isPlayer()) {
NMSHandler.packetHelper.sendCollectItemEntity((Player) getBukkitEntity(), getBukkitEntity(), ent, amount);
}
}

CoreUtilities.autoPropertyMechanism(this, mechanism);
Expand Down
Expand Up @@ -2878,7 +2878,12 @@ public void adjust(Mechanism mechanism) {
// <PlayerTag.is_flying>
// -->
if (mechanism.matches("flying") && mechanism.requireBoolean()) {
getPlayerEntity().setFlying(mechanism.getValue().asBoolean());
boolean doFly = mechanism.getValue().asBoolean();
if (doFly && !getPlayerEntity().getAllowFlight()) {
Debug.echoError("Must adjust 'can_fly:true' before you can adjust 'flying:true'");
return;
}
getPlayerEntity().setFlying(doFly);
}

// <--[mechanism]
Expand Down

0 comments on commit b9733e9

Please sign in to comment.