Skip to content

Commit

Permalink
More work on ShapeGen. Make sure saving calls actually reach it. More…
Browse files Browse the repository at this point in the history
… clean up. Tick only once per tick. Adjustment on terraformer wands.
  • Loading branch information
da3dsoul committed Nov 4, 2015
1 parent 50d5ac4 commit 1420250
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 150 deletions.
51 changes: 15 additions & 36 deletions src/main/java/abo/ABO.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import buildcraft.transport.PipeTransportFluids;
import buildcraft.transport.stripes.StripesHandlerRightClick;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import da3dsoul.ShapeGen.ShapeGen;
Expand All @@ -24,6 +24,7 @@
import da3dsoul.scaryGen.liquidXP.BlockLiquidXP;
import da3dsoul.scaryGen.liquidXP.WorldGenXPLake;
import da3dsoul.scaryGen.projectile.EntityThrownBottle;
import micdoodle8.mods.galacticraft.core.util.WorldUtil;
import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.*;
import net.minecraft.entity.IProjectile;
Expand Down Expand Up @@ -83,9 +84,6 @@
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
Expand Down Expand Up @@ -499,7 +497,7 @@ public void onTextureStitchPre(TextureStitchEvent.Pre event) {

@SubscribeEvent
public void tickWorld(TickEvent.WorldTickEvent event) {
if(event.side == Side.SERVER || !event.world.isRemote) {
if((event.side == Side.SERVER || !event.world.isRemote) && event.phase == TickEvent.Phase.START) {
if(!shapeGens.containsKey(event.world.provider.dimensionId))
{
shapeGens.put(event.world.provider.dimensionId, new ShapeGen(event.world));
Expand All @@ -508,6 +506,16 @@ public void tickWorld(TickEvent.WorldTickEvent event) {
}
}

@SubscribeEvent
public void worldUnload(WorldEvent.Unload event) {
ShapeGen.stopping = true;
}

@SubscribeEvent
public void serverStopping(FMLServerStoppingEvent event) {
ShapeGen.stopping = true;
}

@SubscribeEvent
public void playerUpdate(LivingEvent.LivingUpdateEvent event) {
if (ABO.blockLiquidXP != null) {
Expand Down Expand Up @@ -544,35 +552,6 @@ public void playerUpdate(LivingEvent.LivingUpdateEvent event) {
}
}

@SubscribeEvent
public void onBonemeal(BonemealEvent event) {
Block var5 = event.block;
World par1World = event.world;
if (var5 == Blocks.dirt)
{
if (!par1World.isRemote)
{
boolean success = false;

if (isBlockDirtAndFree(par1World, event.x, event.y, event.z))
{
BiomeGenBase biome = par1World.getBiomeGenForCoords(event.x, event.z);
Block block1 = Blocks.grass;
int meta = 0;
if(biome == BiomeGenBase.mushroomIsland || biome == BiomeGenBase.mushroomIslandShore) block1 = Blocks.mycelium;
if(biome == BiomeGenBase.megaTaiga || biome == BiomeGenBase.megaTaigaHills) meta = 1;
success = par1World.setBlock(event.x, event.y, event.z, block1, meta, 3) && randomizeGrass(par1World, event.x, event.y, event.z);
}

if (success && !event.entityPlayer.capabilities.isCreativeMode && par1World.rand.nextInt(20) == 0)
{
event.entityPlayer.inventory.getCurrentItem().stackSize--;
if(event.entityPlayer.inventory.getCurrentItem().stackSize <= 0 ) event.entityPlayer.inventory.setInventorySlotContents(event.entityPlayer.inventory.currentItem, null);
}
}
}
}

private boolean randomizeGrass(World world, int i, int j, int k)
{
boolean success = false;
Expand Down Expand Up @@ -727,7 +706,7 @@ public void onRightClick(PlayerInteractEvent event) {
{
return;
}
ShapeGen.getShapeGen(world).blend(world, i, j, k, 5, 3, true, false, true);
ShapeGen.getShapeGen(world).blend(world, i, j, k, 5, 1, true, false, false);
} else if (itemstack.getItemDamage() == 10)
{
ChunkCoordinates chuck = getLookingOffset(world, entityplayer, range, -2);
Expand All @@ -745,7 +724,7 @@ public void onRightClick(PlayerInteractEvent event) {
{
return;
}
ShapeGen.getShapeGen(world).blend(world, i, j, k, 4, 2, false, false, true);
ShapeGen.getShapeGen(world).blend(world, i, j, k, 4, 1, false, false, true);
}
}

Expand Down
127 changes: 13 additions & 114 deletions src/main/java/da3dsoul/ShapeGen/ShapeGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public ShapeGen(World world)
blocksToAdd = new LinkedHashMap();
this.world = world;
shapeGenID = world.provider.dimensionId;
alive = true;
readFromNBT();
}

Expand All @@ -81,84 +80,39 @@ public int getLength()

public void tick()
{
if (server == null)
{
return;
if(!updatingAnywhere) {
synchronized (blocks) {
blocks.putAll(blocksToAdd);
blocksToAdd.clear();
}
}

if (world == null)
if (server == null || world == null)
{
return;
}

boolean flag = true;

if (world != null && !world.playerEntities.isEmpty())
{
flag = false;
}

if (flag)
{
if (!Instant)
{
Instant = true;
}
}
else if (Instant)
{
Instant = false;
}

blocks.putAll(blocksToAdd);
blocksToAdd.clear();

update();
cleanUpList();
}

public void update()
{
if (!server.isServerRunning() && !stopping)
if (stopping)
{
writeToNBT();
return;
}

if (world == null || server == null)
{
return;
}

if (adding)
{
if (!updatingAnywhere)
{
updatingAnywhere = true;
}

return;
}

int c = 0;

if (blocks == null || blocks.isEmpty())
{
if (updatingAnywhere)
{
updatingAnywhere = false;
}

return;
}

if (!updatingAnywhere)
{
updatingAnywhere = true;
}

Notify = true;

updatingAnywhere = true;
synchronized (blocks)
{
for (Iterator it = blocks.entrySet().iterator(); c <= (Instant ? 16384 : 512) && it.hasNext(); it.remove())
Expand Down Expand Up @@ -192,6 +146,7 @@ public void update()
c++;
}
}
updatingAnywhere = false;
}

public synchronized void addBlock(int i, int j, int k, Block id)
Expand All @@ -214,8 +169,6 @@ public synchronized void addBlock(int a[], Block blockID)

public synchronized void addBlock(int i, int j, int k, Block id, int l)
{
if (!alive) return;

if (updatingAnywhere)
{
blocksToAdd.put(toString(i, j, k),Block.blockRegistry.getNameForObject(id) + "," + l);
Expand All @@ -240,7 +193,7 @@ public synchronized void addBlockAtStart(int i, int j, int k, Block id, int l)

public synchronized void addBlocks(Map list)
{
if (!alive)
if (updatingAnywhere)
{
blocksToAdd.putAll(list);
return;
Expand Down Expand Up @@ -278,10 +231,6 @@ public void removeBlockUpdate(int i, int j, int k, int id, int l)
}
}

public void cleanUpList()
{
}

public void clearBlocks()
{
synchronized (blocks)
Expand Down Expand Up @@ -898,10 +847,6 @@ public void placeBlockLine(int par1ArrayOfInteger[], int par2ArrayOfInteger[], B

public void placeCone(int X, int Y, int Z, int radius, int height, Block blockID, int blockMeta)
{
if (!alive)
{
return;
}

int endPoint[] =
{
Expand Down Expand Up @@ -929,10 +874,6 @@ public void placeCone(int X, int Y, int Z, int radius, int height, Block blockID
public void placeConeHollow(int X, int Y, int Z, int radius, int height, Block blockID, int blockMeta,
int thickness, boolean cap, boolean fillair)
{
if (!alive)
{
return;
}

int endPoint[] =
{
Expand Down Expand Up @@ -970,10 +911,6 @@ public void placeConeHollow(int X, int Y, int Z, int radius, int height, Block b
public void placeConeHollowInverted(int X, int Y, int Z, int radius, int height, Block blockID, int blockMeta,
int thickness, boolean cap, boolean fillair)
{
if (!alive)
{
return;
}

int endPoint[] =
{
Expand Down Expand Up @@ -1020,10 +957,6 @@ public void placeConeHollowInverted(int X, int Y, int Z, int radius, int height,

public void placeConeInverted(int X, int Y, int Z, int radius, int height, Block blockID, int blockMeta)
{
if (!alive)
{
return;
}

int endPoint[] =
{
Expand Down Expand Up @@ -1061,10 +994,6 @@ public void placeCube(int X, int Y, int Z, int size, Block BlockID, boolean inve

public void placeCylinder(int X, int Y, int Z, int radius, int height, Block blockID, int blockMeta)
{
if (!alive)
{
return;
}

for (int i = -radius; i <= radius; i++)
{
Expand All @@ -1091,10 +1020,6 @@ public void placeCylinder(int X, int Y, int Z, int radius, int height, Block blo
public void placeCylinderHollow(int X, int Y, int Z, int radius, int height, int thickness, boolean cap,
boolean fillair, Block blockID, int blockMeta, boolean captop)
{
if (!alive)
{
return;
}

for (int i = -radius; i <= radius; i++)
{
Expand Down Expand Up @@ -1134,10 +1059,6 @@ public void placeCylinderHollow(int X, int Y, int Z, int radius, int height, int
public void placeDome(int X, int Y, int Z, float radius, Block BlockID, boolean hollow, int thickness,
boolean fillair, int metadata)
{
if (!alive)
{
return;
}

for (int y = 0; y <= (int)Math.ceil(radius); y++)
{
Expand Down Expand Up @@ -1241,10 +1162,6 @@ else if (distance <= radius)
public void placeDomeInverted(int X, int Y, int Z, float radius, Block BlockID, boolean hollow, int thickness,
boolean fillair, int metadata)
{
if (!alive)
{
return;
}

for (int y = 0; y <= (int)Math.ceil(radius); y++)
{
Expand Down Expand Up @@ -1348,10 +1265,6 @@ public void placeRectangularPrism(int X, int Y, int Z, double sizeX, double size
double sizeZ, Block BlockID, boolean inverted, boolean hollow, int thickness, boolean fillair,
int metadata)
{
if (!alive)
{
return;
}

if (sizeX % 2D == 0.0D && sizeZ % 2D != 0.0D)
{
Expand Down Expand Up @@ -1469,10 +1382,6 @@ else if (!Instant)
public void placeSphere(int X, int Y, int Z, float radius, Block BlockID, boolean hollow, int thickness,
boolean fillair, boolean noisy, int metadata)
{
if (!alive)
{
return;
}

for (int y = 0; y <= (int)Math.ceil(radius); y++)
{
Expand Down Expand Up @@ -1646,16 +1555,12 @@ public void placeSphere(int X, int Y, int Z, int radius, Block BlockID)
public void placeSphereTopsoil(int X, int Y, int Z, float radius, Block BlockID, Block interID, Block topsoilID,
int blockmetadata, int intermetadata, int topmetadata)
{
if (!alive)
{
return;
}

for (int y = 0; y < (int)Math.ceil(radius); y++)
for (int y = 0; y <= (int)Math.ceil(radius); y++)
{
for (int z = 0; z < (int)Math.ceil(radius); z++)
for (int z = 0; z <= (int)Math.ceil(radius); z++)
{
for (int x = 0; x < (int)Math.ceil(radius); x++)
for (int x = 0; x <= (int)Math.ceil(radius); x++)
{
float distance = MathHelper.sqrt_double(x * x + z * z + y * y);

Expand Down Expand Up @@ -1769,10 +1674,6 @@ public void placeTopsoil(int X, int Y, int Z, int radius, Block interID, Block t
public void placeTopsoil(int X, int Y, int Z, int radius, Block interID, Block topsoilID, int intermetadata,
int topmetadata, EntityPlayer player, boolean fromBiome)
{
if (!alive)
{
return;
}

for (int i = X - radius; i <= X + radius; i++)
{
Expand Down Expand Up @@ -2394,9 +2295,7 @@ private String toString(int i, int j, int k)
public static boolean Instant = false;
public static boolean Notify = true;
private static MinecraftServer server;
public boolean alive;
public boolean updatingAnywhere;
public boolean adding;
private Map<String,String> blocks;
private Map<String, String> blocksToAdd;
private final byte otherCoordPairs[] =
Expand Down

0 comments on commit 1420250

Please sign in to comment.