mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-22 13:09:59 +00:00
Server starts
This commit is contained in:
1 parent
330db1a54d
commit
b50b768852
44 files changed
+449
-475
No files matched your search
@@ -21,7 +21,7 @@ package net.minecraftforge.fml;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -32,20 +32,20 @@ import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class RegistryObject<T extends IForgeRegistryEntry<? super T>>
|
||||
public final class RegistryObject<T extends ForgeRegistryEntry<? super T>>
|
||||
{
|
||||
private final String name;
|
||||
private final IForgeRegistry<?> owningRegistry;
|
||||
private T value;
|
||||
private boolean searched;
|
||||
|
||||
public static <T extends IForgeRegistryEntry<T>, U extends T> RegistryObject<U> of(final String name, Supplier<Class<T>> registryType) {
|
||||
public static <T extends ForgeRegistryEntry<T>, U extends T> RegistryObject<U> of(final String name, Supplier<Class<T>> registryType) {
|
||||
return new RegistryObject<>(name, registryType);
|
||||
}
|
||||
|
||||
private static RegistryObject<?> EMPTY = new RegistryObject<>();
|
||||
|
||||
private static <T extends IForgeRegistryEntry<? super T>> RegistryObject<T> empty() {
|
||||
private static <T extends ForgeRegistryEntry<? super T>> RegistryObject<T> empty() {
|
||||
@SuppressWarnings("unchecked")
|
||||
RegistryObject<T> t = (RegistryObject<T>) EMPTY;
|
||||
return t;
|
||||
@@ -57,7 +57,7 @@ public final class RegistryObject<T extends IForgeRegistryEntry<? super T>>
|
||||
this.owningRegistry = null;
|
||||
}
|
||||
|
||||
private <V extends IForgeRegistryEntry<V>> RegistryObject(String name, Supplier<Class<V>> registryType)
|
||||
private <V extends ForgeRegistryEntry<V>> RegistryObject(String name, Supplier<Class<V>> registryType)
|
||||
{
|
||||
this.name = name;
|
||||
IForgeRegistry<V> registry;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.minecraftforge.fml;
|
||||
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class UnsafeHacks
|
||||
{
|
||||
private static final Unsafe UNSAFE;
|
||||
static {
|
||||
try
|
||||
{
|
||||
final Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
theUnsafe.setAccessible(true);
|
||||
UNSAFE = (Unsafe)theUnsafe.get(null);
|
||||
}
|
||||
catch (IllegalAccessException | NoSuchFieldException e)
|
||||
{
|
||||
throw new RuntimeException("BARF!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getField(Field field, Object object) {
|
||||
final long l = UNSAFE.objectFieldOffset(field);
|
||||
return (T) UNSAFE.getObject(object, l);
|
||||
}
|
||||
|
||||
public static <T> T getField(Object object) {
|
||||
UNSAFE.staticFieldBase()
|
||||
}
|
||||
}
|
||||
@@ -19,31 +19,8 @@
|
||||
|
||||
package net.minecraftforge.fml.common.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Utilities for interacting with {@link ByteBuf}.
|
||||
* @author cpw
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
package net.minecraftforge.fml.common.registry;
|
||||
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class GameRegistry
|
||||
* @param registryType The base class of items in this registry.
|
||||
* @return The registry, Null if none is registered.
|
||||
*/
|
||||
public static <K extends IForgeRegistryEntry<K>> IForgeRegistry<K> findRegistry(Class<K> registryType)
|
||||
public static <K extends ForgeRegistryEntry<K>> IForgeRegistry<K> findRegistry(Class<K> registryType)
|
||||
{
|
||||
return RegistryManager.ACTIVE.getRegistry(registryType);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.entity.monster.EntityZombieVillager;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
@@ -34,7 +35,6 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.RegistryNamespaced;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -188,7 +188,7 @@ public class VillagerRegistry
|
||||
}
|
||||
}
|
||||
|
||||
public static class VillagerProfession extends IForgeRegistryEntry.Impl<VillagerProfession>
|
||||
public static class VillagerProfession extends ForgeRegistryEntry<VillagerProfession>
|
||||
{
|
||||
private ResourceLocation name;
|
||||
private ResourceLocation texture;
|
||||
|
||||
@@ -1,18 +1,61 @@
|
||||
package net.minecraftforge.fml.network;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceArrayMap;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.play.client.CPacketCustomPayload;
|
||||
import net.minecraft.network.play.server.SPacketCustomPayload;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.UnsafeHacks;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface ICustomPacket<T extends Packet<?>> {
|
||||
enum Fields {
|
||||
CPACKETCUSTOMPAYLOAD(CPacketCustomPayload.class),
|
||||
SPACKETCUSTOMPAYLOAD(SPacketCustomPayload.class),
|
||||
;
|
||||
|
||||
static final Reference2ReferenceArrayMap<Class<?>, Fields> lookup;
|
||||
static {
|
||||
lookup = Stream.of(values()).
|
||||
collect(Collectors.toMap(Fields::getClazz, Function.identity(), (m1, m2)->m1, Reference2ReferenceArrayMap::new));
|
||||
}
|
||||
|
||||
private final Class<?> clazz;
|
||||
|
||||
public final Field data;
|
||||
public final Field channel;
|
||||
Fields(Class<?> customPacketClass)
|
||||
{
|
||||
this.clazz = customPacketClass;
|
||||
try
|
||||
{
|
||||
data = customPacketClass.getDeclaredField("data");
|
||||
channel = customPacketClass.getDeclaredField("channel");
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
throw new RuntimeException("BARF?");
|
||||
}
|
||||
}
|
||||
|
||||
private Class<?> getClazz()
|
||||
{
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
|
||||
default PacketBuffer getData() {
|
||||
return getBufferDataSupplier().get();
|
||||
return UnsafeHacks.getField(Fields.lookup.get(this.getClass()).data, this);
|
||||
}
|
||||
|
||||
default ResourceLocation getName() {
|
||||
return getChannelNameSupplier().get();
|
||||
return UnsafeHacks.getField(Fields.lookup.get(this.getClass()).channel, this);
|
||||
}
|
||||
|
||||
default NetworkDirection getDirection() {
|
||||
@@ -23,7 +66,4 @@ public interface ICustomPacket<T extends Packet<?>> {
|
||||
default T getThis() {
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
Supplier<ResourceLocation> getChannelNameSupplier();
|
||||
Supplier<PacketBuffer> getBufferDataSupplier();
|
||||
}
|
||||
Reference in new issue
Block a user