From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Wed, 23 Nov 2022 22:03:33 +0100 Subject: [PATCH] Make EntityCollisionContext a live representation License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) Gale - https://galemc.org This patch is based on the following patch: "Make EntityCollisionContext a live representation" By: Paul Sauve As part of: Airplane (https://github.com/TECHNOVE/Airplane) Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) * Airplane description * While Context is in the name, it is not used as a context. Instead it is always created, use temporarily, then thrown away. This means having a lot of fields to initialize and make space for is useless. I cannot find anywhere in the codebase where this is used as a context which may be saved for later, so this should be safe assuming plugins don't use it for some strange reason. * Airplane copyright * Airplane Copyright (C) 2020 Technove LLC This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . diff --git a/src/main/java/net/minecraft/world/phys/shapes/EntityCollisionContext.java b/src/main/java/net/minecraft/world/phys/shapes/EntityCollisionContext.java index 88a4a72bb390947dc17e5da09a99b2d1b3ac4621..9343195e5e7444a1926db656707df961a5b8ea55 100644 --- a/src/main/java/net/minecraft/world/phys/shapes/EntityCollisionContext.java +++ b/src/main/java/net/minecraft/world/phys/shapes/EntityCollisionContext.java @@ -17,23 +17,33 @@ public class EntityCollisionContext implements CollisionContext { return defaultValue; } }; + // Gale start - Airplane - make EntityCollisionContext a live representation - remove these and pray no plugin uses them + /* private final boolean descending; private final double entityBottom; private final ItemStack heldItem; private final Predicate canStandOnFluid; + */ + // Gale end - Airplane - make EntityCollisionContext a live representation - remove these and pray no plugin uses them @Nullable private final Entity entity; protected EntityCollisionContext(boolean descending, double minY, ItemStack heldItem, Predicate walkOnFluidPredicate, @Nullable Entity entity) { + // Gale start - Airplane - make EntityCollisionContext a live representation - remove these and pray no plugin uses them + /* this.descending = descending; this.entityBottom = minY; this.heldItem = heldItem; this.canStandOnFluid = walkOnFluidPredicate; + */ + // Gale end - Airplane - make EntityCollisionContext a live representation - remove these and pray no plugin uses them this.entity = entity; } @Deprecated protected EntityCollisionContext(Entity entity) { + // Gale start - Airplane - make EntityCollisionContext a live representation - remove unneeded things + /* this( entity.isDescending(), entity.getY(), @@ -41,26 +51,41 @@ public class EntityCollisionContext implements CollisionContext { entity instanceof LivingEntity ? ((LivingEntity)entity)::canStandOnFluid : fluidState -> false, entity ); + */ + this.entity = entity; + // Gale end - Airplane - make EntityCollisionContext a live representation - remove unneeded things } @Override public boolean isHoldingItem(Item item) { - return this.heldItem.is(item); + // Gale start - Airplane - make EntityCollisionContext a live representation + Entity entity = this.entity; + if (entity instanceof LivingEntity livingEntity) { + return livingEntity.getMainHandItem().is(item); + } + return ItemStack.EMPTY.is(item); + // Gale end - Airplane - make EntityCollisionContext a live representation } @Override public boolean canStandOnFluid(FluidState stateAbove, FluidState state) { - return this.canStandOnFluid.test(state) && !stateAbove.getType().isSame(state.getType()); + // Gale start - Airplane - make EntityCollisionContext a live representation + Entity entity = this.entity; + if (entity instanceof LivingEntity livingEntity) { + return livingEntity.canStandOnFluid(state) && !stateAbove.getType().isSame(state.getType()); + } + return false; + // Gale end - Airplane - make EntityCollisionContext a live representation } @Override public boolean isDescending() { - return this.descending; + return this.entity != null && this.entity.isDescending(); // Gale - Airplane - make EntityCollisionContext a live representation } @Override public boolean isAbove(VoxelShape shape, BlockPos pos, boolean defaultValue) { - return this.entityBottom > (double)pos.getY() + shape.max(Direction.Axis.Y) - 1.0E-5F; + return (this.entity == null ? -Double.MAX_VALUE : entity.getY()) > (double) pos.getY() + shape.max(Direction.Axis.Y) - (double) 1.0E-5F; // Gale - Airplane - make EntityCollisionContext a live representation } @Nullable