Skip to content

Commit

Permalink
Merge pull request #32 from SourceWriters/main
Browse files Browse the repository at this point in the history
Remove main branch cause v4 is main
  • Loading branch information
Lauriichan authored Jul 7, 2022
2 parents d48a60a + 2c787ac commit 830b130
Show file tree
Hide file tree
Showing 59 changed files with 1,655 additions and 1,360 deletions.
4 changes: 2 additions & 2 deletions legacy-1_17-compat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.sourcewriters.spigot.rwg</groupId>
<artifactId>legacy-1_17-compat</artifactId>
<version>3.0.0</version>
<version>4.0.0</version>

<properties>
<api.version>3.0.0</api.version>
<api.version>4.0.0</api.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.sourcewriters.spigot.rwg.legacy.api.impl;

import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockEntityState;
import org.bukkit.craftbukkit.v1_17_R1.generator.CustomChunkGenerator;

import net.sourcewriters.spigot.rwg.legacy.api.util.java.reflect.Accessor;
import net.sourcewriters.spigot.rwg.legacy.api.version.provider.VersionProvider;

public final class Accessors {

private static final VersionProvider PROVIDER = VersionProvider.get();

public static final Accessor CUSTOM_CHUNK_GENERATOR = Accessor.of(CustomChunkGenerator.class).findField("generator", "generator");
public static final Accessor CRAFT_WORLD = Accessor.of(CraftWorld.class).findField("generator", "generator");
public static final Accessor CRAFT_BLOCK_ENTITY_STATE = Accessor.of(CraftBlockEntityState.class).findField("entity", "getTileEntity");
public static final Accessor CRAFT_META_SKULL = PROVIDER.craftBukkitAccess("inventory.CraftMetaSkull").findField("profile", "profile");

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@

import com.mojang.authlib.GameProfile;

import net.sourcewriters.spigot.rwg.legacy.api.impl.Accessors;
import net.sourcewriters.spigot.rwg.legacy.api.util.rwg.RWGMaterial;
import net.sourcewriters.spigot.rwg.legacy.api.version.IConversionAccess;
import net.sourcewriters.spigot.rwg.legacy.api.version.handle.ClassLookupProvider;

public final class ConversionAccessImpl implements IConversionAccess {

private final ClassLookupProvider provider;

public ConversionAccessImpl(final ClassLookupProvider provider) {
this.provider = provider;
}

@Override
public Material asBukkit(final RWGMaterial material) {
switch (material) {
Expand Down Expand Up @@ -62,7 +56,7 @@ public boolean isGiantTree(final TreeType type) {
public ItemStack asHeadItem(final GameProfile profile) {
final ItemStack stack = new ItemStack(RWGMaterial.HEAD_ITEM.asBukkit(this));
final SkullMeta meta = (SkullMeta) stack.getItemMeta();
provider.getLookup("cb_skull_meta").setFieldValue(meta, "profile", profile);
Accessors.CRAFT_META_SKULL.setValue(meta, "profile", profile);
stack.setItemMeta(meta);
return stack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,25 @@

import com.syntaxphoenix.syntaxapi.logging.ILogger;

import net.sourcewriters.spigot.rwg.legacy.api.impl.version.handle.GlobalLookup;
import net.sourcewriters.spigot.rwg.legacy.api.impl.version.nms.NmsBiomeAccessImpl;
import net.sourcewriters.spigot.rwg.legacy.api.impl.version.nms.NmsNbtAccessImpl;
import net.sourcewriters.spigot.rwg.legacy.api.impl.version.nms.NmsWorldAccessImpl;
import net.sourcewriters.spigot.rwg.legacy.api.version.INmsAccess;
import net.sourcewriters.spigot.rwg.legacy.api.version.handle.ClassLookupProvider;
import net.sourcewriters.spigot.rwg.legacy.api.version.nms.INmsBiomeAccess;
import net.sourcewriters.spigot.rwg.legacy.api.version.nms.INmsNbtAccess;
import net.sourcewriters.spigot.rwg.legacy.api.version.nms.INmsWorldAccess;

public final class NmsAccessImpl implements INmsAccess {

private final ClassLookupProvider provider = new ClassLookupProvider(GlobalLookup::setup);

private final NmsNbtAccessImpl nbtAccess;
private final NmsBiomeAccessImpl biomeAccess;
private final NmsWorldAccessImpl worldAccess;

public NmsAccessImpl(final ILogger logger) {
nbtAccess = new NmsNbtAccessImpl();
biomeAccess = new NmsBiomeAccessImpl(provider);
worldAccess = new NmsWorldAccessImpl(provider);
biomeAccess = new NmsBiomeAccessImpl();
worldAccess = new NmsWorldAccessImpl();
}

@Override
public ClassLookupProvider getLookupProvider() {
return provider;
}

@Override
public INmsNbtAccess getNbtAccess() {
return nbtAccess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class VersionAccessImpl implements IVersionAccess {

public VersionAccessImpl(final ILogger logger) {
nmsAccess = new NmsAccessImpl(logger);
conversionAccess = new ConversionAccessImpl(nmsAccess.getLookupProvider());
conversionAccess = new ConversionAccessImpl();
biomeAccess = new BiomeAccessImpl();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeManager;
import net.sourcewriters.spigot.rwg.legacy.api.version.handle.ClassLookupProvider;
import net.sourcewriters.spigot.rwg.legacy.api.version.nms.INmsBiomeAccess;

public final class NmsBiomeAccessImpl implements INmsBiomeAccess {

public NmsBiomeAccessImpl(final ClassLookupProvider _ignore) {}

@Override
public org.bukkit.block.Biome getBiomeAt(final World bukkitWorld, final int x, final int y, final int z) {
if (bukkitWorld == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,21 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import net.sourcewriters.spigot.rwg.legacy.api.impl.Accessors;
import net.sourcewriters.spigot.rwg.legacy.api.util.minecraft.ProfileCache;
import net.sourcewriters.spigot.rwg.legacy.api.util.rwg.RWGEntityType;
import net.sourcewriters.spigot.rwg.legacy.api.version.handle.ClassLookupProvider;
import net.sourcewriters.spigot.rwg.legacy.api.version.nms.INmsWorldAccess;

public final class NmsWorldAccessImpl implements INmsWorldAccess {

private final ClassLookupProvider provider;

public NmsWorldAccessImpl(final ClassLookupProvider provider) {
this.provider = provider;
}

@Override
public void setSpawner(final Block block, final EntityType type, final short spawnCount, final short spawnRange, final short delay,
final short maxDelay, final short minDelay, final short maxNearbyEntities, final short requiredPlayerRange) {
final BlockState blockState = block.getState();
if (!(blockState instanceof CreatureSpawner)) {
return;
}
final SpawnerBlockEntity entity = (SpawnerBlockEntity) provider.getLookup("cb_block_entity_state").run(blockState, "entity");
final SpawnerBlockEntity entity = (SpawnerBlockEntity) Accessors.CRAFT_BLOCK_ENTITY_STATE.invoke(blockState, "entity");
final CompoundTag tag = entity.getUpdateTag();
tag.putShort("SpawnCount", spawnCount);
tag.putShort("SpawnRange", spawnRange);
Expand All @@ -53,7 +47,7 @@ public void setHeadTexture(final Block block, final String texture) {
return;
}
final GameProfile gameProfile = ProfileCache.asProfile(texture);
final SkullBlockEntity entity = (SkullBlockEntity) provider.getLookup("cb_block_entity_state").run(blockState, "entity");
final SkullBlockEntity entity = (SkullBlockEntity) Accessors.CRAFT_BLOCK_ENTITY_STATE.invoke(blockState, "entity");
entity.setOwner(gameProfile);
}

Expand All @@ -64,7 +58,7 @@ public String getHeadTexture(final Block block) {
return null;
}
return ProfileCache
.asTexture(((SkullBlockEntity) provider.getLookup("cb_block_entity_state").run(blockState, "entity")).getOwnerProfile());
.asTexture(((SkullBlockEntity) Accessors.CRAFT_BLOCK_ENTITY_STATE.invoke(blockState, "entity")).getOwnerProfile());
}

}
2 changes: 1 addition & 1 deletion legacy-1_17-compat/src/main/resources/api.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"api": 3,
"api": 4,
"version": "${project.version}",
"minecraft": [
"1.17"
Expand Down
4 changes: 2 additions & 2 deletions legacy-1_17_1-compat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.sourcewriters.spigot.rwg</groupId>
<artifactId>legacy-1_17_1-compat</artifactId>
<version>3.0.0</version>
<version>4.0.0</version>

<properties>
<api.version>3.0.0</api.version>
<api.version>4.0.0</api.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.sourcewriters.spigot.rwg.legacy.api.impl;

import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockEntityState;
import org.bukkit.craftbukkit.v1_17_R1.generator.CustomChunkGenerator;

import net.sourcewriters.spigot.rwg.legacy.api.util.java.reflect.Accessor;
import net.sourcewriters.spigot.rwg.legacy.api.version.provider.VersionProvider;

public final class Accessors {

private static final VersionProvider PROVIDER = VersionProvider.get();

public static final Accessor CUSTOM_CHUNK_GENERATOR = Accessor.of(CustomChunkGenerator.class).findField("generator", "generator");
public static final Accessor CRAFT_WORLD = Accessor.of(CraftWorld.class).findField("generator", "generator");
public static final Accessor CRAFT_BLOCK_ENTITY_STATE = Accessor.of(CraftBlockEntityState.class).findField("entity", "getTileEntity");
public static final Accessor CRAFT_META_SKULL = PROVIDER.craftBukkitAccess("inventory.CraftMetaSkull").findField("profile", "profile");

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@

import com.mojang.authlib.GameProfile;

import net.sourcewriters.spigot.rwg.legacy.api.impl.Accessors;
import net.sourcewriters.spigot.rwg.legacy.api.util.rwg.RWGMaterial;
import net.sourcewriters.spigot.rwg.legacy.api.version.IConversionAccess;
import net.sourcewriters.spigot.rwg.legacy.api.version.handle.ClassLookupProvider;

public final class ConversionAccessImpl implements IConversionAccess {

private final ClassLookupProvider provider;

public ConversionAccessImpl(final ClassLookupProvider provider) {
this.provider = provider;
}

@Override
public Material asBukkit(final RWGMaterial material) {
switch (material) {
Expand Down Expand Up @@ -62,7 +56,7 @@ public boolean isGiantTree(final TreeType type) {
public ItemStack asHeadItem(final GameProfile profile) {
final ItemStack stack = new ItemStack(RWGMaterial.HEAD_ITEM.asBukkit(this));
final SkullMeta meta = (SkullMeta) stack.getItemMeta();
provider.getLookup("cb_skull_meta").setFieldValue(meta, "profile", profile);
Accessors.CRAFT_META_SKULL.setValue(meta, "profile", profile);
stack.setItemMeta(meta);
return stack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,25 @@

import com.syntaxphoenix.syntaxapi.logging.ILogger;

import net.sourcewriters.spigot.rwg.legacy.api.impl.version.handle.GlobalLookup;
import net.sourcewriters.spigot.rwg.legacy.api.impl.version.nms.NmsBiomeAccessImpl;
import net.sourcewriters.spigot.rwg.legacy.api.impl.version.nms.NmsNbtAccessImpl;
import net.sourcewriters.spigot.rwg.legacy.api.impl.version.nms.NmsWorldAccessImpl;
import net.sourcewriters.spigot.rwg.legacy.api.version.INmsAccess;
import net.sourcewriters.spigot.rwg.legacy.api.version.handle.ClassLookupProvider;
import net.sourcewriters.spigot.rwg.legacy.api.version.nms.INmsBiomeAccess;
import net.sourcewriters.spigot.rwg.legacy.api.version.nms.INmsNbtAccess;
import net.sourcewriters.spigot.rwg.legacy.api.version.nms.INmsWorldAccess;

public final class NmsAccessImpl implements INmsAccess {

private final ClassLookupProvider provider = new ClassLookupProvider(GlobalLookup::setup);

private final NmsNbtAccessImpl nbtAccess;
private final NmsBiomeAccessImpl biomeAccess;
private final NmsWorldAccessImpl worldAccess;

public NmsAccessImpl(final ILogger logger) {
nbtAccess = new NmsNbtAccessImpl();
biomeAccess = new NmsBiomeAccessImpl(provider);
worldAccess = new NmsWorldAccessImpl(provider);
biomeAccess = new NmsBiomeAccessImpl();
worldAccess = new NmsWorldAccessImpl();
}

@Override
public ClassLookupProvider getLookupProvider() {
return provider;
}

@Override
public INmsNbtAccess getNbtAccess() {
return nbtAccess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class VersionAccessImpl implements IVersionAccess {

public VersionAccessImpl(final ILogger logger) {
nmsAccess = new NmsAccessImpl(logger);
conversionAccess = new ConversionAccessImpl(nmsAccess.getLookupProvider());
conversionAccess = new ConversionAccessImpl();
biomeAccess = new BiomeAccessImpl();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeManager;
import net.sourcewriters.spigot.rwg.legacy.api.version.handle.ClassLookupProvider;
import net.sourcewriters.spigot.rwg.legacy.api.version.nms.INmsBiomeAccess;

public final class NmsBiomeAccessImpl implements INmsBiomeAccess {

public NmsBiomeAccessImpl(final ClassLookupProvider _ignore) {}

@Override
public org.bukkit.block.Biome getBiomeAt(final World bukkitWorld, final int x, final int y, final int z) {
if (bukkitWorld == null) {
Expand Down
Loading

0 comments on commit 830b130

Please sign in to comment.