Skip to content

Instantly share code, notes, and snippets.

@Vazkii
Last active February 27, 2016 04:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vazkii/a6f3f0d8f33ebe8a9eb2 to your computer and use it in GitHub Desktop.
Save Vazkii/a6f3f0d8f33ebe8a9eb2 to your computer and use it in GitHub Desktop.
Mod that replaces swamp trees with other stuff
package vazkii.substreetution;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.relauncher.ReflectionHelper;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.config.Configuration;
@Mod(modid="substreetution", name="Substreetution", version="1.0")
public class Substreetution {
public static Block logBlock = Blocks.log, leafBlock = Blocks.leaves;
public static int logMeta, leafMeta;
private static String logBlockName, leafBlockName;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
logBlockName = config.getString("Log Block", Configuration.CATEGORY_GENERAL, Block.blockRegistry.getNameForObject(logBlock), "");
leafBlockName = config.getString("Leaf Block", Configuration.CATEGORY_GENERAL, Block.blockRegistry.getNameForObject(leafBlock), "");
logMeta = config.getInt("Log Metadata", Configuration.CATEGORY_GENERAL, logMeta, 0, 15, "");
leafMeta = config.getInt("Leaf Metadata", Configuration.CATEGORY_GENERAL, leafMeta, 0, 15, "");
if(config.hasChanged())
config.save();
}
@EventHandler
public void init(FMLInitializationEvent event) {
if(Block.blockRegistry.containsKey(logBlockName))
logBlock = (Block) Block.blockRegistry.getObject(logBlockName);
if(Block.blockRegistry.containsKey(leafBlockName))
leafBlock = (Block) Block.blockRegistry.getObject(leafBlockName);
String[] values = {
"aB", "field_76763_Q", "worldGeneratorSwamp"
};
BiomeGenBase b = BiomeGenBase.swampland;
ReflectionHelper.setPrivateValue(BiomeGenBase.class, b, new WorldGenSwampOverride(), values);
}
}
package vazkii.substreetution;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenSwamp;
import net.minecraftforge.common.util.ForgeDirection;
public class WorldGenSwampOverride extends WorldGenSwamp {
public boolean generate(World p_76484_1_, Random p_76484_2_, int p_76484_3_, int p_76484_4_, int p_76484_5_)
{
int l;
for (l = p_76484_2_.nextInt(4) + 5; p_76484_1_.getBlock(p_76484_3_, p_76484_4_ - 1, p_76484_5_).getMaterial() == Material.water; --p_76484_4_)
{
;
}
boolean flag = true;
if (p_76484_4_ >= 1 && p_76484_4_ + l + 1 <= 256)
{
int j1;
int k1;
for (int i1 = p_76484_4_; i1 <= p_76484_4_ + 1 + l; ++i1)
{
byte b0 = 1;
if (i1 == p_76484_4_)
{
b0 = 0;
}
if (i1 >= p_76484_4_ + 1 + l - 2)
{
b0 = 3;
}
for (j1 = p_76484_3_ - b0; j1 <= p_76484_3_ + b0 && flag; ++j1)
{
for (k1 = p_76484_5_ - b0; k1 <= p_76484_5_ + b0 && flag; ++k1)
{
if (i1 >= 0 && i1 < 256)
{
Block block = p_76484_1_.getBlock(j1, i1, k1);
if (!(block.isAir(p_76484_1_, j1, i1, k1) || block.isLeaves(p_76484_1_, j1, i1, k1)))
{
if (block != Blocks.water && block != Blocks.flowing_water)
{
flag = false;
}
else if (i1 > p_76484_4_)
{
flag = false;
}
}
}
else
{
flag = false;
}
}
}
}
if (!flag)
{
return false;
}
else
{
Block block1 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ - 1, p_76484_5_);
boolean isSoil = block1.canSustainPlant(p_76484_1_, p_76484_3_, p_76484_4_ - 1, p_76484_5_, ForgeDirection.UP, (BlockSapling)Blocks.sapling);
if (isSoil && p_76484_4_ < 256 - l - 1)
{
block1.onPlantGrow(p_76484_1_, p_76484_3_, p_76484_4_ - 1, p_76484_5_, p_76484_3_, p_76484_4_, p_76484_5_);
int l1;
int k2;
int l2;
for (k2 = p_76484_4_ - 3 + l; k2 <= p_76484_4_ + l; ++k2)
{
j1 = k2 - (p_76484_4_ + l);
k1 = 2 - j1 / 2;
for (l2 = p_76484_3_ - k1; l2 <= p_76484_3_ + k1; ++l2)
{
l1 = l2 - p_76484_3_;
for (int i2 = p_76484_5_ - k1; i2 <= p_76484_5_ + k1; ++i2)
{
int j2 = i2 - p_76484_5_;
if ((Math.abs(l1) != k1 || Math.abs(j2) != k1 || p_76484_2_.nextInt(2) != 0 && j1 != 0) && p_76484_1_.getBlock(l2, k2, i2).canBeReplacedByLeaves(p_76484_1_, l2, k2, i2))
{
setBlockAndNotifyAdequately(p_76484_1_, l2, k2, i2, Substreetution.leafBlock, Substreetution.leafMeta);
}
}
}
}
for (k2 = 0; k2 < l; ++k2)
{
Block block2 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ + k2, p_76484_5_);
if (block2.isAir(p_76484_1_, p_76484_3_, p_76484_4_ + k2, p_76484_5_) || block2.isLeaves(p_76484_1_, p_76484_3_, p_76484_4_ + k2, p_76484_5_) || block2 == Blocks.flowing_water || block2 == Blocks.water)
{
setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_, p_76484_4_ + k2, p_76484_5_, Substreetution.logBlock, Substreetution.logMeta);
}
}
for (k2 = p_76484_4_ - 3 + l; k2 <= p_76484_4_ + l; ++k2)
{
j1 = k2 - (p_76484_4_ + l);
k1 = 2 - j1 / 2;
for (l2 = p_76484_3_ - k1; l2 <= p_76484_3_ + k1; ++l2)
{
for (l1 = p_76484_5_ - k1; l1 <= p_76484_5_ + k1; ++l1)
{
if (p_76484_1_.getBlock(l2, k2, l1).isLeaves(p_76484_1_, l2, k2, l1))
{
if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(l2 - 1, k2, l1).isAir(p_76484_1_, l2 - 1, k2, l1))
{
this.generateVines(p_76484_1_, l2 - 1, k2, l1, 8);
}
if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(l2 + 1, k2, l1).isAir(p_76484_1_, l2 + 1, k2, l1))
{
this.generateVines(p_76484_1_, l2 + 1, k2, l1, 2);
}
if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(l2, k2, l1 - 1).isAir(p_76484_1_, l2, k2, l1 - 1))
{
this.generateVines(p_76484_1_, l2, k2, l1 - 1, 1);
}
if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(l2, k2, l1 + 1).isAir(p_76484_1_, l2, k2, l1 + 1))
{
this.generateVines(p_76484_1_, l2, k2, l1 + 1, 4);
}
}
}
}
}
return true;
}
else
{
return false;
}
}
}
else
{
return false;
}
}
/**
* Generates vines at the given position until it hits a block.
*/
private void generateVines(World p_76536_1_, int p_76536_2_, int p_76536_3_, int p_76536_4_, int p_76536_5_)
{
this.setBlockAndNotifyAdequately(p_76536_1_, p_76536_2_, p_76536_3_, p_76536_4_, Blocks.vine, p_76536_5_);
int i1 = 4;
while (true)
{
--p_76536_3_;
if (!(p_76536_1_.getBlock(p_76536_2_, p_76536_3_, p_76536_4_).isAir(p_76536_1_, p_76536_2_, p_76536_3_, p_76536_4_)) || i1 <= 0)
{
return;
}
this.setBlockAndNotifyAdequately(p_76536_1_, p_76536_2_, p_76536_3_, p_76536_4_, Blocks.vine, p_76536_5_);
--i1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment