Skip to content

Instantly share code, notes, and snippets.

@LexManos
Created September 17, 2016 01:31
Show Gist options
  • Save LexManos/723aa54f59af2968bdaaef56f090895d to your computer and use it in GitHub Desktop.
Save LexManos/723aa54f59af2968bdaaef56f090895d to your computer and use it in GitHub Desktop.
RetroGen Draft
diff --git a/patches/minecraft/net/minecraft/item/Item.java.patch b/patches/minecraft/net/minecraft/item/Item.java.patch
index 5496a45..ced5c8a 100644
--- a/patches/minecraft/net/minecraft/item/Item.java.patch
+++ b/patches/minecraft/net/minecraft/item/Item.java.patch
@@ -52,7 +52,7 @@
return p_77621_1_.func_147447_a(vec3d, vec3d1, p_77621_3_, !p_77621_3_, false);
}
-@@ -426,11 +432,569 @@
+@@ -426,11 +432,580 @@
return false;
}
diff --git a/patches/minecraft/net/minecraft/world/WorldServer.java.patch b/patches/minecraft/net/minecraft/world/WorldServer.java.patch
index cc3e323..42f7101 100644
--- a/patches/minecraft/net/minecraft/world/WorldServer.java.patch
+++ b/patches/minecraft/net/minecraft/world/WorldServer.java.patch
@@ -1,12 +1,13 @@
--- ../src-base/minecraft/net/minecraft/world/WorldServer.java
+++ ../src-work/minecraft/net/minecraft/world/WorldServer.java
-@@ -98,30 +98,39 @@
+@@ -98,30 +98,40 @@
private int field_147489_T;
private final List<NextTickListEntry> field_94579_S = Lists.<NextTickListEntry>newArrayList();
+ /** Stores the recently processed (lighting) chunks */
+ protected Set<ChunkPos> doneChunks = new java.util.HashSet<ChunkPos>();
+ public List<Teleporter> customTeleporters = new ArrayList<Teleporter>();
++ public com.google.common.collect.ArrayListMultimap<ChunkPos, net.minecraft.util.ResourceLocation> pendingRetroGens = com.google.common.collect.ArrayListMultimap.create();
+
public WorldServer(MinecraftServer p_i45921_1_, ISaveHandler p_i45921_2_, WorldInfo p_i45921_3_, int p_i45921_4_, Profiler p_i45921_5_)
{
@@ -43,7 +44,7 @@
}
else
{
-@@ -156,6 +165,7 @@
+@@ -156,6 +166,7 @@
this.func_175723_af().func_177750_a(this.field_72986_A.func_176137_E());
}
@@ -51,7 +52,7 @@
return this;
}
-@@ -215,6 +225,10 @@
+@@ -215,20 +226,28 @@
this.field_175740_d.func_75528_a();
this.field_72984_F.func_76318_c("portalForcer");
this.field_85177_Q.func_85189_a(this.func_82737_E());
@@ -61,8 +62,11 @@
+ }
this.field_72984_F.func_76319_b();
this.func_147488_Z();
++
++ net.minecraftforge.common.ForgeHooks.doRetrogenTick(this);
}
-@@ -223,12 +237,14 @@
+
+ @Nullable
public Biome.SpawnListEntry func_175734_a(EnumCreatureType p_175734_1_, BlockPos p_175734_2_)
{
List<Biome.SpawnListEntry> list = this.func_72863_F().func_177458_a(p_175734_1_, p_175734_2_);
@@ -77,7 +81,7 @@
return list != null && !list.isEmpty() ? list.contains(p_175732_2_) : false;
}
-@@ -274,10 +290,7 @@
+@@ -274,10 +293,7 @@
private void func_73051_P()
{
@@ -89,7 +93,7 @@
}
public boolean func_73056_e()
-@@ -370,7 +383,7 @@
+@@ -370,7 +386,7 @@
boolean flag1 = this.func_72911_I();
this.field_72984_F.func_76320_a("pollingChunks");
@@ -98,7 +102,7 @@
{
this.field_72984_F.func_76320_a("getChunk");
Chunk chunk = (Chunk)iterator.next();
-@@ -382,7 +395,7 @@
+@@ -382,7 +398,7 @@
chunk.func_150804_b(false);
this.field_72984_F.func_76318_c("thunder");
@@ -107,7 +111,7 @@
{
this.field_73005_l = this.field_73005_l * 3 + 1013904223;
int l = this.field_73005_l >> 2;
-@@ -411,7 +424,7 @@
+@@ -411,7 +427,7 @@
this.field_72984_F.func_76318_c("iceandsnow");
@@ -116,7 +120,7 @@
{
this.field_73005_l = this.field_73005_l * 3 + 1013904223;
int j2 = this.field_73005_l >> 2;
-@@ -527,7 +540,10 @@
+@@ -527,7 +543,10 @@
{
if (p_175654_2_.func_149698_L())
{
@@ -128,7 +132,7 @@
{
IBlockState iblockstate = this.func_180495_p(p_175654_1_);
-@@ -587,7 +603,7 @@
+@@ -587,7 +606,7 @@
public void func_72939_s()
{
@@ -137,7 +141,7 @@
{
if (this.field_80004_Q++ >= 300)
{
-@@ -711,6 +727,9 @@
+@@ -711,6 +730,9 @@
{
NextTickListEntry nextticklistentry1 = (NextTickListEntry)iterator.next();
iterator.remove();
@@ -147,7 +151,7 @@
int k = 0;
if (this.func_175707_a(nextticklistentry1.field_180282_a.func_177982_a(0, 0, 0), nextticklistentry1.field_180282_a.func_177982_a(0, 0, 0)))
-@@ -837,6 +856,10 @@
+@@ -837,6 +859,10 @@
public boolean func_175660_a(EntityPlayer p_175660_1_, BlockPos p_175660_2_)
{
@@ -158,7 +162,7 @@
return !this.field_73061_a.func_175579_a(this, p_175660_2_, p_175660_1_) && this.func_175723_af().func_177746_a(p_175660_2_);
}
-@@ -902,6 +925,7 @@
+@@ -902,6 +928,7 @@
}
else
{
@@ -166,7 +170,7 @@
this.field_72987_B = true;
BiomeProvider biomeprovider = this.field_73011_w.func_177499_m();
List<Biome> list = biomeprovider.func_76932_a();
-@@ -986,6 +1010,7 @@
+@@ -986,6 +1013,7 @@
}
chunkproviderserver.func_186027_a(p_73044_1_);
@@ -174,7 +178,7 @@
for (Chunk chunk : Lists.newArrayList(chunkproviderserver.func_189548_a()))
{
-@@ -1030,6 +1055,7 @@
+@@ -1030,6 +1058,7 @@
this.field_72986_A.func_176135_e(this.func_175723_af().func_177732_i());
this.field_73019_z.func_75755_a(this.field_72986_A, this.field_73061_a.func_184103_al().func_72378_q());
this.field_72988_C.func_75744_a();
@@ -182,7 +186,7 @@
}
public boolean func_72838_d(Entity p_72838_1_)
-@@ -1041,7 +1067,7 @@
+@@ -1041,7 +1070,7 @@
{
for (Entity entity : Lists.newArrayList(p_175650_1_))
{
@@ -191,7 +195,7 @@
{
this.field_72996_f.add(entity);
this.func_72923_a(entity);
-@@ -1122,7 +1148,7 @@
+@@ -1122,7 +1151,7 @@
{
if (super.func_72942_c(p_72942_1_))
{
@@ -200,7 +204,7 @@
return true;
}
else
-@@ -1144,6 +1170,7 @@
+@@ -1144,6 +1173,7 @@
public Explosion func_72885_a(@Nullable Entity p_72885_1_, double p_72885_2_, double p_72885_4_, double p_72885_6_, float p_72885_8_, boolean p_72885_9_, boolean p_72885_10_)
{
Explosion explosion = new Explosion(this, p_72885_1_, p_72885_2_, p_72885_4_, p_72885_6_, p_72885_8_, p_72885_9_, p_72885_10_);
@@ -208,7 +212,7 @@
explosion.func_77278_a();
explosion.func_77279_a(false);
-@@ -1189,7 +1216,7 @@
+@@ -1189,7 +1219,7 @@
{
if (this.func_147485_a(blockeventdata))
{
@@ -217,7 +221,7 @@
}
}
-@@ -1215,27 +1242,31 @@
+@@ -1215,27 +1245,31 @@
if (this.field_73003_n != this.field_73004_o)
{
@@ -255,7 +259,7 @@
}
}
-@@ -1314,6 +1345,11 @@
+@@ -1314,6 +1348,11 @@
return this.field_73061_a.func_152345_ab();
}
diff --git a/patches/minecraft/net/minecraft/world/chunk/Chunk.java.patch b/patches/minecraft/net/minecraft/world/chunk/Chunk.java.patch
index 5137f4b..4221144 100644
--- a/patches/minecraft/net/minecraft/world/chunk/Chunk.java.patch
+++ b/patches/minecraft/net/minecraft/world/chunk/Chunk.java.patch
@@ -1,6 +1,24 @@
--- ../src-base/minecraft/net/minecraft/world/chunk/Chunk.java
+++ ../src-work/minecraft/net/minecraft/world/chunk/Chunk.java
-@@ -178,7 +178,7 @@
+@@ -3,6 +3,7 @@
+ import com.google.common.base.Predicate;
+ import com.google.common.collect.Maps;
+ import com.google.common.collect.Queues;
++
+ import java.util.Arrays;
+ import java.util.List;
+ import java.util.Map;
+@@ -68,6 +69,9 @@
+ private ConcurrentLinkedQueue<BlockPos> field_177447_w;
+ public boolean field_189550_d;
+
++ @Deprecated //Modders, Do not use, Forge use only.
++ public java.util.Set<net.minecraft.util.ResourceLocation> ranGens = com.google.common.collect.Sets.newHashSet();
++
+ public Chunk(World p_i1995_1_, int p_i1995_2_, int p_i1995_3_)
+ {
+ this.field_76652_q = new ExtendedBlockStorage[16];
+@@ -178,7 +182,7 @@
{
IBlockState iblockstate = this.func_186032_a(j, l - 1, k);
@@ -9,7 +27,7 @@
{
this.field_76634_f[k << 4 | j] = l;
-@@ -451,12 +451,13 @@
+@@ -451,12 +455,13 @@
public int func_177437_b(BlockPos p_177437_1_)
{
@@ -25,7 +43,7 @@
}
public IBlockState func_177435_g(BlockPos p_177435_1_)
-@@ -538,6 +539,7 @@
+@@ -538,6 +543,7 @@
{
Block block = p_177436_2_.func_177230_c();
Block block1 = iblockstate.func_177230_c();
@@ -33,7 +51,7 @@
ExtendedBlockStorage extendedblockstorage = this.field_76652_q[j >> 4];
boolean flag = false;
-@@ -555,14 +557,19 @@
+@@ -555,14 +561,19 @@
extendedblockstorage.func_177484_a(i, j & 15, k, p_177436_2_);
@@ -55,7 +73,7 @@
this.field_76637_e.func_175713_t(p_177436_1_);
}
}
-@@ -579,8 +586,7 @@
+@@ -579,8 +590,7 @@
}
else
{
@@ -65,7 +83,7 @@
if (j1 > 0)
{
-@@ -600,28 +606,19 @@
+@@ -600,28 +610,19 @@
}
}
@@ -98,7 +116,7 @@
this.field_76637_e.func_175690_a(p_177436_1_, tileentity1);
}
-@@ -725,6 +722,7 @@
+@@ -725,6 +726,7 @@
k = this.field_76645_j.length - 1;
}
@@ -106,7 +124,7 @@
p_76612_1_.field_70175_ag = true;
p_76612_1_.field_70176_ah = this.field_76635_g;
p_76612_1_.field_70162_ai = k;
-@@ -765,7 +763,7 @@
+@@ -765,7 +767,7 @@
{
IBlockState iblockstate = this.func_177435_g(p_177422_1_);
Block block = iblockstate.func_177230_c();
@@ -115,7 +133,7 @@
}
@Nullable
-@@ -773,6 +771,12 @@
+@@ -773,6 +775,12 @@
{
TileEntity tileentity = (TileEntity)this.field_150816_i.get(p_177424_1_);
@@ -128,7 +146,7 @@
if (tileentity == null)
{
if (p_177424_2_ == Chunk.EnumCreateEntityType.IMMEDIATE)
-@@ -782,14 +786,9 @@
+@@ -782,14 +790,9 @@
}
else if (p_177424_2_ == Chunk.EnumCreateEntityType.QUEUED)
{
@@ -144,7 +162,7 @@
return tileentity;
}
-@@ -806,10 +805,11 @@
+@@ -806,10 +809,11 @@
public void func_177426_a(BlockPos p_177426_1_, TileEntity p_177426_2_)
{
@@ -157,7 +175,7 @@
{
if (this.field_150816_i.containsKey(p_177426_1_))
{
-@@ -818,6 +818,7 @@
+@@ -818,6 +822,7 @@
p_177426_2_.func_145829_t();
this.field_150816_i.put(p_177426_1_, p_177426_2_);
@@ -165,7 +183,7 @@
}
}
-@@ -841,8 +842,9 @@
+@@ -841,8 +846,9 @@
for (ClassInheritanceMultiMap<Entity> classinheritancemultimap : this.field_76645_j)
{
@@ -176,7 +194,7 @@
}
public void func_76623_d()
-@@ -858,6 +860,7 @@
+@@ -858,6 +864,7 @@
{
this.field_76637_e.func_175681_c(classinheritancemultimap);
}
@@ -184,7 +202,7 @@
}
public void func_76630_e()
-@@ -867,8 +870,8 @@
+@@ -867,8 +874,8 @@
public void func_177414_a(@Nullable Entity p_177414_1_, AxisAlignedBB p_177414_2_, List<Entity> p_177414_3_, Predicate <? super Entity > p_177414_4_)
{
@@ -195,7 +213,7 @@
i = MathHelper.func_76125_a(i, 0, this.field_76645_j.length - 1);
j = MathHelper.func_76125_a(j, 0, this.field_76645_j.length - 1);
-@@ -905,8 +908,8 @@
+@@ -905,8 +912,8 @@
public <T extends Entity> void func_177430_a(Class <? extends T > p_177430_1_, AxisAlignedBB p_177430_2_, List<T> p_177430_3_, Predicate <? super T > p_177430_4_)
{
@@ -206,7 +224,7 @@
i = MathHelper.func_76125_a(i, 0, this.field_76645_j.length - 1);
j = MathHelper.func_76125_a(j, 0, this.field_76645_j.length - 1);
-@@ -995,6 +998,7 @@
+@@ -995,6 +1002,7 @@
{
this.func_150809_p();
p_186034_1_.func_185931_b(this.field_76635_g, this.field_76647_h);
@@ -214,7 +232,7 @@
this.func_76630_e();
}
}
-@@ -1051,7 +1055,7 @@
+@@ -1051,7 +1059,7 @@
{
BlockPos blockpos = (BlockPos)this.field_177447_w.poll();
@@ -223,7 +241,7 @@
{
TileEntity tileentity = this.func_177422_i(blockpos);
this.field_76637_e.func_175690_a(blockpos, tileentity);
-@@ -1115,6 +1119,13 @@
+@@ -1115,6 +1123,13 @@
@SideOnly(Side.CLIENT)
public void func_186033_a(PacketBuffer p_186033_1_, int p_186033_2_, boolean p_186033_3_)
{
@@ -237,7 +255,7 @@
boolean flag = !this.field_76637_e.field_73011_w.func_177495_o();
for (int i = 0; i < this.field_76652_q.length; ++i)
-@@ -1163,10 +1174,16 @@
+@@ -1163,10 +1178,16 @@
this.field_76646_k = true;
this.func_76590_a();
@@ -254,7 +272,7 @@
}
public Biome func_177411_a(BlockPos p_177411_1_, BiomeProvider p_177411_2_)
-@@ -1231,13 +1248,13 @@
+@@ -1231,13 +1252,13 @@
BlockPos blockpos1 = blockpos.func_177982_a(k, (j << 4) + i1, l);
boolean flag = i1 == 0 || i1 == 15 || k == 0 || k == 15 || l == 0 || l == 15;
@@ -270,7 +288,7 @@
{
this.field_76637_e.func_175664_x(blockpos2);
}
-@@ -1368,7 +1385,7 @@
+@@ -1368,7 +1389,7 @@
{
blockpos$mutableblockpos.func_181079_c(blockpos$mutableblockpos.func_177958_n(), l, blockpos$mutableblockpos.func_177952_p());
@@ -279,7 +297,7 @@
{
this.field_76637_e.func_175664_x(blockpos$mutableblockpos);
}
-@@ -1476,4 +1493,20 @@
+@@ -1476,4 +1497,20 @@
QUEUED,
CHECK;
}
diff --git a/src/main/java/net/minecraftforge/client/gui/ForgeGuiFactory.java b/src/main/java/net/minecraftforge/client/gui/ForgeGuiFactory.java
index ba71f46..70fa85c 100644
--- a/src/main/java/net/minecraftforge/client/gui/ForgeGuiFactory.java
+++ b/src/main/java/net/minecraftforge/client/gui/ForgeGuiFactory.java
@@ -126,6 +126,8 @@ public class ForgeGuiFactory implements IModGuiFactory
list.add(new DummyCategoryElement("forgeClientCfg", "forge.configgui.ctgy.forgeClientConfig", ClientEntry.class));
list.add(new DummyCategoryElement("forgeChunkLoadingCfg", "forge.configgui.ctgy.forgeChunkLoadingConfig", ChunkLoaderEntry.class));
list.add(new DummyCategoryElement("forgeVersionCheckCfg", "forge.configgui.ctgy.VersionCheckConfig", VersionCheckEntry.class));
+ list.add(new DummyCategoryElement("forgeRetroGenCfg", "forge.configgui.ctgy.RetroGenConfig",
+ new ConfigElement(ForgeModContainer.getConfig().getCategory(ForgeModContainer.RETROGEN_CAT)).getChildElements()));
return list;
}
diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java
index 11c336f..be2a5c6 100644
--- a/src/main/java/net/minecraftforge/common/ForgeHooks.java
+++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java
@@ -25,12 +25,15 @@ import java.util.ArrayList;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
+import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Queues;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
@@ -81,6 +84,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.WeightedRandom;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
@@ -90,7 +94,10 @@ import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
+import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
+import net.minecraft.world.chunk.Chunk;
+import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.GameType;
import net.minecraft.world.storage.loot.LootEntry;
import net.minecraft.world.storage.loot.LootTable;
@@ -119,7 +126,9 @@ import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.NoteBlockEvent;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fml.common.FMLLog;
+import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraftforge.fml.common.eventhandler.Event;
+import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
public class ForgeHooks
@@ -1147,4 +1156,34 @@ public class ForgeHooks
{
return MinecraftForge.EVENT_BUS.post(new ThrowableImpactEvent(throwable, ray));
}
+
+ public static void doRetrogenTick(WorldServer world)
+ {
+ long worldSeed = world.getSeed();
+ ChunkProviderServer providerServer = world.getChunkProvider();
+
+ Iterable<Entry<ChunkPos, ResourceLocation>> pending = ImmutableList.copyOf(Iterables.limit(world.pendingRetroGens.entries(), ForgeModContainer.retrogenMax));
+ for (Entry<ChunkPos, ResourceLocation> e : pending)
+ {
+ int chunkX = e.getKey().chunkXPos;
+ int chunkZ = e.getKey().chunkZPos;
+ Chunk c = world.getChunkFromChunkCoords(chunkX, chunkZ);
+ ResourceLocation name = e.getValue();
+ IWorldGenerator gen = GameRegistry.getGenerator(name);
+ if (gen == null)
+ continue;
+
+ Random rand = new Random(worldSeed);
+ long xSeed = rand.nextLong() >> 2 + 1L;
+ long zSeed = rand.nextLong() >> 2 + 1L;
+ long chunkSeed = (xSeed * chunkX + zSeed * chunkZ) ^ worldSeed;
+ rand.setSeed(chunkSeed);
+
+ gen.generate(rand, chunkX, chunkZ, world, providerServer.chunkGenerator, providerServer);
+ FMLLog.fine("Retrogenerated chunk at (%d, %d) for %s", chunkX, chunkZ, name);
+
+ c.ranGens.add(name);
+ world.pendingRetroGens.remove(e.getKey(), e.getValue());
+ }
+ }
}
diff --git a/src/main/java/net/minecraftforge/common/ForgeInternalHandler.java b/src/main/java/net/minecraftforge/common/ForgeInternalHandler.java
index 88e29bf..32e77db 100644
--- a/src/main/java/net/minecraftforge/common/ForgeInternalHandler.java
+++ b/src/main/java/net/minecraftforge/common/ForgeInternalHandler.java
@@ -19,17 +19,28 @@
package net.minecraftforge.common;
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.nbt.NBTTagString;
+import net.minecraft.util.ResourceLocation;
import net.minecraft.world.WorldServer;
+import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
+import net.minecraftforge.event.world.ChunkDataEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.registry.GameRegistry;
public class ForgeInternalHandler
{
@@ -86,7 +97,7 @@ public class ForgeInternalHandler
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onDimensionSave(WorldEvent.Save event)
{
- ForgeChunkManager.saveWorld(event.getWorld());
+ ForgeChunkManager.saveWorld(event.getWorld());
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
@@ -96,4 +107,47 @@ public class ForgeInternalHandler
if (event.getWorld() instanceof WorldServer)
FakePlayerFactory.unloadWorld((WorldServer) event.getWorld());
}
+
+ @SuppressWarnings("deprecation")
+ @SubscribeEvent(priority = EventPriority.HIGHEST)
+ public void onChunkDataLoad(ChunkDataEvent.Load e)
+ {
+ Chunk c = e.getChunk();
+ NBTTagCompound nbt = e.getData();
+ if (!nbt.hasKey("ForgeData") || !nbt.getCompoundTag("ForgeData").hasKey("RetroGen"))
+ return;
+ nbt = nbt.getCompoundTag("ForgeData").getCompoundTag("RetroGen");
+ for (String key : nbt.getKeySet())
+ {
+ NBTTagList list = nbt.getTagList(key, 8);
+ for (int x = 0; x < list.tagCount(); x++)
+ c.ranGens.add(new ResourceLocation(key, list.getStringTagAt(x)));
+ }
+
+ if (ForgeModContainer.retrogenEnable)
+ {
+ Set<ResourceLocation> names = Sets.newHashSet(GameRegistry.getGeneratorNames());
+ names.removeAll(c.ranGens);
+ for (ResourceLocation name : names)
+ ((WorldServer)e.getWorld()).pendingRetroGens.put(c.getChunkCoordIntPair(), name);
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ @SubscribeEvent(priority = EventPriority.HIGHEST)
+ public void onChunkDataSave(ChunkDataEvent.Save e)
+ {
+ Chunk c = e.getChunk();
+ NBTTagCompound forge = e.getData().getCompoundTag("ForgeData");
+ e.getData().setTag("ForgeData", forge);
+
+ NBTTagCompound retro = new NBTTagCompound();
+ for (ResourceLocation res : c.ranGens) //TODO? Sort this to lessen the NBT hashmap lookups?
+ {
+ NBTTagList list = retro.getTagList(res.getResourceDomain(), 8);
+ list.appendTag(new NBTTagString(res.getResourcePath()));
+ retro.setTag(res.getResourceDomain(), list);
+ }
+ forge.setTag("RetroGen", retro);
+ }
}
diff --git a/src/main/java/net/minecraftforge/common/ForgeModContainer.java b/src/main/java/net/minecraftforge/common/ForgeModContainer.java
index 10ac6bd..7960944 100644
--- a/src/main/java/net/minecraftforge/common/ForgeModContainer.java
+++ b/src/main/java/net/minecraftforge/common/ForgeModContainer.java
@@ -95,6 +95,7 @@ import net.minecraftforge.fml.common.network.NetworkRegistry;
public class ForgeModContainer extends DummyModContainer implements WorldAccessContainer
{
public static final String VERSION_CHECK_CAT = "version_checking";
+ public static final String RETROGEN_CAT = "retrogen";
public static int clumpingThreshold = 64;
public static boolean removeErroringEntities = false;
public static boolean removeErroringTileEntities = false;
@@ -108,6 +109,8 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
public static boolean replaceVanillaBucketModel = true;
public static long java8Reminder = 0;
public static boolean disableStairSlabCulling = false; // Also known as the "DontCullStairsBecauseIUseACrappyTexturePackThatBreaksBasicBlockShapesSoICantTrustBasicBlockCulling" flag
+ public static boolean retrogenEnable = false;
+ public static int retrogenMax = 100;
private static Configuration config;
private static ForgeModContainer INSTANCE;
@@ -265,10 +268,23 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
forgeLightPipelineEnabled = prop.getBoolean(Boolean.TRUE);
prop.setLanguageKey("forge.configgui.forgeLightPipelineEnabled");
propOrder.add(prop.getName());
-
config.setCategoryPropertyOrder(CATEGORY_GENERAL, propOrder);
propOrder = new ArrayList<String>();
+ prop = config.get(RETROGEN_CAT, "enable", Boolean.FALSE,
+ "Enable the ability for mod world generation to be run on chunks that have already generated.");
+ retrogenEnable = prop.getBoolean(Boolean.FALSE);
+ prop.setLanguageKey("forge.configgui.retro.enable");
+ propOrder.add(prop.getName());
+
+ prop = config.get(RETROGEN_CAT, "maxPerTick", 100, "Maximum number of generators to run per tick.");
+ retrogenMax = prop.getInt(100);
+ prop.setLanguageKey("forge.configgui.retro.max");
+ propOrder.add(prop.getName());
+
+ config.setCategoryPropertyOrder(RETROGEN_CAT, propOrder);
+
+ propOrder = new ArrayList<String>();
prop = config.get(VERSION_CHECK_CAT, "Global", true, "Enable the entire mod update check system. This only applies to mods using the Forge system.");
propOrder.add("Global");
@@ -329,7 +345,8 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
ForgeChunkManager.syncConfigDefaults();
ForgeChunkManager.loadConfiguration();
}
- else if (VERSION_CHECK_CAT.equals(event.getConfigID()))
+ else if (VERSION_CHECK_CAT.equals(event.getConfigID()) ||
+ RETROGEN_CAT.equals(event.getConfigID()))
{
syncConfig(false);
}
@@ -417,7 +434,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
{
universalBucket = new UniversalBucket();
universalBucket.setUnlocalizedName("forge.bucketFilled");
- GameRegistry.registerItem(universalBucket, "bucketFilled");
+ GameRegistry.register(universalBucket.setRegistryName("bucketFilled"));
MinecraftForge.EVENT_BUS.register(universalBucket);
}
}
diff --git a/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java
index 69bbe32..60acaba 100644
--- a/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java
+++ b/src/main/java/net/minecraftforge/fml/common/registry/GameRegistry.java
@@ -46,14 +46,19 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
+import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider;
+import net.minecraftforge.fml.common.FMLCommonHandler;
+import net.minecraftforge.fml.common.FMLContainer;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.IFuelHandler;
import net.minecraftforge.fml.common.IWorldGenerator;
+import net.minecraftforge.fml.common.InjectedModContainer;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.LoaderException;
import net.minecraftforge.fml.common.LoaderState;
+import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import org.apache.logging.log4j.Level;
@@ -70,22 +75,26 @@ import com.google.common.primitives.Ints;
@SuppressWarnings({"WeakerAccess", "unused"})
public class GameRegistry
{
- private static Set<IWorldGenerator> worldGenerators = Sets.newHashSet();
- private static Map<IWorldGenerator, Integer> worldGeneratorIndex = Maps.newHashMap();
+ private static Map<ResourceLocation, WorldGenHolder> worldGenerators = Maps.newHashMap();
+ private static List<WorldGenHolder> sortedGeneratorList;
private static List<IFuelHandler> fuelHandlers = Lists.newArrayList();
- private static List<IWorldGenerator> sortedGeneratorList;
/**
* Register a world generator - something that inserts new block types into the world
*
+ * @param name The name to be used as a marker in the chunk file,
+ * This name is necessary for the 'RetroGen' feature, generators that have not
+ * be run on chunks loaded from disc will be queue to be run.
* @param generator the generator
* @param modGenerationWeight a weight to assign to this generator. Heavy weights tend to sink to the bottom of
* list of world generators (i.e. they run later)
+ * @Deprecated Use Named before below.
*/
- public static void registerWorldGenerator(IWorldGenerator generator, int modGenerationWeight)
+ public static void registerWorldGenerator(ResourceLocation name, IWorldGenerator generator, int modGenerationWeight)
{
- worldGenerators.add(generator);
- worldGeneratorIndex.put(generator, modGenerationWeight);
+ if (worldGenerators.containsKey(name))
+ throw new IllegalStateException("Attempted to register a duplicate world generator: " + name);
+ worldGenerators.put(name, new WorldGenHolder(name, generator, modGenerationWeight));
if (sortedGeneratorList != null)
{
sortedGeneratorList = null;
@@ -113,23 +122,25 @@ public class GameRegistry
long xSeed = fmlRandom.nextLong() >> 2 + 1L;
long zSeed = fmlRandom.nextLong() >> 2 + 1L;
long chunkSeed = (xSeed * chunkX + zSeed * chunkZ) ^ worldSeed;
+ Chunk chunk = world.getChunkFromChunkCoords(chunkX, chunkX);
- for (IWorldGenerator generator : sortedGeneratorList)
+ for (WorldGenHolder holder : sortedGeneratorList)
{
fmlRandom.setSeed(chunkSeed);
- generator.generate(fmlRandom, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
+ holder.gen.generate(fmlRandom, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
+ chunk.ranGens.add(holder.name);
}
}
private static void computeSortedGeneratorList()
{
- ArrayList<IWorldGenerator> list = Lists.newArrayList(worldGenerators);
- Collections.sort(list, new Comparator<IWorldGenerator>()
+ ArrayList<WorldGenHolder> list = Lists.newArrayList(worldGenerators.values());
+ Collections.sort(list, new Comparator<WorldGenHolder>()
{
@Override
- public int compare(IWorldGenerator o1, IWorldGenerator o2)
+ public int compare(WorldGenHolder o1, WorldGenHolder o2)
{
- return Ints.compare(worldGeneratorIndex.get(o1), worldGeneratorIndex.get(o2));
+ return Ints.compare(o1.weight, o2.weight);
}
});
sortedGeneratorList = ImmutableList.copyOf(list);
@@ -403,9 +414,6 @@ public class GameRegistry
return is;
}
-
-
-
// ============================= DEPRECATED/INTERNAL MODDERS DO NOT USE =================================
/**
* Use {@link #register(IForgeRegistryEntry)} instead
@@ -531,4 +539,43 @@ public class GameRegistry
{
return GameData.findItem(modId, name);
}
+
+ /**
+ * Register a world generator - something that inserts new block types into the world
+ *
+ * @param generator the generator
+ * @param modGenerationWeight a weight to assign to this generator. Heavy weights tend to sink to the bottom of
+ * list of world generators (i.e. they run later)
+ * @Deprecated Use Named before below.
+ * TODO: Remove in 1.11
+ */
+ @Deprecated
+ public static void registerWorldGenerator(IWorldGenerator generator, int modGenerationWeight)
+ {
+ ModContainer mc = Loader.instance().activeModContainer();
+ String prefix = mc == null || (mc instanceof InjectedModContainer && ((InjectedModContainer)mc).wrappedContainer instanceof FMLContainer) ? "minecraft" : mc.getModId().toLowerCase();
+ registerWorldGenerator(new ResourceLocation(prefix, generator.getClass().getName()), generator, modGenerationWeight);
+ }
+
+ private static class WorldGenHolder
+ {
+ private ResourceLocation name;
+ private IWorldGenerator gen;
+ private int weight;
+ public WorldGenHolder(ResourceLocation name, IWorldGenerator gen, int weight)
+ {
+ this.name = name;
+ this.gen = gen;
+ this.weight = weight;
+ }
+ }
+
+ @Deprecated //Internal
+ public static Set<ResourceLocation> getGeneratorNames() { return worldGenerators.keySet(); }
+ @Deprecated //Internal
+ public static IWorldGenerator getGenerator(ResourceLocation name)
+ {
+ WorldGenHolder holder = worldGenerators.get(name);
+ return holder == null ? null : holder.gen;
+ }
}
diff --git a/src/main/resources/assets/forge/lang/en_US.lang b/src/main/resources/assets/forge/lang/en_US.lang
index 02c81a5..ab79434 100644
--- a/src/main/resources/assets/forge/lang/en_US.lang
+++ b/src/main/resources/assets/forge/lang/en_US.lang
@@ -22,6 +22,7 @@ forge.configgui.ctgy.forgeChunkLoadingModConfig=Mod Overrides
forge.configgui.ctgy.forgeChunkLoadingAddModConfig.tooltip=Allows you to define mod-specific settings that will override the defaults. A value of zero in either entry effectively disables any chunkloading capabilities for that mod.
forge.configgui.ctgy.forgeChunkLoadingAddModConfig=+ Add New Mod Override
forge.configgui.ctgy.VersionCheckConfig=Version Check Settings
+forge.configgui.ctgy.RetroGenConfig=RetroGen Settings
forge.configgui.biomeSkyBlendRange.tooltip=Control the range of sky blending for colored skies in biomes.
forge.configgui.biomeSkyBlendRange=Biome Sky Blend Range
@@ -50,6 +51,8 @@ forge.configgui.forgeLightPipelineEnabled=Forge Light Pipeline Enabled
forge.configgui.java8Reminder=Java 8 Reminder timestamp
forge.configgui.disableStairSlabCulling=Disable Stair/Slab culling.
forge.configgui.disableStairSlabCulling.tooltip=Enable this if you see through blocks touching stairs/slabs with your resource pack.
+forge.configgui.retro.enable=Enable
+forge.configgui.retro.max=Max tasks per tick
forge.configgui.modID.tooltip=The mod ID that you want to define override settings for.
forge.configgui.modID=Mod ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment