Skip to content

Commit

Permalink
improve(bundle,versions): target next verstion to 1.20.5, and improve…
Browse files Browse the repository at this point in the history
… building DefaultItemProvider
  • Loading branch information
Siroshun09 committed Apr 15, 2024
1 parent a1f0fcd commit 518fd69
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,20 @@
import net.okocraft.box.version.common.item.LegacyVersionPatches;
import org.jetbrains.annotations.NotNull;

import static net.okocraft.box.api.util.MCDataVersion.MC_1_19;
import static net.okocraft.box.api.util.MCDataVersion.MC_1_19_4;
import static net.okocraft.box.api.util.MCDataVersion.MC_1_20_3;
import static net.okocraft.box.api.util.MCDataVersion.MC_1_20_4;

final class PatcherFactories {

static @NotNull ItemNamePatcher createItemNamePatcher(@NotNull ItemVersion startingVersion, @NotNull ItemVersion currentVersion) {
var builder = new ItemNamePatcherBuilder();
var dataVer = startingVersion.dataVersion();
var itemVer = startingVersion.defaultItemVersion();

if (dataVer.isBetween(MC_1_19, MC_1_19_4) && itemVer == 0) {
if (LegacyVersionPatches.shouldPatchGoatHorn(startingVersion)) {
builder.append(LegacyVersionPatches::goatHornName);
}

if (dataVer.isBefore(MC_1_20_3) && currentVersion.dataVersion().isAfterOrSame(MC_1_20_3)) {
if (LegacyVersionPatches.shouldPatchShortGrassName(startingVersion, currentVersion)) {
builder.append(LegacyVersionPatches::shortGrassName);
}

if (dataVer.isBefore(MC_1_20_4) && currentVersion.dataVersion().isAfterOrSame(MC_1_20_4)) { // TODO: back to MC_1_21 after Minecraft 1.21 released
if (true || LegacyVersionPatches.shouldPatchPotionName(startingVersion, currentVersion)) { // TODO: fix this after Minecraft 1.20.5 released
builder.append(LegacyVersionPatches::potionName);
}

Expand All @@ -35,10 +28,8 @@ final class PatcherFactories {

static @NotNull ItemDataPatcher createItemDataPatcher(@NotNull ItemVersion startingVersion, @NotNull ItemVersion ignoredCurrentVersion) {
var builder = new ItemDataPatcherBuilder();
var dataVer = startingVersion.dataVersion();
var itemVer = startingVersion.defaultItemVersion();

if (dataVer.isBetween(MC_1_19, MC_1_19_4) && itemVer == 0) {
if (LegacyVersionPatches.shouldPatchGoatHorn(startingVersion)) {
builder.append(LegacyVersionPatches::goatHorn);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package net.okocraft.box.platform;

import net.okocraft.box.api.model.item.ItemVersion;
import net.okocraft.box.api.scheduler.BoxScheduler;
import net.okocraft.box.api.util.Folia;
import net.okocraft.box.api.util.MCDataVersion;
import net.okocraft.box.core.command.CommandRegisterer;
import net.okocraft.box.storage.api.util.item.DefaultItem;
import net.okocraft.box.storage.api.util.item.DefaultItemProvider;
import net.okocraft.box.api.model.item.ItemVersion;
import net.okocraft.box.storage.api.util.item.patcher.ItemDataPatcher;
import net.okocraft.box.storage.api.util.item.patcher.ItemNamePatcher;
import net.okocraft.box.storage.api.util.item.patcher.PatcherFactory;
import net.okocraft.box.version.common.command.BukkitCommandRegisterer;
import net.okocraft.box.version.common.scheduler.FoliaSchedulerWrapper;
import net.okocraft.box.version.paper_1_21.Paper_1_21;
import net.okocraft.box.version.paper_1_20_5.Paper_1_20_5;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
Expand All @@ -22,6 +22,8 @@

public final class PlatformDependent {

private static final ItemVersion TESTING_VERSION = new ItemVersion(MCDataVersion.MC_1_20_4, 1); // TODO: remove this after Minecraft 1.20.5 released

public static @NotNull BoxScheduler createScheduler(@NotNull Plugin plugin) throws NotSupportedException {
if (Folia.check() || MCDataVersion.current().isAfterOrSame(MCDataVersion.MC_1_20)) {
return new FoliaSchedulerWrapper(plugin);
Expand All @@ -31,9 +33,14 @@ public final class PlatformDependent {
}

public static @NotNull DefaultItemProvider createItemProvider() throws NotSupportedException {
if (MCDataVersion.current().isAfterOrSame(MCDataVersion.MC_1_20_4)) { // TODO: back to MC_1_21 after Minecraft 1.21 released
return new DefaultItemProviderImpl(new ItemVersion(MCDataVersion.MC_1_20_4, 0), Paper_1_21::defaultItems);
if (MCDataVersion.current().isSame(TESTING_VERSION.dataVersion())) {
return new DefaultItemProviderImpl(TESTING_VERSION, Paper_1_20_5::defaultItems);
}

if (MCDataVersion.current().isSame(MCDataVersion.MC_1_20_5)) {
return new DefaultItemProviderImpl(Paper_1_20_5.VERSION, Paper_1_20_5::defaultItems);
}

throw new NotSupportedException("Unsupported version: " + Bukkit.getVersion());
}

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ val versionSuffix = "version"
// versions
sequenceOf(
"common",
"paper-1_21"
"paper-1_20_5"
).forEach {
include("$boxPrefix-$versionSuffix-$it")
project(":$boxPrefix-$versionSuffix-$it").projectDir = file("./versions/$it")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
package net.okocraft.box.version.common.item;

import net.okocraft.box.api.model.item.ItemVersion;
import net.okocraft.box.storage.api.model.item.ItemData;
import org.bukkit.Material;
import org.bukkit.MusicInstrument;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MusicInstrumentMeta;
import org.jetbrains.annotations.NotNull;

import static net.okocraft.box.api.util.MCDataVersion.MC_1_19;
import static net.okocraft.box.api.util.MCDataVersion.MC_1_19_4;
import static net.okocraft.box.api.util.MCDataVersion.MC_1_20_3;
import static net.okocraft.box.api.util.MCDataVersion.MC_1_20_5;

public final class LegacyVersionPatches {

public static boolean shouldPatchGoatHorn(@NotNull ItemVersion version) {
return version.dataVersion().isBetween(MC_1_19, MC_1_19_4) && version.defaultItemVersion() == 0;
}

public static @NotNull String goatHornName(@NotNull String original) {
return original.equals("GOAT_HORN") ? "PONDER_GOAT_HORN" : original;
}

public static boolean shouldPatchShortGrassName(@NotNull ItemVersion starting, @NotNull ItemVersion current) {
return starting.dataVersion().isBefore(MC_1_20_3) && current.dataVersion().isAfterOrSame(MC_1_20_3);
}

public static @NotNull String shortGrassName(@NotNull String original) {
return original.equals("GRASS") ? "SHORT_GRASS" : original;
}

public static boolean shouldPatchPotionName(@NotNull ItemVersion starting, @NotNull ItemVersion current) {
return starting.dataVersion().isBefore(MC_1_20_5) && current.dataVersion().isAfterOrSame(MC_1_20_5);
}

public static @NotNull String potionName(@NotNull String original) {
String material;
String potionType;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package net.okocraft.box.version.paper_1_21;
package net.okocraft.box.version.paper_1_20_5;

import net.okocraft.box.api.model.item.ItemVersion;
import net.okocraft.box.api.util.MCDataVersion;
import net.okocraft.box.storage.api.util.item.DefaultItem;
import net.okocraft.box.version.common.item.ItemSources;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;

import java.util.stream.Stream;

public final class Paper_1_21 {
public final class Paper_1_20_5 {

public static final ItemVersion VERSION = new ItemVersion(MCDataVersion.MC_1_20_5, 0);

public static @NotNull Stream<DefaultItem> defaultItems() {
return new ItemSources.Merger()
Expand All @@ -24,7 +28,7 @@ public final class Paper_1_21 {
.result();
}

private Paper_1_21() {
private Paper_1_20_5() {
throw new UnsupportedOperationException();
}
}

0 comments on commit 518fd69

Please sign in to comment.