Skip to content

Commit

Permalink
feat: Update to Minecraft 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Jun 9, 2024
1 parent 56aa788 commit b037a39
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 130 deletions.
File renamed without changes.
7 changes: 4 additions & 3 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: publish-snapshot
on:
push:
tags:
- '*'
branches:
- '**'

jobs:
publish-snapshot:
Expand All @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
loader: [common, fabric, forge, neoforge]
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -32,7 +33,7 @@ jobs:
uses: TwelveIterationMods/bump-version@v1
with:
version: ${{ steps.extract-version.outputs.version }}
bump: minor
bump: patch
id: bump-version
- name: Publish
run: ./gradlew :${{ matrix.loader }}:publish '-Pversion=${{ steps.bump-version.outputs.version }}-SNAPSHOT' '-PtwelveIterationsNexusUsername=${{ secrets.NEXUS_USER }}' '-PtwelveIterationsNexusPassword=${{ secrets.NEXUS_PASSWORD }}'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ build
eclipse
run
runs
runserver
logs

common/src/generated/resources/.cache
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Updated to Minecraft 1.20.6
- Updated to Minecraft 1.21
8 changes: 8 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ artifacts {
commonJava sourceSets.main.java.sourceDirectories.singleFile
commonResources sourceSets.main.resources.sourceDirectories.singleFile
commonGeneratedResources sourceSets.generated.resources.sourceDirectories.singleFile
}

sourceSets {
main {
java {
srcDir 'src/shell/java'
}
}
}
1 change: 1 addition & 0 deletions common/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ dependencies {
implementation("net.blay09.mods:balm-common:${balm_version}") {
changing = balm_version.endsWith("SNAPSHOT")
}
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.6"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.blay09.mods.balm.api.Balm;
import net.blay09.mods.balm.api.event.PlayerChangedDimensionEvent;
import net.blay09.mods.netherportalfix.mixin.LivingEntityAccessor;
import net.minecraft.BlockUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -36,15 +35,15 @@ public static void initialize() {
return;
}

BlockUtil.FoundRectangle fromPortal = ReturnPortalManager.findPortalAt(player, fromDim, lastPos);
final var fromPortal = ReturnPortalManager.findPortalAt(player, fromDim, lastPos);
BlockPos toPos = player.blockPosition();
if (fromPortal == null) {
NetherPortalFix.logger.debug("Not storing return portal because I'm not in a portal.");
return;
}

ReturnPortalManager.storeReturnPortal(player, toDim, toPos, fromPortal);
NetherPortalFix.logger.debug("Storing return portal from {} to {} in {}", toDim, fromPortal.minCorner, fromDim);
NetherPortalFix.logger.debug("Storing return portal from {} to {} in {}", toDim, fromPortal, fromDim);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package net.blay09.mods.netherportalfix;

import net.minecraft.BlockUtil;
import net.minecraft.core.BlockPos;

import java.util.UUID;

public class ReturnPortal {
private final UUID uid;
private final BlockUtil.FoundRectangle rectangle;
private final BlockPos pos;

public ReturnPortal(UUID uid, BlockUtil.FoundRectangle rectangle) {
public ReturnPortal(UUID uid, BlockPos pos) {
this.uid = uid;
this.rectangle = rectangle;
this.pos = pos;
}

public UUID getUid() {
return uid;
}

public BlockUtil.FoundRectangle getRectangle() {
return rectangle;
public BlockPos getPos() {
return pos;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.blay09.mods.netherportalfix;

import net.blay09.mods.balm.api.Balm;
import net.minecraft.BlockUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -12,6 +11,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.portal.PortalForcer;
Expand All @@ -26,57 +26,48 @@ public class ReturnPortalManager {
private static final String RETURN_PORTAL_UID = "UID";
private static final String FROM_DIM = "FromDim";
private static final String FROM_POS = "FromPos";
private static final String TO_MIN_CORNER = "ToMinCorner";
private static final String TO_AXIS_1_SIZE = "ToAxis1Size";
private static final String TO_AXIS_2_SIZE = "ToAxis2Size";
private static final String TO_POS = "ToPos";

public static BlockUtil.FoundRectangle findPortalAt(Player player, ResourceKey<Level> dim, BlockPos pos) {
public static BlockPos findPortalAt(Player player, ResourceKey<Level> dim, BlockPos pos) {
MinecraftServer server = player.level().getServer();
if (server != null) {
ServerLevel fromWorld = server.getLevel(dim);
if (fromWorld != null) {
PortalForcer portalForcer = fromWorld.getPortalForcer();
return portalForcer.findPortalAround(pos, false, fromWorld.getWorldBorder()).orElse(null);
return portalForcer.findClosestPortalPosition(pos, false, fromWorld.getWorldBorder()).orElse(null);
}
}

return null;
}

public static BlockUtil.FoundRectangle findRectangleFromReturnPortal(ServerLevel level, ReturnPortal returnPortal) {
PortalForcer portalForcer = level.getPortalForcer();
return portalForcer.findPortalAround(returnPortal.getRectangle().minCorner, false, level.getWorldBorder()).orElse(null);
}

public static ListTag getPlayerPortalList(Player player) {
CompoundTag data = Balm.getHooks().getPersistentData(player);
public static ListTag getPlayerPortalList(Entity entity) {
CompoundTag data = Balm.getHooks().getPersistentData(entity);
ListTag list = data.getList(RETURN_PORTAL_LIST, Tag.TAG_COMPOUND);
data.put(RETURN_PORTAL_LIST, list);
return list;
}

@Nullable
public static ReturnPortal findReturnPortal(ServerPlayer player, ResourceKey<Level> fromDim, BlockPos fromPos) {
ListTag portalList = getPlayerPortalList(player);
public static ReturnPortal findReturnPortal(Entity entity, ResourceKey<Level> fromDim, BlockPos fromPos) {
ListTag portalList = getPlayerPortalList(entity);
for (Tag entry : portalList) {
CompoundTag portal = (CompoundTag) entry;
ResourceKey<Level> entryFromDim = ResourceKey.create(Registries.DIMENSION, new ResourceLocation(portal.getString(FROM_DIM)));
ResourceKey<Level> entryFromDim = ResourceKey.create(Registries.DIMENSION, ResourceLocation.parse(portal.getString(FROM_DIM)));
if (entryFromDim == fromDim) {
BlockPos portalTrigger = BlockPos.of(portal.getLong(FROM_POS));
if (portalTrigger.distSqr(fromPos) <= MAX_PORTAL_DISTANCE_SQ) {
UUID uid = portal.hasUUID(RETURN_PORTAL_UID) ? portal.getUUID(RETURN_PORTAL_UID) : UUID.randomUUID();
BlockPos minCorner = BlockPos.of(portal.getLong(TO_MIN_CORNER));
int axis1Size = portal.getInt(TO_AXIS_1_SIZE);
int axis2Size = portal.getInt(TO_AXIS_2_SIZE);
return new ReturnPortal(uid, new BlockUtil.FoundRectangle(minCorner, axis1Size, axis2Size));
final var uid = portal.hasUUID(RETURN_PORTAL_UID) ? portal.getUUID(RETURN_PORTAL_UID) : UUID.randomUUID();
final var pos = BlockPos.of(portal.getLong(TO_POS));
return new ReturnPortal(uid, pos);
}
}
}

return null;
}

public static void storeReturnPortal(ServerPlayer player, ResourceKey<Level> fromDim, BlockPos fromPos, BlockUtil.FoundRectangle toPortal) {
public static void storeReturnPortal(ServerPlayer player, ResourceKey<Level> fromDim, BlockPos fromPos, BlockPos toPos) {
ListTag portalList = getPlayerPortalList(player);
ReturnPortal returnPortal = findReturnPortal(player, fromDim, fromPos);
if (returnPortal != null) {
Expand All @@ -87,9 +78,7 @@ public static void storeReturnPortal(ServerPlayer player, ResourceKey<Level> fro
portalCompound.putUUID(RETURN_PORTAL_UID, UUID.randomUUID());
portalCompound.putString(FROM_DIM, String.valueOf(fromDim.location()));
portalCompound.putLong(FROM_POS, fromPos.asLong());
portalCompound.putLong(TO_MIN_CORNER, toPortal.minCorner.asLong());
portalCompound.putInt(TO_AXIS_1_SIZE, toPortal.axis1Size);
portalCompound.putInt(TO_AXIS_2_SIZE, toPortal.axis2Size);
portalCompound.putLong(TO_POS, toPos.asLong());
portalList.add(portalCompound);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package net.blay09.mods.netherportalfix.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.blay09.mods.netherportalfix.NetherPortalFix;
import net.blay09.mods.netherportalfix.ReturnPortalManager;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.NetherPortalBlock;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import java.util.Optional;

@Mixin(NetherPortalBlock.class)
public class NetherPortalBlockMixin {

@ModifyExpressionValue(method = "getExitPortal(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/BlockPos;ZLnet/minecraft/world/level/border/WorldBorder;)Lnet/minecraft/world/level/portal/DimensionTransition;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/portal/PortalForcer;findClosestPortalPosition(Lnet/minecraft/core/BlockPos;ZLnet/minecraft/world/level/border/WorldBorder;)Ljava/util/Optional;"))
public Optional<BlockPos> getExitPortal(Optional<BlockPos> original, ServerLevel level, Entity entity) {
final var fromPos = entity.blockPosition();
final ResourceKey<Level> fromDim = entity.level().dimension();
final var returnPortal = ReturnPortalManager.findReturnPortal(entity, fromDim, fromPos);
if (returnPortal == null) {
NetherPortalFix.logger.info("No return portal found");
return original;
}

if (!level.getBlockState(returnPortal.getPos()).is(Blocks.NETHER_PORTAL)) {
NetherPortalFix.logger.info("Return portal is no longer valid");
return original;
}

NetherPortalFix.logger.debug("Return portal found, redirecting! :)");
return Optional.of(returnPortal.getPos());
}

}

This file was deleted.

3 changes: 1 addition & 2 deletions common/src/main/resources/netherportalfix.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_17",
"mixins": [
"EntityAccessor",
"LivingEntityAccessor",
"ServerPlayerMixin"
"NetherPortalBlockMixin"
],
"client": [
],
Expand Down
6 changes: 3 additions & 3 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
],

"depends": {
"fabricloader": ">=0.14",
"fabricloader": ">=${fabric_loader_version}",
"fabric-api": "*",
"balm-fabric": "*",
"minecraft": ">=1.20.2",
"java": ">=17"
"minecraft": "${minecraft_version_range}",
"java": ">=${java_version}"
},
"suggests": {
},
Expand Down
2 changes: 1 addition & 1 deletion forge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'multiloader-loader'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'net.minecraftforge.gradle' version '[6.0.25,6.2)'
id 'org.spongepowered.mixin'
id 'net.darkhax.curseforgegradle'
id "com.modrinth.minotaur"
Expand Down
5 changes: 5 additions & 0 deletions forge/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ dependencies {
implementation("net.blay09.mods:balm-forge:${balm_version}") {
changing = balm_version.contains("SNAPSHOT")
}

compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.6"))
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.3.6")) {
jarJar.ranged(it, "[0.3.6,)")
}
}
Loading

0 comments on commit b037a39

Please sign in to comment.