Server starts

This commit is contained in:
cpw 2018-08-29 21:30:15 -04:00 committed by LexManos
parent 330db1a54d
commit b50b768852
44 changed files with 449 additions and 475 deletions

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/block/Block.java
+++ b/net/minecraft/block/Block.java
@@ -75,7 +75,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-public class Block implements IItemProvider {
+public class Block extends net.minecraftforge.registries.ForgeRegistryEntry<Block> implements IItemProvider {
protected static final Logger field_196273_d = LogManager.getLogger();
private static final ResourceLocation AIR_ID = new ResourceLocation("air");
public static final RegistryNamespacedDefaultedByKey<ResourceLocation, Block> REGISTRY = new RegistryNamespacedDefaultedByKey<ResourceLocation, Block>(AIR_ID);

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/enchantment/Enchantment.java
+++ b/net/minecraft/enchantment/Enchantment.java
@@ -18,7 +18,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
-public abstract class Enchantment {
+public abstract class Enchantment extends net.minecraftforge.registries.ForgeRegistryEntry<Enchantment> {
public static final RegistryNamespaced<ResourceLocation, Enchantment> REGISTRY = new RegistryNamespaced<ResourceLocation, Enchantment>();
private final EntityEquipmentSlot[] applicableEquipmentTypes;
private final Enchantment.Rarity rarity;

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/item/Item.java
+++ b/net/minecraft/item/Item.java
@@ -50,7 +50,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
-public class Item implements IItemProvider {
+public class Item extends net.minecraftforge.registries.ForgeRegistryEntry<Item> implements IItemProvider {
public static final RegistryNamespaced<ResourceLocation, Item> REGISTRY = new RegistryNamespaced<ResourceLocation, Item>();
public static final Map<Block, Item> BLOCK_TO_ITEM = Maps.<Block, Item>newHashMap();
private static final IItemPropertyGetter DAMAGED_GETTER = (p_210306_0_, p_210306_1_, p_210306_2_) -> {

View file

@ -0,0 +1,19 @@
--- a/net/minecraft/network/NetworkManager.java
+++ b/net/minecraft/network/NetworkManager.java
@@ -384,6 +384,16 @@
return this.field_211397_t;
}
+ public Channel channel()
+ {
+ return channel;
+ }
+
+ public EnumPacketDirection getDirection()
+ {
+ return this.direction;
+ }
+
static class QueuedPacket {
private final Packet<?> packet;
@Nullable

View file

@ -0,0 +1,34 @@
--- a/net/minecraft/network/handshake/client/CPacketHandshake.java
+++ b/net/minecraft/network/handshake/client/CPacketHandshake.java
@@ -13,6 +13,7 @@
private String ip;
private int port;
private EnumConnectionState requestedState;
+ private String fmlVersion = net.minecraftforge.fml.network.NetworkHooks.NETVERSION;
public CPacketHandshake() {
}
@@ -30,11 +31,13 @@
this.ip = buf.readString(255);
this.port = buf.readUnsignedShort();
this.requestedState = EnumConnectionState.getById(buf.readVarInt());
+ this.fmlVersion = net.minecraftforge.fml.network.NetworkHooks.getFMLVersion(this.ip);
+ this.ip = this.ip.split("\0")[0];
}
public void writePacketData(PacketBuffer buf) throws IOException {
buf.writeVarInt(this.protocolVersion);
- buf.writeString(this.ip);
+ buf.writeString(this.ip + "\0"+net.minecraftforge.fml.network.NetworkHooks.NETVERSION+"\0");
buf.writeShort(this.port);
buf.writeVarInt(this.requestedState.getId());
}
@@ -50,4 +53,8 @@
public int getProtocolVersion() {
return this.protocolVersion;
}
+
+ public String getFMLVersion() {
+ return this.fmlVersion;
}
+}

View file

@ -0,0 +1,12 @@
--- a/net/minecraft/network/play/client/CPacketCustomPayload.java
+++ b/net/minecraft/network/play/client/CPacketCustomPayload.java
@@ -9,7 +9,8 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
-public class CPacketCustomPayload implements Packet<INetHandlerPlayServer> {
+public class CPacketCustomPayload implements Packet<INetHandlerPlayServer>, net.minecraftforge.fml.network.ICustomPacket<CPacketCustomPayload>
+{
public static final ResourceLocation field_210344_a = new ResourceLocation("minecraft:brand");
private ResourceLocation channel;
private PacketBuffer data;

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/potion/Potion.java
+++ b/net/minecraft/potion/Potion.java
@@ -24,7 +24,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
-public class Potion {
+public class Potion extends net.minecraftforge.registries.ForgeRegistryEntry<Potion> {
public static final RegistryNamespaced<ResourceLocation, Potion> REGISTRY = new RegistryNamespaced<ResourceLocation, Potion>();
private final Map<IAttribute, AttributeModifier> attributeModifierMap = Maps.<IAttribute, AttributeModifier>newHashMap();
private final boolean isBadEffect;

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/potion/PotionType.java
+++ b/net/minecraft/potion/PotionType.java
@@ -7,7 +7,7 @@
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey;
-public class PotionType {
+public class PotionType extends net.minecraftforge.registries.ForgeRegistryEntry<PotionType> {
private static final ResourceLocation EMPTY = new ResourceLocation("empty");
public static final RegistryNamespacedDefaultedByKey<ResourceLocation, PotionType> REGISTRY = new RegistryNamespacedDefaultedByKey<ResourceLocation, PotionType>(EMPTY);
private final String baseName;

View file

@ -0,0 +1,18 @@
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -111,6 +111,7 @@
LOGGER.warn("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\"");
}
+ net.minecraftforge.fml.server.ServerModLoader.begin(this);
LOGGER.info("Loading properties");
this.settings = new PropertyManager(new File("server.properties"));
this.eula = new ServerEula(new File("eula.txt"));
@@ -182,6 +183,7 @@
if (!PreYggdrasilConverter.tryConvert(this.settings)) {
return false;
} else {
+ net.minecraftforge.fml.server.ServerModLoader.end();
this.setPlayerList(new DedicatedPlayerList(this));
long j = Util.func_211178_c();
if (this.getFolderName() == null) {

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/util/SoundEvent.java
+++ b/net/minecraft/util/SoundEvent.java
@@ -4,7 +4,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
-public class SoundEvent {
+public class SoundEvent extends net.minecraftforge.registries.ForgeRegistryEntry<SoundEvent> {
public static final RegistryNamespaced<ResourceLocation, SoundEvent> REGISTRY = new RegistryNamespaced<ResourceLocation, SoundEvent>();
private final ResourceLocation soundName;

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/world/biome/Biome.java
+++ b/net/minecraft/world/biome/Biome.java
@@ -145,7 +145,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-public abstract class Biome {
+public abstract class Biome extends net.minecraftforge.registries.ForgeRegistryEntry<Biome> {
public static final Logger LOGGER = LogManager.getLogger();
public static final WorldCarver<ProbabilityConfig> field_201907_b = new CaveWorldCarver();
public static final WorldCarver<ProbabilityConfig> field_201908_c = new NetherCaveWorldCarver();

View file

@ -28,7 +28,6 @@ import net.minecraftforge.client.CloudRenderer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
@ -51,6 +50,7 @@ public class ForgeInternalHandler
{
ItemStack stack = ((EntityItem)entity).getItem();
Item item = stack.getItem();
/*
if (item.hasCustomEntity(stack))
{
Entity newEntity = item.createEntity(event.getWorld(), entity, stack);
@ -61,6 +61,7 @@ public class ForgeInternalHandler
event.getWorld().spawnEntity(newEntity);
}
}
*/
}
}

View file

@ -33,15 +33,12 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.VersionChecker;
import net.minecraftforge.fml.WorldPersistenceHooks;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraft.item.Item;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.INBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.stats.StatList;
import net.minecraft.world.storage.SaveHandler;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.common.config.ConfigCategory;
@ -49,16 +46,10 @@ import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.common.model.animation.CapabilityAnimation;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.MissingMappings;
import net.minecraftforge.event.terraingen.DeferredBiomeDecorator;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.fluids.UniversalBucket;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.server.command.ForgeCommand;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent;
@ -118,10 +109,10 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
MinecraftForge.EVENT_BUS.addListener(this::serverStopping);
}
public static Configuration getConfig()
{
return config;
}
// public static Configuration getConfig()
// {
// return config;
// }
private static void remapGeneralPropertyToClient(String key)
{
@ -340,6 +331,7 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
}
}
/*
public void missingMapping(RegistryEvent.MissingMappings<Item> event)
{
for (MissingMappings.Mapping<Item> entry : event.getAllMappings())
@ -351,10 +343,11 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
}
}
}
*/
public void playerLogin(PlayerEvent.PlayerLoggedInEvent event)
{
UsernameCache.setUsername(event.player.getPersistentID(), event.player.getGameProfile().getName());
UsernameCache.setUsername(event.player.getUniqueID(), event.player.getGameProfile().getName());
}
@ -374,6 +367,7 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
}
}
/*
public void registrItems(RegistryEvent.Register<Item> event)
{
// Add and register the forge universal bucket, if it's enabled
@ -385,6 +379,7 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
MinecraftForge.EVENT_BUS.register(universalBucket);
}
}
*/
public void postInit(FMLPostInitializationEvent evt)
{
@ -394,6 +389,7 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
private static void registerAllBiomesAndGenerateEvents()
{
/*
for (Biome biome : ForgeRegistries.BIOMES.getValuesCollection())
{
if (biome.decorator instanceof DeferredBiomeDecorator)
@ -404,16 +400,17 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
BiomeDictionary.ensureHasTypes(biome);
}
*/
}
public void onAvailable(FMLLoadCompleteEvent evt)
{
FluidRegistry.validateFluidRegistry();
// FluidRegistry.validateFluidRegistry();
}
public void serverStarting(FMLServerStartingEvent evt)
{
evt.registerServerCommand(new ForgeCommand());
}
public void serverStopping(FMLServerStoppingEvent evt)
@ -432,7 +429,7 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
}
@Override
public void readData(SaveHandler handler, WorldInfo info, Map<String, INBTBase> propertyMap, NBTTagCompound tag)
public void readData(SaveHandler handler, WorldInfo info, NBTTagCompound tag)
{
DimensionManager.loadDimensionDataMap(tag.hasKey("DimensionData") ? tag.getCompoundTag("DimensionData") : null);
FluidRegistry.loadFluidDefaults(tag);
@ -440,13 +437,6 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
public void mappingChanged(FMLModIdMappingEvent evt)
{
OreDictionary.rebakeMap();
StatList.reinit();
Ingredient.invalidateAll();
DistExecutor.runWhenOn(Dist.CLIENT, ()-> () -> {
Minecraft.getMinecraft().populateSearchTreeManager();
Minecraft.getMinecraft().getSearchTreeManager().onResourceManagerReload(Minecraft.getMinecraft().getResourceManager());
});
}
@Override

View file

@ -19,9 +19,7 @@
package net.minecraftforge.common;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.ICrashCallable;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.eventbus.api.IEventBus;
import java.util.Collections;
@ -35,7 +33,6 @@ import net.minecraft.crash.ICrashReportDetail;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeHooks.SeedEntry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
@ -86,8 +83,6 @@ public class MinecraftForge
{
LOGGER.info(FORGE,"MinecraftForge v{} Initialized", ForgeVersion.getVersion());
OreDictionary.getOreName(0);
UsernameCache.load();
// Load before all the mods, so MC owns the MC fluids
FluidRegistry.validateFluidRegistry();
@ -100,6 +95,7 @@ public class MinecraftForge
/*
public static void preloadCrashClasses(ASMDataTable table, String modID, Set<String> classes)
{
//Find all ICrashReportDetail's handlers and preload them.
@ -129,4 +125,5 @@ public class MinecraftForge
}
}
}
*/
}

View file

@ -40,8 +40,8 @@ import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.resources.IResource;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -50,9 +50,10 @@ import net.minecraftforge.common.animation.ITimeValue;
import net.minecraftforge.common.animation.TimeValues;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.util.JsonUtils;
import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.io.IOException;
@ -67,6 +68,7 @@ import java.util.function.Function;
public final class AnimationStateMachine implements IAnimationStateMachine
{
private static final Logger LOGGER = LogManager.getLogger();
private final ImmutableMap<String, ITimeValue> parameters;
private final ImmutableMap<String, IClip> clips;
private final ImmutableList<String> states;
@ -163,7 +165,7 @@ public final class AnimationStateMachine implements IAnimationStateMachine
}
else
{
FMLLog.log.error("Unknown special event \"{}\", ignoring.", event.event());
LOGGER.error("Unknown special event \"{}\", ignoring.", event.event());
}
}
}
@ -232,7 +234,7 @@ public final class AnimationStateMachine implements IAnimationStateMachine
}
catch(IOException | JsonParseException e)
{
FMLLog.log.error("Exception loading Animation State Machine {}, skipping", location, e);
LOGGER.error("Exception loading Animation State Machine {}, skipping", location, e);
return missing;
}
finally

View file

@ -21,7 +21,7 @@ package net.minecraftforge.common.model.animation;
import java.util.concurrent.Callable;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.INBTBase;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
@ -41,13 +41,13 @@ public class CapabilityAnimation
CapabilityManager.INSTANCE.register(IAnimationStateMachine.class, new Capability.IStorage<IAnimationStateMachine>()
{
@Override
public NBTBase writeNBT(Capability<IAnimationStateMachine> capability, IAnimationStateMachine instance, EnumFacing side)
public INBTBase writeNBT(Capability<IAnimationStateMachine> capability, IAnimationStateMachine instance, EnumFacing side)
{
return null;
}
@Override
public void readNBT(Capability<IAnimationStateMachine> capability, IAnimationStateMachine instance, EnumFacing side, NBTBase nbt) {}
public void readNBT(Capability<IAnimationStateMachine> capability, IAnimationStateMachine instance, EnumFacing side, INBTBase nbt) {}
}, AnimationStateMachine::getMissing);
}

View file

@ -21,7 +21,7 @@ package net.minecraftforge.energy;
import java.util.concurrent.Callable;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.INBTBase;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.*;
@ -37,13 +37,13 @@ public class CapabilityEnergy
CapabilityManager.INSTANCE.register(IEnergyStorage.class, new IStorage<IEnergyStorage>()
{
@Override
public NBTBase writeNBT(Capability<IEnergyStorage> capability, IEnergyStorage instance, EnumFacing side)
public INBTBase writeNBT(Capability<IEnergyStorage> capability, IEnergyStorage instance, EnumFacing side)
{
return new NBTTagInt(instance.getEnergyStored());
}
@Override
public void readNBT(Capability<IEnergyStorage> capability, IEnergyStorage instance, EnumFacing side, NBTBase nbt)
public void readNBT(Capability<IEnergyStorage> capability, IEnergyStorage instance, EnumFacing side, INBTBase nbt)
{
if (!(instance instanceof EnergyStorage))
throw new IllegalArgumentException("Can not deserialize to an instance that isn't the default implementation");

View file

@ -22,6 +22,7 @@ package net.minecraftforge.event;
import java.util.Collection;
import java.util.stream.Collectors;
import net.minecraftforge.registries.ForgeRegistryEntry;
import org.apache.commons.lang3.Validate;
import com.google.common.collect.ImmutableList;
@ -29,13 +30,12 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.eventbus.api.GenericEvent;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
/**
* RegistryEvent supertype.
*/
public class RegistryEvent<T extends IForgeRegistryEntry<T>> extends GenericEvent<T>
public class RegistryEvent<T extends ForgeRegistryEntry<T>> extends GenericEvent<T>
{
RegistryEvent(Class<T> clazz) {
super(clazz);
@ -58,7 +58,7 @@ public class RegistryEvent<T extends IForgeRegistryEntry<T>> extends GenericEven
* ObjectHolders will reload between Blocks and Items, and after all registries have been visited.
* @param <T> The registry top level type
*/
public static class Register<T extends IForgeRegistryEntry<T>> extends RegistryEvent<T>
public static class Register<T extends ForgeRegistryEntry<T>> extends RegistryEvent<T>
{
private final IForgeRegistry<T> registry;
private final ResourceLocation name;
@ -82,7 +82,7 @@ public class RegistryEvent<T extends IForgeRegistryEntry<T>> extends GenericEven
}
public static class MissingMappings<T extends IForgeRegistryEntry<T>> extends RegistryEvent<T>
public static class MissingMappings<T extends ForgeRegistryEntry<T>> extends RegistryEvent<T>
{
private final IForgeRegistry<T> registry;
private final ResourceLocation name;
@ -114,7 +114,7 @@ public class RegistryEvent<T extends IForgeRegistryEntry<T>> extends GenericEven
public ImmutableList<Mapping<T>> getMappings()
{
return ImmutableList.copyOf(this.mappings.stream().filter(e -> e.key.getResourceDomain().equals(this.activeMod.getModId())).collect(Collectors.toList()));
return ImmutableList.copyOf(this.mappings.stream().filter(e -> e.key.getNamespace().equals(this.activeMod.getModId())).collect(Collectors.toList()));
}
public ImmutableList<Mapping<T>> getAllMappings()
@ -154,7 +154,7 @@ public class RegistryEvent<T extends IForgeRegistryEntry<T>> extends GenericEven
REMAP
}
public static class Mapping<T extends IForgeRegistryEntry<T>>
public static class Mapping<T extends ForgeRegistryEntry<T>>
{
public final IForgeRegistry<T> registry;
private final IForgeRegistry<T> pool;

View file

@ -32,7 +32,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.common.MinecraftForge;
import com.google.common.base.Strings;

View file

@ -21,7 +21,7 @@ package net.minecraftforge.fluids.capability;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.INBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
@ -49,7 +49,7 @@ public class CapabilityFluidHandler
private static class DefaultFluidHandlerStorage<T extends IFluidHandler> implements Capability.IStorage<T> {
@Override
public NBTBase writeNBT(Capability<T> capability, T instance, EnumFacing side)
public INBTBase writeNBT(Capability<T> capability, T instance, EnumFacing side)
{
if (!(instance instanceof IFluidTank))
throw new RuntimeException("IFluidHandler instance does not implement IFluidTank");
@ -69,7 +69,7 @@ public class CapabilityFluidHandler
}
@Override
public void readNBT(Capability<T> capability, T instance, EnumFacing side, NBTBase nbt)
public void readNBT(Capability<T> capability, T instance, EnumFacing side, INBTBase nbt)
{
if (!(instance instanceof FluidTank))
throw new RuntimeException("IFluidHandler instance is not instance of FluidTank");

View file

@ -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;

View file

@ -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()
}
}

View file

@ -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

View file

@ -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);
}

View file

@ -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;

View file

@ -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();
}

View file

@ -33,6 +33,7 @@ import java.util.OptionalInt;
*/
public class DyeUtils
{
/*
private static final String[] dyeOredicts = new String[]
{
"dyeWhite",
@ -57,7 +58,7 @@ public class DyeUtils
* Check if an item stack is a dye.
* @param stack the item stack
* @return whether the stack is a dye
*/
* /
public static boolean isDye(ItemStack stack)
{
return metaFromStack(stack).isPresent();
@ -67,7 +68,7 @@ public class DyeUtils
* Get the dye metadata from the stack, which can be passed into {@link EnumDyeColor#byMetadata(int)}.
* @param stack the item stack
* @return an {@link OptionalInt} holding the dye metadata for a dye, or an empty {@link OptionalInt} otherwise
*/
* /
public static OptionalInt metaFromStack(ItemStack stack)
{
if (stack.isEmpty()) return OptionalInt.empty();
@ -83,7 +84,7 @@ public class DyeUtils
* this follows vanilla conventions.
* @param stack the item stack
* @return the dye metadata for a dye, or {@code -1} otherwise
*/
* /
public static int rawMetaFromStack(ItemStack stack)
{
return metaFromStack(stack).orElse(-1);
@ -93,7 +94,7 @@ public class DyeUtils
* Get the dye damage from the stack, which can be passed into {@link EnumDyeColor#byDyeDamage(int)}.
* @param stack the item stack
* @return an {@link OptionalInt} holding the dye damage for a dye, or an empty {@link OptionalInt} otherwise
*/
* /
public static OptionalInt dyeDamageFromStack(ItemStack stack)
{
final OptionalInt meta = metaFromStack(stack);
@ -105,7 +106,7 @@ public class DyeUtils
* this follows vanilla conventions.
* @param stack the item stack
* @return the dye damage for a dye, or {@code -1} otherwise
*/
* /
public static int rawDyeDamageFromStack(ItemStack stack)
{
return dyeDamageFromStack(stack).orElse(-1);
@ -115,10 +116,11 @@ public class DyeUtils
* Get a dye's color.
* @param stack the item stack
* @return an {@link Optional} holding the dye color if present, or an empty {@link Optional} otherwise
*/
* /
public static Optional<EnumDyeColor> colorFromStack(ItemStack stack)
{
final OptionalInt meta = metaFromStack(stack);
return meta.isPresent() ? Optional.of(EnumDyeColor.byMetadata(meta.getAsInt())) : Optional.empty();
}
*/
}

View file

@ -54,6 +54,7 @@ import javax.annotation.Nonnull;
public class OreDictionary
{
/*
private static final boolean DEBUG = false;
private static boolean hasInit = false;
private static List<String> idToName = new ArrayList<String>();
@ -66,7 +67,7 @@ public class OreDictionary
/**
* Minecraft changed from -1 to Short.MAX_VALUE in 1.5 release for the "block wildcard". Use this in case it
* changes again.
*/
* /
public static final int WILDCARD_VALUE = Short.MAX_VALUE;
static {
@ -454,7 +455,7 @@ public class OreDictionary
*
* @param name The unique name for this ore 'oreIron', 'ingotIron', etc..
* @return A number representing the ID for this ore type
*/
* /
public static int getOreID(String name)
{
Integer val = nameToId.get(name);
@ -475,7 +476,7 @@ public class OreDictionary
*
* @param id The ID to translate to a string
* @return The String name, or "Unknown" if not found.
*/
* /
public static String getOreName(int id)
{
return (id >= 0 && id < idToName.size()) ? idToName.get(id) : "Unknown";
@ -487,7 +488,7 @@ public class OreDictionary
*
* @param stack The item stack of the ore.
* @return An array of ids that this ore is registered as.
*/
* /
public static int[] getOreIDs(@Nonnull ItemStack stack)
{
if (stack.isEmpty()) throw new IllegalArgumentException("Stack can not be invalid!");
@ -529,7 +530,7 @@ public class OreDictionary
*
* @param name The ore name, directly calls getOreID
* @return An arrayList containing ItemStacks registered for this ore
*/
* /
public static NonNullList<ItemStack> getOres(String name)
{
return getOres(getOreID(name));
@ -549,7 +550,7 @@ public class OreDictionary
* @param name The ore name, directly calls getOreID if the flag is TRUE
* @param alwaysCreateEntry Flag - should a new entry be created if empty
* @return An arraylist containing ItemStacks registered for this ore
*/
* /
public static NonNullList<ItemStack> getOres(String name, boolean alwaysCreateEntry)
{
if (alwaysCreateEntry) {
@ -567,7 +568,7 @@ public class OreDictionary
*
* @param name The ore name
* @return Whether or not that name is in the Ore Dictionary.
*/
* /
public static boolean doesOreNameExist(String name)
{
return nameToId.get(name) != null;
@ -589,7 +590,7 @@ public class OreDictionary
*
* @param id The ore ID, see getOreID
* @return An List containing ItemStacks registered for this ore
*/
* /
private static NonNullList<ItemStack> getOres(int id)
{
return idToStackUn.size() > id ? idToStackUn.get(id) : EMPTY_LIST;
@ -645,7 +646,7 @@ public class OreDictionary
*
* @param name The name of the ore
* @param ore The ore's ItemStack
*/
* /
private static void registerOreImpl(String name, @Nonnull ItemStack ore)
{
if ("Unknown".equals(name)) return; //prevent bad IDs.
@ -750,4 +751,5 @@ public class OreDictionary
}
}
}
*/
}

View file

@ -31,8 +31,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
public class OreIngredient extends Ingredient
public class OreIngredient //extends Ingredient
{
/*
private NonNullList<ItemStack> ores;
private IntList itemIds = null;
private ItemStack[] array = null;
@ -121,4 +122,5 @@ public class OreIngredient extends Ingredient
{
return true;
}
*/
}

View file

@ -1,313 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.oredict;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.toposort.TopologicalSort;
import net.minecraftforge.fml.common.toposort.TopologicalSort.DirectedGraph;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.RecipeBookCloning;
import net.minecraft.item.crafting.RecipeFireworks;
import net.minecraft.item.crafting.RecipeRepairItem;
import net.minecraft.item.crafting.RecipeTippedArrow;
import net.minecraft.item.crafting.RecipesArmorDyes;
import net.minecraft.item.crafting.RecipesMapCloning;
import net.minecraft.item.crafting.RecipesMapExtending;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.item.crafting.ShieldRecipes;
import net.minecraft.item.crafting.RecipesBanners.RecipeAddPattern;
import net.minecraft.item.crafting.RecipesBanners.RecipeDuplicatePattern;
import javax.annotation.Nullable;
import static net.minecraftforge.oredict.RecipeSorter.Category.*;
@Deprecated //DO NOT USE IN 1.12 UNTIL THIS DEPRECATION MARKER IS REMOVED THIS WILL MOST LIKELY BE DELETED YOU HAVE BEEN WARNED
public class RecipeSorter implements Comparator<IRecipe>
{
public enum Category
{
/**
* Do not use UNKNOWN - it is for recipe types with no clear driver
*/
UNKNOWN,
SHAPELESS,
SHAPED
};
private static class SortEntry
{
private String name;
@Nullable
private Class<?> cls;
private Category cat;
List<String> before = Lists.newArrayList();
List<String> after = Lists.newArrayList();
private SortEntry(String name, @Nullable Class<?> cls, Category cat, String deps)
{
this.name = name;
this.cls = cls;
this.cat = cat;
parseDepends(deps);
}
private void parseDepends(String deps)
{
if (deps.isEmpty()) return;
for (String dep : deps.split(" "))
{
if (dep.startsWith("before:"))
{
before.add(dep.substring(7));
}
else if (dep.startsWith("after:"))
{
after.add(dep.substring(6));
}
else
{
throw new IllegalArgumentException("Invalid dependency: " + dep);
}
}
}
@Override
public String toString()
{
StringBuilder buf = new StringBuilder();
buf.append("RecipeEntry(\"").append(name).append("\", ");
buf.append(cat.name()).append(", ");
buf.append(cls == null ? "" : cls.getName()).append(")");
if (before.size() > 0)
{
buf.append(" Before: ").append(Joiner.on(", ").join(before));
}
if (after.size() > 0)
{
buf.append(" After: ").append(Joiner.on(", ").join(after));
}
return buf.toString();
}
@Override
public int hashCode()
{
return name.hashCode();
}
};
private static Map<Class<?>, Category> categories = Maps.newHashMap();
//private static Map<String, Class<?>> types = Maps.newHashMap();
private static Map<String, SortEntry> entries = Maps.newHashMap();
private static Map<Class<?>, Integer> priorities = Maps.newHashMap();
public static final RecipeSorter INSTANCE = new RecipeSorter();
private static boolean isDirty = true;
private static SortEntry before = new SortEntry("Before", null, UNKNOWN, "");
private static SortEntry after = new SortEntry("After", null, UNKNOWN, "");
private RecipeSorter()
{
register("minecraft:shaped", ShapedRecipes.class, SHAPED, "before:minecraft:shapeless");
register("minecraft:mapextending", RecipesMapExtending.class, SHAPED, "after:minecraft:shaped before:minecraft:shapeless");
register("minecraft:shapeless", ShapelessRecipes.class, SHAPELESS, "after:minecraft:shaped");
register("minecraft:shield_deco", ShieldRecipes.Decoration.class, SHAPELESS, "after:minecraft:shapeless"); //Size 2
register("minecraft:repair", RecipeRepairItem.class, SHAPELESS, "after:minecraft:shapeless"); //Size 4
register("minecraft:bookcloning", RecipeBookCloning.class, SHAPELESS, "after:minecraft:shapeless"); //Size 9
register("minecraft:tippedarrow", RecipeTippedArrow.class, SHAPELESS, "after:minecraft:shapeless"); //Size 9
register("minecraft:fireworks", RecipeFireworks.class, SHAPELESS, "after:minecraft:shapeless"); //Size 10
register("minecraft:armordyes", RecipesArmorDyes.class, SHAPELESS, "after:minecraft:shapeless"); //Size 10
register("minecraft:mapcloning", RecipesMapCloning.class, SHAPELESS, "after:minecraft:shapeless"); //Size 10
register("minecraft:pattern_dupe", RecipeDuplicatePattern.class, SHAPELESS, "after:minecraft:shapeless"); //Size 2
register("minecraft:pattern_add", RecipeAddPattern.class, SHAPELESS, "after:minecraft:shapeless"); //Size 10
register("forge:shapedore", ShapedOreRecipe.class, SHAPED, "after:minecraft:shaped before:minecraft:shapeless");
register("forge:shapelessore", ShapelessOreRecipe.class, SHAPELESS, "after:minecraft:shapeless");
}
@Override
public int compare(IRecipe r1, IRecipe r2)
{
Category c1 = getCategory(r1);
Category c2 = getCategory(r2);
int categoryComparison = -c1.compareTo(c2);
if (categoryComparison != 0)
{
return categoryComparison;
}
else
{
if (r2.getIngredients().size() < r1.getIngredients().size()) return -1;
if (r2.getIngredients().size() > r1.getIngredients().size()) return 1;
return getPriority(r2) - getPriority(r1); // high priority value first!
}
}
private static Set<Class<?>> warned = Sets.newHashSet();
public static void sortCraftManager()
{
bake();
FMLLog.log.debug("Sorting recipes");
warned.clear();
//Collections.sort(CraftingManager.getInstance().getRecipeList(), INSTANCE);
}
public static void register(String name, Class<?> recipe, Category category, String dependencies)
{
assert(category != UNKNOWN) : "Category must not be unknown!";
isDirty = true;
SortEntry entry = new SortEntry(name, recipe, category, dependencies);
entries.put(name, entry);
setCategory(recipe, category);
}
public static void setCategory(Class<?> recipe, Category category)
{
assert(category != UNKNOWN) : "Category must not be unknown!";
categories.put(recipe, category);
}
public static Category getCategory(IRecipe recipe)
{
return getCategory(recipe.getClass());
}
public static Category getCategory(Class<?> recipe)
{
Class<?> cls = recipe;
Category ret = categories.get(cls);
if (ret == null)
{
while (cls != Object.class)
{
cls = cls.getSuperclass();
ret = categories.get(cls);
if (ret != null)
{
categories.put(recipe, ret);
return ret;
}
}
}
return ret == null ? UNKNOWN : ret;
}
private static int getPriority(IRecipe recipe)
{
Class<?> cls = recipe.getClass();
Integer ret = priorities.get(cls);
if (ret == null)
{
if (!warned.contains(cls))
{
FMLLog.bigWarning("Unknown recipe class! {} Modders need to register their recipe types with {}", cls.getName(), RecipeSorter.class.getName());
warned.add(cls);
}
cls = cls.getSuperclass();
while (cls != Object.class)
{
ret = priorities.get(cls);
if (ret != null)
{
priorities.put(recipe.getClass(), ret);
FMLLog.log.debug(" Parent Found: {} - {}", ret, cls.getName());
return ret;
}
}
}
return ret == null ? 0 : ret;
}
private static void bake()
{
if (!isDirty) return;
LOG.debug("Forge RecipeSorter Baking:");
DirectedGraph<SortEntry> sorter = new DirectedGraph<SortEntry>();
sorter.addNode(before);
sorter.addNode(after);
sorter.addEdge(before, after);
for (Map.Entry<String, SortEntry> entry : entries.entrySet())
{
sorter.addNode(entry.getValue());
}
for (Map.Entry<String, SortEntry> e : entries.entrySet())
{
SortEntry entry = e.getValue();
boolean postAdded = false;
sorter.addEdge(before, entry);
for (String dep : entry.after)
{
if (entries.containsKey(dep))
{
sorter.addEdge(entries.get(dep), entry);
}
}
for (String dep : entry.before)
{
postAdded = true;
sorter.addEdge(entry, after);
if (entries.containsKey(dep))
{
sorter.addEdge(entry, entries.get(dep));
}
}
if (!postAdded)
{
sorter.addEdge(entry, after);
}
}
List<SortEntry> sorted = TopologicalSort.topologicalSort(sorter);
int x = sorted.size();
for (SortEntry entry : sorted)
{
FMLLog.log.debug(" {}: {}", x, entry);
priorities.put(entry.cls, x--);
}
}
}

View file

@ -50,8 +50,9 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
public class ShapedOreRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IShapedRecipe
public class ShapedOreRecipe //extends IForgeRegistryEntry.Impl<IRecipe> implements IShapedRecipe
{
/*
@Deprecated
public static final int MAX_CRAFT_GRID_WIDTH = 3;
@Deprecated
@ -110,7 +111,7 @@ public class ShapedOreRecipe extends IForgeRegistryEntry.Impl<IRecipe> implement
/**
* Based on {@link net.minecraft.item.crafting.ShapedRecipes#checkMatch(InventoryCrafting, int, int, boolean)}
*/
* /
protected boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror)
{
for (int x = 0; x < inv.getWidth(); x++)
@ -254,4 +255,5 @@ public class ShapedOreRecipe extends IForgeRegistryEntry.Impl<IRecipe> implement
ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
return new ShapedOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), result, primer);
}
*/
}

View file

@ -43,7 +43,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
public class ShapelessOreRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
public class ShapelessOreRecipe {} /*extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
@Nonnull
protected ItemStack output = ItemStack.EMPTY;
@ -158,3 +158,4 @@ public class ShapelessOreRecipe extends IForgeRegistryEntry.Impl<IRecipe> implem
return new ShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), ings, itemstack);
}
}
*/

View file

@ -56,7 +56,7 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRegistryInternal<V>, IForgeRegistryModifiable<V>
public class ForgeRegistry<V extends ForgeRegistryEntry<V>> implements IForgeRegistryInternal<V>, IForgeRegistryModifiable<V>
{
public static Marker REGISTRIES = MarkerManager.getMarker("REGISTRIES");
private static Logger LOGGER = LogManager.getLogger();
@ -100,7 +100,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
this.clear = clear;
this.validate = validate;
this.missing = missing;
this.isDelegated = IForgeRegistryEntry.Impl.class.isAssignableFrom(superType); //TODO: Make this IDelegatedRegistryEntry?
this.isDelegated = ForgeRegistryEntry.class.isAssignableFrom(superType); //TODO: Make this IDelegatedRegistryEntry?
this.allowOverrides = allowOverrides;
this.isModifiable = isModifiable;
this.dummyFactory = dummyFactory;
@ -392,7 +392,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
private RegistryDelegate<V> getDelegate(V thing)
{
if (isDelegated)
return (RegistryDelegate<V>)((IForgeRegistryEntry.Impl<V>)thing).delegate;
return (RegistryDelegate<V>)((ForgeRegistryEntry<V>)thing).delegate;
else
throw new IllegalStateException("Tried to get existing delegate from registry that is not delegated.");
}

View file

@ -0,0 +1,68 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.registries;
import com.google.common.reflect.TypeToken;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.ModThreadContext;
import org.apache.logging.log4j.LogManager;
import javax.annotation.Nullable;
@SuppressWarnings("unchecked")
public abstract class ForgeRegistryEntry<V extends ForgeRegistryEntry<V>>
{
private final TypeToken<V> token = new TypeToken<V>(getClass()){};
public final IRegistryDelegate<V> delegate = new RegistryDelegate<>((V)this, (Class<V>)token.getRawType());
private ResourceLocation registryName = null;
public final V setRegistryName(String name)
{
if (getRegistryName() != null)
throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName());
int index = name.lastIndexOf(':');
String oldPrefix = index == -1 ? "" : name.substring(0, index).toLowerCase();
name = index == -1 ? name : name.substring(index + 1);
String prefix = ModThreadContext.get().getActiveContainer().getPrefix();
if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0)
{
LogManager.getLogger().info("Potentially Dangerous alternative prefix `{}` for name `{}`, expected `{}`. This could be a intended override, but in most cases indicates a broken mod.", oldPrefix, name, prefix);
prefix = oldPrefix;
}
this.registryName = new ResourceLocation(prefix, name);
return (V)this;
}
//Helper functions
public final V setRegistryName(ResourceLocation name){ return setRegistryName(name.toString()); }
public final V setRegistryName(String modID, String name){ return setRegistryName(modID + ":" + name); }
@Nullable
public final ResourceLocation getRegistryName()
{
if (delegate.name() != null) return delegate.name();
return registryName != null ? registryName : null;
}
public final Class<V> getRegistryType() { return (Class<V>)token.getRawType(); }
}

View file

@ -26,10 +26,10 @@ import com.google.common.collect.Multimap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockObserver;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
@ -50,9 +50,6 @@ import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.MissingMappings;
import net.minecraftforge.fml.common.EnhancedRuntimeException;
import net.minecraftforge.fml.StartupQuery;
import net.minecraftforge.fml.common.ZipperUtil;
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
import net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession;
import com.google.common.collect.ArrayListMultimap;
@ -137,9 +134,9 @@ public class GameData
makeRegistry(SOUNDEVENTS, SoundEvent.class, MAX_SOUND_ID).create();
makeRegistry(POTIONTYPES, PotionType.class, MAX_POTIONTYPE_ID, new ResourceLocation("empty")).create();
makeRegistry(ENCHANTMENTS, Enchantment.class, MAX_ENCHANTMENT_ID).create();
makeRegistry(RECIPES, IRecipe.class, MAX_RECIPE_ID).disableSaving().allowModification().addCallback(RecipeCallbacks.INSTANCE).create();
makeRegistry(PROFESSIONS, VillagerProfession.class, MAX_PROFESSION_ID).create();
entityRegistry = (ForgeRegistry<EntityEntry>)makeRegistry(ENTITIES, EntityEntry.class, MAX_ENTITY_ID).addCallback(EntityCallbacks.INSTANCE).create();
// makeRegistry(RECIPES, IRecipe.class, MAX_RECIPE_ID).disableSaving().allowModification().addCallback(RecipeCallbacks.INSTANCE).create();
// makeRegistry(PROFESSIONS, VillagerProfession.class, MAX_PROFESSION_ID).create();
// entityRegistry = (ForgeRegistry<EntityEntry>)makeRegistry(ENTITIES, EntityEntry.class, MAX_ENTITY_ID).addCallback(EntityCallbacks.INSTANCE).create();
}
private static <T extends IForgeRegistryEntry<T>> RegistryBuilder<T> makeRegistry(ResourceLocation name, Class<T> type, int min, int max)
@ -178,13 +175,13 @@ public class GameData
@SuppressWarnings("unchecked")
public static BiMap<Block,Item> getBlockItemMap()
{
return RegistryManager.ACTIVE.getRegistry((Class<K>)Item.class).getSlaveMap(BLOCK_TO_ITEM, BiMap.class);
return RegistryManager.ACTIVE.getRegistry(Item.class).getSlaveMap(BLOCK_TO_ITEM, BiMap.class);
}
@SuppressWarnings("unchecked")
public static ObjectIntIdentityMap<IBlockState> getBlockStateIDMap()
{
return RegistryManager.ACTIVE.getRegistry((Class<K>)Block.class).getSlaveMap(BLOCKSTATE_TO_ID, ObjectIntIdentityMap.class);
return RegistryManager.ACTIVE.getRegistry(Block.class).getSlaveMap(BLOCKSTATE_TO_ID, ObjectIntIdentityMap.class);
}
public static <K extends IForgeRegistryEntry<K>> K register_impl(K value)
@ -201,7 +198,7 @@ public class GameData
public static void vanillaSnapshot()
{
LOGGER.debug("Creating vanilla freeze snapshot");
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends ForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
{
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(r.getKey());
loadRegistry(r.getKey(), RegistryManager.ACTIVE, RegistryManager.VANILLA, clazz, true);
@ -232,7 +229,7 @@ public class GameData
});
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.freeze());
// the id mapping is fanilized, no ids actually changed but this is a good place to tell everyone to 'bake' their stuff.
// the id mapping is finalized, no ids actually changed but this is a good place to tell everyone to 'bake' their stuff.
//Loader.instance().fireRemapEvent(ImmutableMap.of(), true);
LOGGER.debug(GD, "All registries frozen");
@ -249,7 +246,7 @@ public class GameData
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.resetDelegates());
LOGGER.debug(GD, "Reverting to frozen data state.");
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends ForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
{
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(r.getKey());
loadRegistry(r.getKey(), RegistryManager.FROZEN, RegistryManager.ACTIVE, clazz, true);
@ -291,6 +288,7 @@ public class GameData
{
@SuppressWarnings("unchecked")
ClearableObjectIntIdentityMap<IBlockState> blockstateMap = owner.getSlaveMap(BLOCKSTATE_TO_ID, ClearableObjectIntIdentityMap.class);
/*
if ("minecraft:tripwire".equals(block.getRegistryName().toString())) //Tripwire is crap so we have to special case whee!
{
@ -326,17 +324,19 @@ public class GameData
if (item != null)
blockToItem.forcePut(block, item);
}
*/
}
@Override
public void onClear(IForgeRegistryInternal<Block> owner, RegistryManager stage)
{
owner.getSlaveMap(BLOCKSTATE_TO_ID, ClearableObjectIntIdentityMap.class).clear();
// owner.getSlaveMap(BLOCKSTATE_TO_ID, ClearableObjectIntIdentityMap.class).clear();
}
@Override
public void onCreate(IForgeRegistryInternal<Block> owner, RegistryManager stage)
{
/*
final ClearableObjectIntIdentityMap<IBlockState> idMap = new ClearableObjectIntIdentityMap<IBlockState>()
{
@SuppressWarnings("deprecation")
@ -352,20 +352,28 @@ public class GameData
}
};
owner.setSlaveMap(BLOCKSTATE_TO_ID, idMap);
*/
owner.setSlaveMap(BLOCK_TO_ITEM, HashBiMap.create());
}
@Override
public Block createDummy(ResourceLocation key)
{
Block ret = new BlockDummyAir().setUnlocalizedName("air");
Block ret = new BlockDummyAir(Block.Builder.func_200945_a(Material.AIR));
GameData.forceRegistryName(ret, key);
return ret;
}
private static class BlockDummyAir extends BlockAir //A named class so DummyBlockReplacementTest can detect if its a dummy
{
private BlockDummyAir()
private BlockDummyAir(Block.Builder builder)
{
super(builder);
}
@Override
public String getTranslationKey()
{
return "block.minecraft.air";
}
}
}
@ -400,6 +408,7 @@ public class GameData
}
}
/*
private static class RecipeCallbacks implements IForgeRegistry.ValidateCallback<IRecipe>, IForgeRegistry.MissingFactory<IRecipe>
{
static final RecipeCallbacks INSTANCE = new RecipeCallbacks();
@ -465,6 +474,7 @@ public class GameData
EntityList.ENTITY_EGGS.put(entry.getRegistryName(), entry.getEgg());
}
}
*/
private static <T extends IForgeRegistryEntry<T>> void loadRegistry(final ResourceLocation registryName, final RegistryManager from, final RegistryManager to, final Class<T> regType, boolean freeze)
{
@ -618,6 +628,7 @@ public class GameData
if (!confirmed)
StartupQuery.abort();
/*
try
{
String skip = System.getProperty("fml.doNotBackup");
@ -636,6 +647,7 @@ public class GameData
StartupQuery.notify("The world backup couldn't be created.\n\n" + e);
StartupQuery.abort();
}
*/
}
if (!defaulted.isEmpty())
@ -670,7 +682,7 @@ public class GameData
STAGING.registries.forEach((name, reg) -> reg.validateContent(name));
// Load the STAGING registry into the ACTIVE registry
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
for (Map.Entry<ResourceLocation, IForgeRegistry<? extends ForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
{
final Class<? extends IForgeRegistryEntry> registrySuperType = RegistryManager.ACTIVE.getSuperType(r.getKey());
loadRegistry(r.getKey(), STAGING, RegistryManager.ACTIVE, registrySuperType, true);
@ -690,7 +702,7 @@ public class GameData
}
//Has to be split because of generics, Yay!
private static <T extends IForgeRegistryEntry<T>> void loadPersistentDataToStagingRegistry(RegistryManager pool, RegistryManager to, Map<ResourceLocation, Integer[]> remaps, Map<ResourceLocation, Integer> missing, ResourceLocation name, ForgeRegistry.Snapshot snap, Class<T> regType)
private static <T extends ForgeRegistryEntry<T>> void loadPersistentDataToStagingRegistry(RegistryManager pool, RegistryManager to, Map<ResourceLocation, Integer[]> remaps, Map<ResourceLocation, Integer> missing, ResourceLocation name, ForgeRegistry.Snapshot snap, Class<T> regType)
{
ForgeRegistry<T> active = pool.getRegistry(name);
if (active == null)
@ -705,7 +717,7 @@ public class GameData
//Another bouncer for generic reasons
@SuppressWarnings("unchecked")
private static <T extends IForgeRegistryEntry<T>> void processMissing(Class<T> clazz, ResourceLocation name, RegistryManager STAGING, MissingMappings<?> e, Map<ResourceLocation, Integer> missing, Map<ResourceLocation, Integer[]> remaps, Collection<ResourceLocation> defaulted, Collection<ResourceLocation> failed, boolean injectNetworkDummies)
private static <T extends ForgeRegistryEntry<T>> void processMissing(Class<T> clazz, ResourceLocation name, RegistryManager STAGING, MissingMappings<?> e, Map<ResourceLocation, Integer> missing, Map<ResourceLocation, Integer[]> remaps, Collection<ResourceLocation> defaulted, Collection<ResourceLocation> failed, boolean injectNetworkDummies)
{
List<MissingMappings.Mapping<T>> mappings = ((MissingMappings<T>)e).getAllMappings();
ForgeRegistry<T> active = RegistryManager.ACTIVE.getRegistry(name);
@ -713,7 +725,7 @@ public class GameData
staging.processMissingEvent(name, active, mappings, missing, remaps, defaulted, failed, injectNetworkDummies);
}
private static <T extends IForgeRegistryEntry<T>> void loadFrozenDataToStagingRegistry(RegistryManager STAGING, ResourceLocation name, Map<ResourceLocation, Integer[]> remaps, Class<T> clazz)
private static <T extends ForgeRegistryEntry<T>> void loadFrozenDataToStagingRegistry(RegistryManager STAGING, ResourceLocation name, Map<ResourceLocation, Integer[]> remaps, Class<T> clazz)
{
ForgeRegistry<T> frozen = RegistryManager.FROZEN.getRegistry(name);
ForgeRegistry<T> newRegistry = STAGING.getRegistry(name, RegistryManager.FROZEN);

View file

@ -34,7 +34,7 @@ import javax.annotation.Nullable;
*
* @param <V> The top level type for the registry
*/
public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterable<V>
public interface IForgeRegistry<V extends ForgeRegistryEntry<V>> extends Iterable<V>
{
Class<V> getRegistrySuperType();
@ -72,7 +72,7 @@ public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterab
* Callback fired when objects are added to the registry. This will fire when the registry is rebuilt
* on the client side from a server side synchronization, or when a world is loaded.
*/
interface AddCallback<V extends IForgeRegistryEntry<V>>
interface AddCallback<V extends ForgeRegistryEntry<V>>
{
void onAdd(IForgeRegistryInternal<V> owner, RegistryManager stage, int id, V obj, @Nullable V oldObj);
}
@ -81,7 +81,7 @@ public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterab
* Callback fired when the registry is cleared. This is done before a registry is reloaded from client
* or server.
*/
interface ClearCallback<V extends IForgeRegistryEntry<V>>
interface ClearCallback<V extends ForgeRegistryEntry<V>>
{
void onClear(IForgeRegistryInternal<V> owner, RegistryManager stage);
}
@ -89,7 +89,7 @@ public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterab
/**
* Callback fired when a registry instance is created. Populate slave maps here.
*/
interface CreateCallback<V extends IForgeRegistryEntry<V>>
interface CreateCallback<V extends ForgeRegistryEntry<V>>
{
void onCreate(IForgeRegistryInternal<V> owner, RegistryManager stage);
}
@ -105,7 +105,7 @@ public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterab
/**
* Factory for creating dummy entries, allowing worlds to be loaded and keep the missing block references.
*/
interface DummyFactory<V extends IForgeRegistryEntry<V>>
interface DummyFactory<V extends ForgeRegistryEntry<V>>
{
V createDummy(ResourceLocation key);
}
@ -113,7 +113,7 @@ public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterab
/**
*
*/
interface MissingFactory<V extends IForgeRegistryEntry<V>>
interface MissingFactory<V extends ForgeRegistryEntry<V>>
{
V createMissing(ResourceLocation key, boolean isNetwork);
}

View file

@ -41,7 +41,7 @@ public interface IForgeRegistryEntry<V>
*
* @param name Unique registry name
* @return This instance
*/
* /
V setRegistryName(ResourceLocation name);
/**
@ -50,7 +50,7 @@ public interface IForgeRegistryEntry<V>
* If neither are valid null is returned.
*
* @return Unique identifier or null.
*/
* /
@Nullable
ResourceLocation getRegistryName();
@ -89,4 +89,5 @@ public interface IForgeRegistryEntry<V>
@Override
public final Class<T> getRegistryType() { return (Class<T>) token.getRawType(); };
}
*/
}

View file

@ -21,7 +21,7 @@ package net.minecraftforge.registries;
import net.minecraft.util.ResourceLocation;
public interface IForgeRegistryInternal<V extends IForgeRegistryEntry<V>> extends IForgeRegistry<V>
public interface IForgeRegistryInternal<V extends ForgeRegistryEntry<V>> extends IForgeRegistry<V>
{
void setSlaveMap(ResourceLocation name, Object obj);
}

View file

@ -21,7 +21,7 @@ package net.minecraftforge.registries;
import net.minecraft.util.ResourceLocation;
public interface IForgeRegistryModifiable<V extends IForgeRegistryEntry<V>> extends IForgeRegistry<V>
public interface IForgeRegistryModifiable<V extends ForgeRegistryEntry<V>> extends IForgeRegistry<V>
{
void clear();
V remove(ResourceLocation key);

View file

@ -21,8 +21,6 @@ package net.minecraftforge.registries;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
@ -30,14 +28,14 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.Validate;
import com.google.common.collect.Maps;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey;
import net.minecraftforge.fml.common.FMLLog;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamespacedDefaultedByKey<ResourceLocation, V> implements ILockableRegistry
class NamespacedDefaultedWrapper<V extends ForgeRegistryEntry<V>> extends RegistryNamespacedDefaultedByKey<ResourceLocation, V> implements ILockableRegistry
{
private static final Logger LOGGER = LogManager.getLogger();
private boolean locked = false;
private ForgeRegistry<V> delegate;
@ -59,7 +57,7 @@ class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends Regis
int realId = this.delegate.add(id, value);
if (realId != id && id != -1)
FMLLog.log.warn("Registered object did not get ID it asked for. Name: {} Type: {} Expected: {} Got: {}", key, value.getRegistryType().getName(), id, realId);
LOGGER.warn("Registered object did not get ID it asked for. Name: {} Type: {} Expected: {} Got: {}", key, value.getRegistryType().getName(), id, realId);
}
@Override
@ -132,7 +130,7 @@ class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends Regis
@Override
public void lock(){ this.locked = true; }
public static class Factory<V extends IForgeRegistryEntry<V>> implements IForgeRegistry.CreateCallback<V>
public static class Factory<V extends ForgeRegistryEntry<V>> implements IForgeRegistry.CreateCallback<V>
{
public static final ResourceLocation ID = new ResourceLocation("forge", "registry_defaulted_wrapper");
@Override

View file

@ -19,11 +19,8 @@
package net.minecraftforge.registries;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
@ -33,10 +30,12 @@ import org.apache.commons.lang3.Validate;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraftforge.fml.common.FMLLog;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
class NamespacedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamespaced<ResourceLocation, V> implements ILockableRegistry
class NamespacedWrapper<V extends ForgeRegistryEntry<V>> extends RegistryNamespaced<ResourceLocation, V> implements ILockableRegistry
{
private static final Logger LOGGER = LogManager.getLogger();
private boolean locked = false;
private ForgeRegistry<V> delegate;
@ -58,7 +57,7 @@ class NamespacedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamesp
int realId = this.delegate.add(id, value);
if (realId != id && id != -1)
FMLLog.log.warn("Registered object did not get ID it asked for. Name: {} Type: {} Expected: {} Got: {}", key, value.getRegistryType().getName(), id, realId);
LOGGER.warn("Registered object did not get ID it asked for. Name: {} Type: {} Expected: {} Got: {}", key, value.getRegistryType().getName(), id, realId);
}
@Override
@ -126,7 +125,7 @@ class NamespacedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamesp
@Override
public void lock(){ this.locked = true; }
public static class Factory<V extends IForgeRegistryEntry<V>> implements IForgeRegistry.CreateCallback<V>
public static class Factory<V extends ForgeRegistryEntry<V>> implements IForgeRegistry.CreateCallback<V>
{
public static final ResourceLocation ID = new ResourceLocation("forge", "registry_defaulted_wrapper");
@Override

View file

@ -66,7 +66,7 @@ class ObjectHolderRef
}
else
{
this.injectedObject = ((IForgeRegistryEntry)existing).getRegistryName();
this.injectedObject = ((ForgeRegistryEntry)existing).getRegistryName();
}
}
catch (IllegalAccessException e)
@ -105,9 +105,9 @@ class ObjectHolderRef
{
Class<?> type = typesToExamine.remove();
Collections.addAll(typesToExamine, type.getInterfaces());
if (IForgeRegistryEntry.class.isAssignableFrom(type))
if (ForgeRegistryEntry.class.isAssignableFrom(type))
{
registry = (ForgeRegistry<?>)RegistryManager.ACTIVE.getRegistry((Class<IForgeRegistryEntry>)type);
registry = (ForgeRegistry<?>)RegistryManager.ACTIVE.getRegistry((Class<ForgeRegistryEntry>)type);
final Class<?> parentType = type.getSuperclass();
if (parentType != null)
{

View file

@ -28,7 +28,7 @@ import net.minecraftforge.registries.IForgeRegistry.*;
import javax.annotation.Nullable;
public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
public class RegistryBuilder<T extends ForgeRegistryEntry<T>>
{
private ResourceLocation registryName;
private Class<T> registryType;

View file

@ -31,18 +31,20 @@ import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.registries.ForgeRegistry.Snapshot;
import net.minecraftforge.registries.IForgeRegistry.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class RegistryManager
{
private static final Logger LOGGER = LogManager.getLogger();
public static final RegistryManager ACTIVE = new RegistryManager("ACTIVE");
public static final RegistryManager VANILLA = new RegistryManager("VANILLA");
public static final RegistryManager FROZEN = new RegistryManager("FROZEN");
BiMap<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> registries = HashBiMap.create();
private BiMap<Class<? extends IForgeRegistryEntry<?>>, ResourceLocation> superTypes = HashBiMap.create();
private BiMap<Class<? extends ForgeRegistryEntry<?>>, ResourceLocation> superTypes = HashBiMap.create();
private Set<ResourceLocation> persisted = Sets.newHashSet();
private final String name;
@ -103,7 +105,7 @@ public class RegistryManager
if (!overlappedTypes.isEmpty())
{
Class<?> foundType = overlappedTypes.iterator().next();
FMLLog.log.error("Found existing registry of type {} named {}, you cannot create a new registry ({}) with type {}, as {} has a parent of that type", foundType, superTypes.get(foundType), name, type, type);
LOGGER.error("Found existing registry of type {} named {}, you cannot create a new registry ({}) with type {}, as {} has a parent of that type", foundType, superTypes.get(foundType), name, type, type);
throw new IllegalArgumentException("Duplicate registry parent type found - you can only have one registry for a particular super type");
}
ForgeRegistry<V> reg = new ForgeRegistry<V>(type, defaultKey, min, max, create, add, clear, validate, this, allowOverrides, isModifiable, dummyFactory, missing);