Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make every Vec3i use BetterBlockPos hash #4501

Open
wants to merge 1 commit into
base: 1.19.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/api/java/baritone/api/utils/BetterBlockPos.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ public static BetterBlockPos from(BlockPos pos) {
return new BetterBlockPos(pos);
}

@Override
public int hashCode() {
return (int) longHash(x, y, z);
}

public static long longHash(BetterBlockPos pos) {
return longHash(pos.x, pos.y, pos.z);
}
Expand Down
39 changes: 39 additions & 0 deletions src/launch/java/baritone/launch/mixins/MixinVec3i.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/


package baritone.launch.mixins;

import baritone.api.utils.BetterBlockPos;
import net.minecraft.core.Vec3i;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

@Mixin(Vec3i.class)
public class MixinVec3i {

/**
* @author Babbaj
* @reason overriding hashCode with different behavior violates the general contract of hashCode.
* 2 BlockPos objects that are equal but give different hashCodes trolls hashmaps and causes duplicate entries.
*/
@Overwrite
public int hashCode() {
Vec3i vec = (Vec3i) (Object) this;
return (int) BetterBlockPos.longHash(vec.getX(), vec.getY(), vec.getZ());
}
}
3 changes: 2 additions & 1 deletion src/launch/resources/mixins.baritone.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"MixinPalettedContainer$Data",
"MixinPlayerController",
"MixinScreen",
"MixinWorldRenderer"
"MixinWorldRenderer",
"MixinVec3i"
]
}