mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
--------- Co-authored-by: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Co-authored-by: violetc <58360096+s-yh-china@users.noreply.github.com> Co-authored-by: Helvetica Volubi <88063803+Suisuroru@users.noreply.github.com>
146 lines
11 KiB
Diff
146 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
Date: Tue, 27 Jun 2023 09:26:58 +0800
|
|
Subject: [PATCH] Creative fly no clip
|
|
|
|
|
|
diff --git a/net/minecraft/world/entity/ExperienceOrb.java b/net/minecraft/world/entity/ExperienceOrb.java
|
|
index 85c5a8497ee45de232a87c3f152e7ca67c1821ee..47bdbf9c73f19ff85ae93f3e31e45d35fe8c0a92 100644
|
|
--- a/net/minecraft/world/entity/ExperienceOrb.java
|
|
+++ b/net/minecraft/world/entity/ExperienceOrb.java
|
|
@@ -202,7 +202,7 @@ public class ExperienceOrb extends Entity {
|
|
Player prevTarget = this.followingPlayer; // CraftBukkit - store old target
|
|
if (this.followingPlayer == null || this.followingPlayer.isSpectator() || this.followingPlayer.distanceToSqr(this) > 64.0) {
|
|
Player nearestPlayer = this.level().getNearestPlayer(this, 8.0);
|
|
- if (nearestPlayer != null && !nearestPlayer.isSpectator() && !nearestPlayer.isDeadOrDying()) {
|
|
+ if (nearestPlayer != null && !nearestPlayer.isCreativeFlyOrSpectator() && !nearestPlayer.isDeadOrDying()) { // Leaves - creative no clip
|
|
this.followingPlayer = nearestPlayer;
|
|
} else {
|
|
this.followingPlayer = null;
|
|
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
|
|
index e4c7262ded690e56ba2eef71bb7d46f9cd99b8b7..7b0fdecf7ca4a5b6dd910369d6546a909926dff2 100644
|
|
--- a/net/minecraft/world/entity/player/Player.java
|
|
+++ b/net/minecraft/world/entity/player/Player.java
|
|
@@ -247,8 +247,8 @@ public abstract class Player extends Avatar implements ContainerUser {
|
|
|
|
@Override
|
|
public void tick() {
|
|
- this.noPhysics = this.isSpectator();
|
|
- if (this.isSpectator() || this.isPassenger()) {
|
|
+ this.noPhysics = this.isCreativeFlyOrSpectator(); // Leaves - creative no clip
|
|
+ if (this.isCreativeFlyOrSpectator() || this.isPassenger()) { // Leaves - creative no clip
|
|
this.setOnGround(false);
|
|
}
|
|
|
|
@@ -375,7 +375,7 @@ public abstract class Player extends Avatar implements ContainerUser {
|
|
if (this.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.SWIMMING)) {
|
|
Pose desiredPose = this.getDesiredPose();
|
|
Pose pose;
|
|
- if (this.isSpectator() || this.isPassenger() || this.canPlayerFitWithinBlocksAndEntitiesWhen(desiredPose)) {
|
|
+ if (this.isCreativeFlyOrSpectator() || this.isPassenger() || this.canPlayerFitWithinBlocksAndEntitiesWhen(desiredPose)) { // Leaves - creative no clip
|
|
pose = desiredPose;
|
|
} else if (this.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.CROUCHING)) {
|
|
pose = Pose.CROUCHING;
|
|
@@ -507,7 +507,7 @@ public abstract class Player extends Avatar implements ContainerUser {
|
|
this.updateSwingTime();
|
|
this.yHeadRot = this.getYRot();
|
|
this.setSpeed((float)this.getAttributeValue(Attributes.MOVEMENT_SPEED));
|
|
- if (this.getHealth() > 0.0F && !this.isSpectator()) {
|
|
+ if (this.getHealth() > 0.0F && !this.isCreativeFlyOrSpectator()) { // Leaves - creative no clip
|
|
AABB aabb;
|
|
if (this.isPassenger() && !this.getVehicle().isRemoved()) {
|
|
aabb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0);
|
|
@@ -1733,9 +1733,29 @@ public abstract class Player extends Avatar implements ContainerUser {
|
|
return this.gameMode() == GameType.SPECTATOR;
|
|
}
|
|
|
|
+ // Leaves start - creative no clip
|
|
+ public boolean isCreativeFlyOrSpectator() {
|
|
+ return isSpectator() || (org.leavesmc.leaves.LeavesConfig.modify.creativeNoClip && isCreative() && getAbilities().flying);
|
|
+ }
|
|
+
|
|
+ public boolean canSpectatingPlace(net.minecraft.world.level.LevelReader world, BlockState state, BlockPos pos, net.minecraft.world.phys.shapes.CollisionContext context) {
|
|
+ if (this.isCreativeFlyOrSpectator()) {
|
|
+ net.minecraft.world.phys.shapes.VoxelShape voxelShape = state.getCollisionShape(world, pos, context);
|
|
+ return voxelShape.isEmpty() || world.isUnobstructed(this, voxelShape.move(pos.getX(), pos.getY(), pos.getZ()));
|
|
+ } else {
|
|
+ return world.isUnobstructed(state, pos, context);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isCollidable(boolean ignoreClimbing) {
|
|
+ return !isCreativeFlyOrSpectator() && super.isCollidable(ignoreClimbing);
|
|
+ }
|
|
+ // Leaves end - creative no clip
|
|
+
|
|
@Override
|
|
public boolean canBeHitByProjectile() {
|
|
- return !this.isSpectator() && super.canBeHitByProjectile();
|
|
+ return !this.isCreativeFlyOrSpectator() && super.canBeHitByProjectile(); // Leaves - creative no clip
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
|
index 58ec8a43265ebf50fdd71f2cbb7dedf4762bc5b4..c269fd74bb2157f5c5f38d9dd6e1a0a032c9f29c 100644
|
|
--- a/net/minecraft/world/item/BlockItem.java
|
|
+++ b/net/minecraft/world/item/BlockItem.java
|
|
@@ -184,8 +184,9 @@ public class BlockItem extends Item {
|
|
protected boolean canPlace(BlockPlaceContext context, BlockState state) {
|
|
Player player = context.getPlayer();
|
|
// CraftBukkit start
|
|
+ CollisionContext collisionContext = player == null ? CollisionContext.empty() : CollisionContext.placementContext(player);
|
|
Level world = context.getLevel(); // Paper - Cancel hit for vanished players
|
|
- boolean canBuild = (!this.mustSurvive() || state.canSurvive(world, context.getClickedPos())) && world.checkEntityCollision(state, player, CollisionContext.placementContext(player), context.getClickedPos(), true); // Paper - Cancel hit for vanished players
|
|
+ boolean canBuild = (!this.mustSurvive() || state.canSurvive(world, context.getClickedPos())) && ((org.leavesmc.leaves.LeavesConfig.modify.creativeNoClip && context.getPlayer() != null) ? context.getPlayer().canSpectatingPlace(world, state, context.getClickedPos(), collisionContext) : world.checkEntityCollision(state, player, collisionContext, context.getClickedPos(), true)); // Paper - Cancel hit for vanished players // Leaves - creative no clip
|
|
org.bukkit.entity.Player bukkitPlayer = (context.getPlayer() instanceof ServerPlayer) ? (org.bukkit.entity.Player) context.getPlayer().getBukkitEntity() : null;
|
|
|
|
org.bukkit.event.block.BlockCanBuildEvent event = new org.bukkit.event.block.BlockCanBuildEvent(
|
|
diff --git a/net/minecraft/world/item/StandingAndWallBlockItem.java b/net/minecraft/world/item/StandingAndWallBlockItem.java
|
|
index 1f0e7c391d02b18e2c89700025713ec3d759f2ea..300ee12ca9584e53e9d72e3ebfd039beb3fab3b2 100644
|
|
--- a/net/minecraft/world/item/StandingAndWallBlockItem.java
|
|
+++ b/net/minecraft/world/item/StandingAndWallBlockItem.java
|
|
@@ -45,7 +45,7 @@ public class StandingAndWallBlockItem extends BlockItem {
|
|
// return blockState != null && level.isUnobstructed(blockState, clickedPos, CollisionContext.empty()) ? blockState : null;
|
|
// CraftBukkit start
|
|
if (blockState != null) {
|
|
- boolean defaultReturn = level.isUnobstructed(blockState, clickedPos, CollisionContext.empty());
|
|
+ boolean defaultReturn = (org.leavesmc.leaves.LeavesConfig.modify.creativeNoClip && context.getPlayer() != null) ? context.getPlayer().canSpectatingPlace(level, blockState, clickedPos, CollisionContext.empty()) : level.isUnobstructed(blockState, clickedPos, CollisionContext.empty()); // Leaves - creative no clip
|
|
org.bukkit.entity.Player player = (context.getPlayer() instanceof net.minecraft.server.level.ServerPlayer serverPlayer) ? serverPlayer.getBukkitEntity() : null;
|
|
|
|
org.bukkit.event.block.BlockCanBuildEvent event = new org.bukkit.event.block.BlockCanBuildEvent(org.bukkit.craftbukkit.block.CraftBlock.at(context.getLevel(), clickedPos), player, org.bukkit.craftbukkit.block.data.CraftBlockData.fromData(blockState), defaultReturn, org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(context.getHand())); // Paper - Expose hand in BlockCanBuildEvent
|
|
diff --git a/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java b/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
|
|
index 68fcb64d13bbd61ad78137f101ab20264f402df8..7e8ca373a48f89d30d4efdfcfe2acdc903a1fed9 100644
|
|
--- a/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
|
|
@@ -153,7 +153,7 @@ public class ShulkerBoxBlockEntity extends RandomizableContainerBlockEntity impl
|
|
List<Entity> entities = level.getEntities(null, progressDeltaAabb);
|
|
if (!entities.isEmpty()) {
|
|
for (Entity entity : entities) {
|
|
- if (entity.getPistonPushReaction() != PushReaction.IGNORE) {
|
|
+ if (entity.getPistonPushReaction() != PushReaction.IGNORE && !(entity instanceof net.minecraft.world.entity.player.Player player && player.isCreativeFlyOrSpectator())) { // Leaves - creative no clip
|
|
entity.move(
|
|
MoverType.SHULKER_BOX,
|
|
new Vec3(
|
|
diff --git a/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java b/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
|
|
index 0a76cf42aaaaf210a4e43ed9bd3d177f0003ba57..13bd8dc66ad1a6f882d13dc0cbc3f6ae710fab90 100644
|
|
--- a/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
|
|
@@ -151,7 +151,7 @@ public class PistonMovingBlockEntity extends BlockEntity {
|
|
d3 = movementDirection.getStepZ();
|
|
}
|
|
|
|
- entity.setDeltaMovement(d1, d2, d3);
|
|
+ if (!(entity instanceof net.minecraft.world.entity.player.Player player) || !player.isCreativeFlyOrSpectator()) entity.setDeltaMovement(d1, d2, d3); // Leaves - creative no clip
|
|
// Paper - EAR items stuck in slime pushed by a piston
|
|
entity.activatedTick = Math.max(entity.activatedTick, net.minecraft.server.MinecraftServer.currentTick + 10);
|
|
entity.activatedImmunityTick = Math.max(entity.activatedImmunityTick, net.minecraft.server.MinecraftServer.currentTick + 10);
|
|
@@ -187,6 +187,7 @@ public class PistonMovingBlockEntity extends BlockEntity {
|
|
}
|
|
|
|
private static void moveEntityByPiston(Direction noClipDirection, Entity entity, double progress, Direction direction) {
|
|
+ if (entity instanceof net.minecraft.world.entity.player.Player player && player.isCreativeFlyOrSpectator()) return; // Leaves - creative no clip
|
|
NOCLIP.set(noClipDirection);
|
|
Vec3 vec3 = entity.position();
|
|
entity.move(MoverType.PISTON, new Vec3(progress * direction.getStepX(), progress * direction.getStepY(), progress * direction.getStepZ()));
|