Skip to content
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
- По `3` TUI показывает пронумерованный список серверов. Нажатие `1` сохраняет DJ2.
- Если файлы меняются во время создания архива, плановый бэкап повторяет
попытку после паузы и публикует копию только после полной проверки.
- Порталы между Адом и Основным миром соблюдают границу назначения.
- Порталы Ада и Заснежья выбирают подходящую существующую рамку внутри
границы. Если рядом с расчётной точкой выхода нет, поиск смещается глубже в мир.
- Сложность Hard применяется отдельно при загрузке измерений DJ2.

## Не выпущено — каталог миров DJ2
Expand Down
8 changes: 8 additions & 0 deletions mods/forge-1.12.2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Изменения Forge-модов

## DJ2Fix 0.1.18

- При переходах через порталы Ада и Заснежья поиск существующей рамки
учитывает границу мира назначения. Подходящая ближайшая рамка у края
сохраняет связь с входом.
- Если у расчётной точки подходящего выхода нет, поиск повторяется внутри
границы. Новая рамка строится там же, если подходящего выхода всё ещё нет.

## DJ2Fix 0.1.17

- Shift-клик по предмету в хотбаре открытого обычного верстака переносит
Expand Down
2 changes: 1 addition & 1 deletion mods/forge-1.12.2/packs/dj2/profile.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema=1
id=omkalitycraft.dj2
required.extensions=omkalitydj2fix@0.1.17
required.extensions=omkalitydj2fix@0.1.18
required.capabilities=ftb.claims,ftb.containers,ftb.mute,ftb.player_placement,ftb.spawn,ftb.rtp,dj2fix,fix.vanilla,fix.vanilla.beds,fix.vanilla.disconnect,fix.twilight.inventory,fix.twilight.world,fix.twilight.beans,fix.ae2.planes,fix.wrcbe,fix.mekanism.portable
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ mekanism.portable.9.8.3.390=17573e0c3b2ff9d071a719a06a84c8cd89ca26d1ea3bd7f6e9f3
groovyscript.1.4.3=07617b7ce9170a857199bd61d730a0db3af2685cf83d31734a2d4b628fda7533
crafttweaker.4.1.20.711=dc11a0cb527019385a732907a8057ecd673cdf6bf56d4b5358693e3c2e572a82
zenutils.1.27.2=46dc53134128ced2812fe0744d20b55faaedf2cac2bf9bda47fb17b8c6c698c6
divinerpg.1.7.1=6a220de5ccde3580f44e113d3e89ade6e9196a11799fc6c3c03fbfd5a520a491
universaltweaks.1.20.0=0b94bea35ce762c1f9066695ddafea0091afc7696bdc310f77b5d2fa7139a13c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.omkality.patches.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"DivinePortalBorderMixin"
],
"injectors": {
"defaultRequire": 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.apache.logging.log4j.Logger;

/** Reviewed patch composition for DJ2; reusable implementations live in patches/. */
@Mod(modid="omkalitydj2fix",name="Omkality DJ2 Fix",version="0.1.17",
@Mod(modid="omkalitydj2fix",name="Omkality DJ2 Fix",version="0.1.18",
acceptedMinecraftVersions="[1.12.2]",serverSideOnly=true,acceptableRemoteVersions="*",
dependencies="required-after:omkalitycore@[0.3.18,0.4.0);required-after:mixinbooter")
public final class OmkalityDJ2Fix {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public List<String> getMixinConfigs() {
? Arrays.asList("mixins.omkalitydj2fix.wrcbe.json", "mixins.omkalitydj2fix.twilight.json",
"mixins.omkalitydj2fix.ae2.json", "mixins.omkalitydj2fix.mekanism.json",
"mixins.omkalitydj2fix.disconnect.json", "mixins.omkalitydj2fix.crafttweaker.json",
"mixins.omkalitydj2fix.ftb.json")
"mixins.omkalitydj2fix.ftb.json", "mixins.omkalitydj2fix.divinerpg.json")
: Collections.<String>emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,198 @@

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;
import net.minecraftforge.fml.common.Loader;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

/** Keep the native portal search and its possible exits inside the DJ2 border. */
/** Retain native portal pairing while restricting exits to the destination border. */
public final class NetherPortalBorder {
// Vanilla searches 128 blocks outward. A frame can span 21 blocks and
// its exit needs space for the player's offset and bounding box.
private static final double PORTAL_MARGIN = 128 + 21 + 3;

private static Field destination;
private static Field provider;
private static Field entityX;
private static Field entityY;
private static Field entityZ;
private static Method getDimension;
private static Method getBorder;
private static Method minX;
private static Method minZ;
private static Method maxX;
private static Method maxZ;
private static Method setPosition;

public static void install() throws ReflectiveOperationException {
// A new portal can be built 16 blocks from the search center. The larger
// inset also keeps the subsequent native search and a full frame inside.
private static final double FALLBACK_INSET = 128 + 21 + 3;
private static final double COLUMN_INSET = 3;
private static final ThreadLocal<Search> CURRENT = new ThreadLocal<>();

private static Field destination, provider, iceikaPortal;
private static Field entityX, entityY, entityZ, width, yaw, motionX, motionY, motionZ;
private static Method dimension, worldBorder, minX, minZ, maxX, maxZ;
private static Method findExisting, setPosition, entityExit, playerExit;
private static Method blockName, blockX, blockZ;

public static void install() throws Exception {
Class<?> teleporter = Class.forName("net.minecraft.world.Teleporter");
Class<?> world = Class.forName("net.minecraft.world.World");
Class<?> border = Class.forName("net.minecraft.world.border.WorldBorder");
Class<?> entity = Class.forName("net.minecraft.entity.Entity");
destination = teleporter.getDeclaredField("field_85192_a");
destination.setAccessible(true);
Class<?> network = Class.forName("net.minecraft.network.NetHandlerPlayServer");
Class<?> blockPos = Class.forName("net.minecraft.util.math.BlockPos");
destination = field(teleporter, "field_85192_a");
provider = world.getField("field_73011_w");
getDimension = provider.getType().getMethod("getDimension");
getBorder = world.getMethod("func_175723_af");
dimension = provider.getType().getMethod("getDimension");
worldBorder = world.getMethod("func_175723_af");
minX = border.getMethod("func_177726_b");
minZ = border.getMethod("func_177736_c");
maxX = border.getMethod("func_177728_d");
maxZ = border.getMethod("func_177733_e");
entityX = entity.getField("field_70165_t");
entityY = entity.getField("field_70163_u");
entityZ = entity.getField("field_70161_v");
width = entity.getField("field_70130_N");
yaw = entity.getField("field_70177_z");
motionX = entity.getField("field_70159_w");
motionY = entity.getField("field_70181_x");
motionZ = entity.getField("field_70179_y");
findExisting = teleporter.getMethod("func_180620_b", entity, float.class);
setPosition = entity.getMethod("func_70107_b", double.class, double.class, double.class);
entityExit = exitMethod(entity, "func_70012_b");
playerExit = exitMethod(network, "func_147364_a");
blockX = blockPos.getMethod("func_177958_n");
blockZ = blockPos.getMethod("func_177952_p");
if (Loader.isModLoaded("divinerpg")) {
String type = "divinerpg.utils.DivineTeleporter";
VerifiedArtifacts.requireClass(type, "divinerpg.1.7.1");
iceikaPortal = field(Class.forName(type), "portal");
blockName = iceikaPortal.getType().getMethod("getRegistryName");
}
}

public static void keepSearchInside(Object teleporter, Object entity) throws ReflectiveOperationException {
// During initialization there are no transfers for active players.
if (setPosition == null) {
return;
}
private static Field field(Class<?> owner, String name) throws ReflectiveOperationException {
Field found = owner.getDeclaredField(name);
found.setAccessible(true);
return found;
}

private static Method exitMethod(Class<?> owner, String name) throws ReflectiveOperationException {
return owner.getMethod(name, double.class, double.class, double.class, float.class, float.class);
}

public static boolean find(Object teleporter, Object entity, float rotation,
boolean divine) throws ReflectiveOperationException {
Object world = destination.get(teleporter);
int dimension = (int) getDimension.invoke(provider.get(world));
if (dimension != 0 && dimension != -1) {
return;
int id = (int) dimension.invoke(provider.get(world));
boolean guarded = divine
? iceikaPortal != null && "divinerpg:iceika_portal".equals(
String.valueOf(blockName.invoke(iceikaPortal.get(teleporter))))
: id == 0 || id == -1;
if (!guarded) {
return nativeSearch(teleporter, entity, rotation, null);
}
Search search = new Search(world, entity);
if (search.inside(search.x, search.z, FALLBACK_INSET)) {
return nativeSearch(teleporter, entity, rotation, null);
}
if (scan(teleporter, entity, rotation, search)) {
return true;
}
double x = inset(search.x, search.minX, search.maxX);
double z = inset(search.z, search.minZ, search.maxZ);
if (x == search.x && z == search.z) {
return false;
}
setPosition.invoke(entity, x, search.y, z);
return scan(teleporter, entity, rotation, new Search(world, entity));
}

private static boolean scan(Object teleporter, Object entity, float rotation,
Search search) throws ReflectiveOperationException {
float previousYaw = yaw.getFloat(entity);
double vx = motionX.getDouble(entity);
double vy = motionY.getDouble(entity);
double vz = motionZ.getDouble(entity);
boolean found = nativeSearch(teleporter, entity, rotation, search);
if (!search.rejected) {
return found;
}
// Native selection already rotated the velocity before publishing the exit.
search.cache.remove(search.key);
yaw.setFloat(entity, previousYaw);
motionX.setDouble(entity, vx);
motionY.setDouble(entity, vy);
motionZ.setDouble(entity, vz);
return false;
}

private static boolean nativeSearch(Object teleporter, Object entity, float rotation,
Search search) throws ReflectiveOperationException {
Search previous = CURRENT.get();
CURRENT.set(search);
try {
return (boolean) findExisting.invoke(teleporter, entity, rotation);
} finally {
if (previous == null) CURRENT.remove();
else CURRENT.set(previous);
}
}

public static void clipColumn(Args offset) {
Search search = CURRENT.get();
if (search != null && !search.inside(search.columnX + (int) offset.get(0),
search.columnZ + (int) offset.get(2), COLUMN_INSET)) {
// The native scan stops immediately below y=0.
offset.set(1, search.belowWorld);
}
}

public static boolean containsCached(Object original, long id) throws ReflectiveOperationException {
Map<?, ?> cache = (Map<?, ?>) original;
Long key = Long.valueOf(id);
Search search = CURRENT.get();
if (search == null) {
return cache.containsKey(key);
}
search.cache = cache;
search.key = key;
Object cached = cache.get(key);
if (cached == null) {
return false;
}
if (!search.inside((int) blockX.invoke(cached), (int) blockZ.invoke(cached), COLUMN_INSET)) {
cache.remove(key);
return false;
}
Object border = getBorder.invoke(world);
double x = entityX.getDouble(entity);
double z = entityZ.getDouble(entity);
double safeX = searchCoordinate(x, (double) minX.invoke(border), (double) maxX.invoke(border));
double safeZ = searchCoordinate(z, (double) minZ.invoke(border), (double) maxZ.invoke(border));
if (safeX != x || safeZ != z) {
setPosition.invoke(entity, safeX, entityY.getDouble(entity), safeZ);
return true;
}

public static void exit(Object actor, double x, double y, double z, float rotation,
float pitch, boolean player) throws ReflectiveOperationException {
Search search = CURRENT.get();
if (search != null && !search.inside(x, z, search.clearance)) {
search.rejected = true;
return;
}
(player ? playerExit : entityExit).invoke(actor, x, y, z, rotation, pitch);
}

private static double inset(double value, double lower, double upper) {
double margin = Math.min(FALLBACK_INSET, (upper - lower) / 2.0);
return Math.max(lower + margin, Math.min(value, upper - margin));
}

private static double searchCoordinate(double value, double min, double max) {
double margin = Math.min(PORTAL_MARGIN, (max - min) / 2.0);
return Math.max(min + margin, Math.min(value, max - margin));
private static final class Search {
final double minX, minZ, maxX, maxZ, x, y, z, clearance;
final int columnX, columnZ, belowWorld;
Map<?, ?> cache;
Long key;
boolean rejected;

Search(Object world, Object entity) throws ReflectiveOperationException {
Object border = worldBorder.invoke(world);
minX = (double) NetherPortalBorder.minX.invoke(border);
minZ = (double) NetherPortalBorder.minZ.invoke(border);
maxX = (double) NetherPortalBorder.maxX.invoke(border);
maxZ = (double) NetherPortalBorder.maxZ.invoke(border);
x = entityX.getDouble(entity);
y = entityY.getDouble(entity);
z = entityZ.getDouble(entity);
columnX = (int) Math.floor(x);
columnZ = (int) Math.floor(z);
belowWorld = -1 - (int) Math.floor(y);
clearance = Math.max(0.5, width.getFloat(entity) / 2.0);
}

boolean inside(double x, double z, double inset) {
return x >= minX + inset && x <= maxX - inset && z >= minZ + inset && z <= maxZ - inset;
}
}

private NetherPortalBorder() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.omkality.patches.mixin;

import net.omkality.patches.NetherPortalBorder;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Coerce;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(targets = "divinerpg.utils.DivineTeleporter", remap = false)
public abstract class DivinePortalBorderMixin {
@Redirect(method = "func_180266_a", at = @At(value = "INVOKE",
target = "Ldivinerpg/utils/DivineTeleporter;func_180620_b(Lnet/minecraft/entity/Entity;F)Z"),
require = 2, allow = 2, remap = false)
private boolean omkality$findPortal(@Coerce Object teleporter, @Coerce Object entity, float yaw)
throws ReflectiveOperationException {
return NetherPortalBorder.find(teleporter, entity, yaw, true);
}

@ModifyArgs(method = "func_180620_b", at = @At(value = "INVOKE",
target = "Lnet/minecraft/util/math/BlockPos;func_177982_a(III)Lnet/minecraft/util/math/BlockPos;"),
require = 1, allow = 1, remap = false)
private void omkality$clipColumn(Args offsets) {
NetherPortalBorder.clipColumn(offsets);
}

@Redirect(method = "func_180620_b", at = @At(value = "INVOKE",
target = "Lit/unimi/dsi/fastutil/longs/Long2ObjectMap;containsKey(J)Z"),
require = 1, allow = 1, remap = false)
private boolean omkality$useCached(@Coerce Object cache, long id) throws ReflectiveOperationException {
return NetherPortalBorder.containsCached(cache, id);
}

@Redirect(method = "func_180620_b", at = @At(value = "INVOKE",
target = "Lnet/minecraft/entity/Entity;func_70012_b(DDDFF)V"),
require = 1, allow = 1, remap = false)
private void omkality$entityExit(@Coerce Object entity, double x, double y, double z, float yaw, float pitch)
throws ReflectiveOperationException {
NetherPortalBorder.exit(entity, x, y, z, yaw, pitch, false);
}
}
Loading
Loading