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

1.21.3 #4536

Merged
merged 3 commits into from
Nov 6, 2024
Merged

1.21.3 #4536

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
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@

"depends": {
"fabricloader": ">=0.14.22",
"minecraft": ["1.21","1.21.1"]
"minecraft": ["1.21.2","1.21.3"]
}
}
2 changes: 1 addition & 1 deletion forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ A Minecraft pathfinder bot.
modId="minecraft"
mandatory=true
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.21, 1.21.1]"
versionRange="[1.21.2, 1.21.3]"
ordering="NONE"
side="BOTH"
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ org.gradle.jvmargs=-Xmx4G

available_loaders=fabric,forge,neoforge,tweaker

mod_version=1.11.0
mod_version=1.12.0
maven_group=baritone
archives_base_name=baritone

java_version=21

minecraft_version=1.21
minecraft_version=1.21.3

forge_version=51.0.16
forge_version=53.0.7

neoforge_version=20-beta
neoforge_version=6-beta

fabric_version=0.15.11
fabric_version=0.16.7

nether_pathfinder_version=1.4.1

Expand Down
2 changes: 1 addition & 1 deletion neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ archivesBaseName = archivesBaseName + "-neoforge"

unimined.minecraft {

neoForged {
neoForge {
loader project.neoforge_version
mixinConfig ["mixins.baritone.json"]
}
Expand Down
2 changes: 1 addition & 1 deletion neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ A Minecraft pathfinder bot.
modId="minecraft"
type="required"
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.21,1.21.1]"
versionRange="[1.21.2,1.21.3]"
ordering="NONE"
side="BOTH"
7 changes: 0 additions & 7 deletions src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,6 @@ public final class Settings {
*/
public final Setting<Boolean> logAsToast = new Setting<>(false);

/**
* The time of how long the message in the pop-up will display
* <p>
* If below 1000L (1sec), it's better to disable this
*/
public final Setting<Long> toastTimer = new Setting<>(5000L);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed/possible anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably possible but the timer is encoded as a final field in SystemToastId

so we'd have to revert back to implementing a custom Toast subclass or do some other hack

reusing system toasts is much simpler and i don't think its worth the maintenance burden doing the alternatives

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fine.


/**
* Print all the debug messages to chat
*/
Expand Down
4 changes: 2 additions & 2 deletions src/api/java/baritone/api/utils/BetterBlockPos.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public BetterBlockPos below(int amt) {

@Override
public BetterBlockPos relative(Direction dir) {
Vec3i vec = dir.getNormal();
Vec3i vec = dir.getUnitVec3i();
return new BetterBlockPos(x + vec.getX(), y + vec.getY(), z + vec.getZ());
}

Expand All @@ -166,7 +166,7 @@ public BetterBlockPos relative(Direction dir, int dist) {
if (dist == 0) {
return this;
}
Vec3i vec = dir.getNormal();
Vec3i vec = dir.getUnitVec3i();
return new BetterBlockPos(x + vec.getX() * dist, y + vec.getY() * dist, z + vec.getZ() * dist);
}

Expand Down
49 changes: 14 additions & 35 deletions src/api/java/baritone/api/utils/BlockOptionalMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.commands.Commands;
import net.minecraft.core.LayeredRegistryAccess;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.RegistryDataLoader;
import net.minecraft.resources.ResourceKey;
Expand All @@ -42,6 +43,7 @@
import net.minecraft.server.packs.resources.CloseableResourceManager;
import net.minecraft.server.packs.resources.MultiPackResourceManager;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.tags.TagLoader;
import net.minecraft.world.RandomSequences;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -229,8 +231,8 @@ private static VanillaPackResources getVanillaServerPack() {

private static synchronized List<Item> drops(Block b) {
return drops.computeIfAbsent(b, block -> {
ResourceLocation lootTableLocation = block.getLootTable().location();
if (lootTableLocation.equals(BuiltInLootTables.EMPTY.location())) {
Optional<ResourceKey<LootTable>> optionalLootTableKey = block.getLootTable();
if (optionalLootTableKey.isEmpty()) {
return Collections.emptyList();
} else {
List<Item> items = new ArrayList<>();
Expand All @@ -251,13 +253,13 @@ private static synchronized List<Item> drops(Block b) {
}

private static List<ItemStack> getDrops(Block state, LootParams.Builder params) {
ResourceKey<LootTable> lv = state.getLootTable();
if (lv == BuiltInLootTables.EMPTY) {
Optional<ResourceKey<LootTable>> lv = state.getLootTable();
if (lv.isEmpty()) {
return Collections.emptyList();
} else {
LootParams lv2 = params.withParameter(LootContextParams.BLOCK_STATE, state.defaultBlockState()).create(LootContextParamSets.BLOCK);
ServerLevelStub lv3 = (ServerLevelStub) lv2.getLevel();
LootTable lv4 = lv3.holder().getLootTable(lv);
LootTable lv4 = lv3.holder().getLootTable(lv.get());
return((ILootTable) lv4).invokeGetRandomItems(new LootContext.Builder(lv2).withOptionalRandomSeed(1).create(null));
}
}
Expand Down Expand Up @@ -307,39 +309,16 @@ public static Unsafe getUnsafe() {
public static CompletableFuture<RegistryAccess> load() {
PackRepository packRepository = Minecraft.getInstance().getResourcePackRepository();
CloseableResourceManager closeableResourceManager = new MultiPackResourceManager(PackType.SERVER_DATA, packRepository.openAllSelected());
LayeredRegistryAccess<RegistryLayer> layeredRegistryAccess = loadAndReplaceLayer(
closeableResourceManager, RegistryLayer.createRegistryAccess(), RegistryLayer.WORLDGEN, RegistryDataLoader.WORLDGEN_REGISTRIES
LayeredRegistryAccess<RegistryLayer> layeredRegistryAccess = RegistryLayer.createRegistryAccess();
List<Registry.PendingTags<?>> pendingTags = TagLoader.loadTagsForExistingRegistries(
closeableResourceManager, layeredRegistryAccess.getLayer(RegistryLayer.STATIC)
);
return ReloadableServerResources.loadResources(
closeableResourceManager,
return ReloadableServerRegistries.reload(
layeredRegistryAccess,
WorldDataConfiguration.DEFAULT.enabledFeatures(),
Commands.CommandSelection.INTEGRATED,
2,
Runnable::run,
pendingTags,
closeableResourceManager,
Minecraft.getInstance()
).thenApply(reloadableServerResources -> reloadableServerResources.fullRegistries().get());
}

private static LayeredRegistryAccess<RegistryLayer> loadAndReplaceLayer(
ResourceManager resourceManager,
LayeredRegistryAccess<RegistryLayer> registryAccess,
RegistryLayer registryLayer,
List<RegistryDataLoader.RegistryData<?>> registryData
) {
RegistryAccess.Frozen frozen = loadLayer(resourceManager, registryAccess, registryLayer, registryData);
return registryAccess.replaceFrom(registryLayer, frozen);
).thenApply(r -> r.layers().compositeAccess());
}

private static RegistryAccess.Frozen loadLayer(
ResourceManager resourceManager,
LayeredRegistryAccess<RegistryLayer> registryAccess,
RegistryLayer registryLayer,
List<RegistryDataLoader.RegistryData<?>> registryData
) {
RegistryAccess.Frozen frozen = registryAccess.getAccessForLoading(registryLayer);
return RegistryDataLoader.load(resourceManager, frozen, registryData);
}

}
}
5 changes: 3 additions & 2 deletions src/api/java/baritone/api/utils/SettingsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import baritone.api.Settings;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.Vec3i;
import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -241,8 +242,8 @@ private enum Parser implements ISettingParser {
BlockUtils::blockToString
),
ITEM(
Item.class,
str -> BuiltInRegistries.ITEM.get(ResourceLocation.parse(str.trim())), // TODO this now returns AIR on failure instead of null, is that an issue?
Item.class,
str -> BuiltInRegistries.ITEM.get(ResourceLocation.parse(str.trim())).map(Holder.Reference::value).orElse(null),
item -> BuiltInRegistries.ITEM.getKey(item).toString()
),
LIST() {
Expand Down
60 changes: 4 additions & 56 deletions src/api/java/baritone/api/utils/gui/BaritoneToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,13 @@

package baritone.api.utils.gui;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastComponent;
import net.minecraft.client.gui.components.toasts.SystemToast;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;

public class BaritoneToast implements Toast {
private String title;
private String subtitle;
private long firstDrawTime;
private boolean newDisplay;
private long totalShowTime;

public BaritoneToast(Component titleComponent, Component subtitleComponent, long totalShowTime) {
this.title = titleComponent.getString();
this.subtitle = subtitleComponent == null ? null : subtitleComponent.getString();
this.totalShowTime = totalShowTime;
}

public Visibility render(GuiGraphics gui, ToastComponent toastGui, long delta) {
if (this.newDisplay) {
this.firstDrawTime = delta;
this.newDisplay = false;
}


//TODO: check
gui.blit(ResourceLocation.parse("textures/gui/toasts.png"), 0, 0, 0, 32, 160, 32);

if (this.subtitle == null) {
gui.drawString(toastGui.getMinecraft().font, this.title, 18, 12, -11534256);
} else {
gui.drawString(toastGui.getMinecraft().font, this.title, 18, 7, -11534256);
gui.drawString(toastGui.getMinecraft().font, this.subtitle, 18, 18, -16777216);
}

return delta - this.firstDrawTime < totalShowTime ? Visibility.SHOW : Visibility.HIDE;
}

public void setDisplayedText(Component titleComponent, Component subtitleComponent) {
this.title = titleComponent.getString();
this.subtitle = subtitleComponent == null ? null : subtitleComponent.getString();
this.newDisplay = true;
}

public static void addOrUpdate(ToastComponent toast, Component title, Component subtitle, long totalShowTime) {
BaritoneToast baritonetoast = toast.getToast(BaritoneToast.class, new Object());

if (baritonetoast == null) {
toast.addToast(new BaritoneToast(title, subtitle, totalShowTime));
} else {
baritonetoast.setDisplayedText(title, subtitle);
}
}

public class BaritoneToast {
private static final SystemToast.SystemToastId BARITONE_TOAST_ID = new SystemToast.SystemToastId(5000L);
public static void addOrUpdate(Component title, Component subtitle) {
addOrUpdate(Minecraft.getInstance().getToasts(), title, subtitle, baritone.api.BaritoneAPI.getSettings().toastTimer.value);
SystemToast.addOrUpdate(Minecraft.getInstance().getToastManager(), BARITONE_TOAST_ID, title, subtitle);
}
}
9 changes: 5 additions & 4 deletions src/launch/java/baritone/launch/mixins/MixinLivingEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Optional;

Expand Down Expand Up @@ -81,13 +82,13 @@ private float overrideYaw(LivingEntity self) {
}

@Inject(
method = "travel",
method = "updateFallFlyingMovement",
at = @At(
value = "INVOKE",
target = "net/minecraft/world/entity/LivingEntity.getLookAngle()Lnet/minecraft/world/phys/Vec3;"
)
)
private void onPreElytraMove(Vec3 direction, CallbackInfo ci) {
private void onPreElytraMove(Vec3 direction, final CallbackInfoReturnable<Vec3> cir) {
this.getBaritone().ifPresent(baritone -> {
this.elytraRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.MOTION_UPDATE, this.getYRot(), this.getXRot());
baritone.getGameEventHandler().onPlayerRotationMove(this.elytraRotationEvent);
Expand All @@ -97,14 +98,14 @@ private void onPreElytraMove(Vec3 direction, CallbackInfo ci) {
}

@Inject(
method = "travel",
method = "travelFallFlying",
at = @At(
value = "INVOKE",
target = "net/minecraft/world/entity/LivingEntity.move(Lnet/minecraft/world/entity/MoverType;Lnet/minecraft/world/phys/Vec3;)V",
shift = At.Shift.AFTER
)
)
private void onPostElytraMove(Vec3 direction, CallbackInfo ci) {
private void onPostElytraMove(final CallbackInfo ci) {
if (this.elytraRotationEvent != null) {
this.setYRot(this.elytraRotationEvent.getOriginal().getYaw());
this.setXRot(this.elytraRotationEvent.getOriginal().getPitch());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.event.events.RenderEvent;
import com.mojang.blaze3d.resource.GraphicsResourceAllocator;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
Expand All @@ -44,7 +45,7 @@ public class MixinWorldRenderer {
method = "renderLevel",
at = @At("RETURN")
)
private void onStartHand(final DeltaTracker deltaTracker, final boolean bl, final Camera camera, final GameRenderer gameRenderer, final LightTexture lightTexture, final Matrix4f matrix4f, final Matrix4f matrix4f2, final CallbackInfo ci) {
private void onStartHand(final GraphicsResourceAllocator graphicsResourceAllocator, final DeltaTracker deltaTracker, final boolean bl, final Camera camera, final GameRenderer gameRenderer, final LightTexture lightTexture, final Matrix4f matrix4f, final Matrix4f matrix4f2, final CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
PoseStack poseStack = new PoseStack();
poseStack.mulPose(matrix4f);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/baritone/cache/ChunkPacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static CachedChunk pack(LevelChunk chunk) {
Block block = state.getBlock();
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
String name = BlockUtils.blockToString(block);
specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y+chunk.getMinBuildHeight(), z));
specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y+chunk.getMinY(), z));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/baritone/cache/FasterWorldScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private Stream<BlockPos> scanChunkInternal(IPlayerContext ctx, BlockOptionalMeta
long chunkX = (long) pos.x << 4;
long chunkZ = (long) pos.z << 4;

int playerSectionY = (ctx.playerFeet().y - ctx.world().getMinBuildHeight()) >> 4;
int playerSectionY = (ctx.playerFeet().y - ctx.world().getMinY()) >> 4;

return collectChunkSections(lookup, chunkProvider.getChunk(pos.x, pos.z, false), chunkX, chunkZ, playerSectionY).stream();
}
Expand All @@ -165,7 +165,7 @@ private Stream<BlockPos> scanChunkInternal(IPlayerContext ctx, BlockOptionalMeta
private List<BlockPos> collectChunkSections(BlockOptionalMetaLookup lookup, LevelChunk chunk, long chunkX, long chunkZ, int playerSection) {
// iterate over sections relative to player
List<BlockPos> blocks = new ArrayList<>();
int chunkY = chunk.getMinBuildHeight();
int chunkY = chunk.getMinY();
LevelChunkSection[] sections = chunk.getSections();
int l = sections.length;
int i = playerSection - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public MovementState updateState(MovementState state) {
}
state.setInput(Input.MOVE_FORWARD, true);
}
Vec3i avoid = Optional.ofNullable(avoid()).map(Direction::getNormal).orElse(null);
Vec3i avoid = Optional.ofNullable(avoid()).map(Direction::getUnitVec3i).orElse(null);
if (avoid == null) {
avoid = src.subtract(dest);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/baritone/process/FarmProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (!(ctx.world().getBlockState(pos.relative(dir)).getBlock() instanceof AirBlock)) {
continue;
}
Vec3 faceCenter = Vec3.atCenterOf(pos).add(Vec3.atLowerCornerOf(dir.getNormal()).scale(0.5));
Vec3 faceCenter = Vec3.atCenterOf(pos).add(Vec3.atLowerCornerOf(dir.getUnitVec3i()).scale(0.5));
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, blockReachDistance, false);
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isCocoa)) {
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), blockReachDistance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public int getHeight() {
}

@Override
public int getMinBuildHeight() {
public int getMinY() {
return 0;
}

Expand Down
Loading