Skip to content

Commit

Permalink
Deprecate access for 1.20+
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Aug 25, 2024
1 parent 0cba6da commit 742c538
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ public abstract class WorldHandler {
public abstract void translateCraft(@NotNull Craft craft, @NotNull MovecraftLocation newLocation, @NotNull World world);
public abstract void setBlockFast(@NotNull Location location, @NotNull BlockData data);
public abstract void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data);
public abstract @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView);
public abstract void setAccessLocation(@NotNull InventoryView inventoryView, @NotNull Location location);
@Deprecated(forRemoval = true)
public abstract @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView); // Not needed for 1.20+, remove when dropping support for 1.18.2
@Deprecated(forRemoval = true)
public abstract void setAccessLocation(@NotNull InventoryView inventoryView, @NotNull Location location); // Not needed for 1.20+, remove when dropping support for 1.18.2

public static @NotNull String getPackageName(@NotNull String minecraftVersion) {
String[] parts = minecraftVersion.split("\\.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,29 +262,13 @@ public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation

@Override
public @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView) {
AbstractContainerMenu menu = ((CraftInventoryView) inventoryView).getHandle();
Field field = UnsafeUtils.getFieldOfType(ContainerLevelAccess.class, menu.getClass());
if (field != null) {
try {
field.setAccessible(true);
return ((ContainerLevelAccess) field.get(menu)).getLocation();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
// Not needed for 1.20+, remove when dropping support for 1.18.2
return null;
}

@Override
public void setAccessLocation(@NotNull InventoryView inventoryView, @NotNull Location location) {
if (location.getWorld() == null)
return;
ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
BlockPos position = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
ContainerLevelAccess access = ContainerLevelAccess.create(level, position);

AbstractContainerMenu menu = ((CraftInventoryView) inventoryView).getHandle();
UnsafeUtils.trySetFieldOfType(ContainerLevelAccess.class, menu, access);
// Not needed for 1.20+, remove when dropping support for 1.18.2
}

private void moveBlockEntity(@NotNull Level nativeWorld, @NotNull BlockPos newPosition, @NotNull BlockEntity tile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,29 +257,13 @@ public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation

@Override
public @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView) {
AbstractContainerMenu menu = ((CraftInventoryView) inventoryView).getHandle();
Field field = UnsafeUtils.getFieldOfType(ContainerLevelAccess.class, menu.getClass());
if (field != null) {
try {
field.setAccessible(true);
return ((ContainerLevelAccess) field.get(menu)).getLocation();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
// Not needed for 1.20+, remove when dropping support for 1.18.2
return null;
}

@Override
public void setAccessLocation(@NotNull InventoryView inventoryView, @NotNull Location location) {
if (location.getWorld() == null)
return;
ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
BlockPos position = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
ContainerLevelAccess access = ContainerLevelAccess.create(level, position);

AbstractContainerMenu menu = ((CraftInventoryView) inventoryView).getHandle();
UnsafeUtils.trySetFieldOfType(ContainerLevelAccess.class, menu, access);
// Not needed for 1.20+, remove when dropping support for 1.18.2
}

private void moveBlockEntity(@NotNull Level nativeWorld, @NotNull BlockPos newPosition, @NotNull BlockEntity tile) {
Expand Down

0 comments on commit 742c538

Please sign in to comment.