Skip to content

Instantly share code, notes, and snippets.

@AEnterprise
Created April 29, 2014 19:07
Show Gist options
  • Save AEnterprise/11409086 to your computer and use it in GitHub Desktop.
Save AEnterprise/11409086 to your computer and use it in GitHub Desktop.
code for the railcraft villager stuff
package buildcraftAdditions.villager;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.gen.structure.StructureBoundingBox;
import net.minecraft.world.gen.structure.StructureComponent;
import net.minecraft.world.gen.structure.StructureVillagePieces;
import net.minecraft.world.gen.structure.StructureVillagePieces.Start;
public class ComponentWorkshop extends StructureVillagePieces.House1 {
private int averageGroundLevel = -1;
public ComponentWorkshop(){}
public ComponentWorkshop(Start villagePiece, int par2, Random par3Random, StructureBoundingBox par4StructureBoundingBox, int par5){
super();
this.coordBaseMode = par5;
this.boundingBox = par4StructureBoundingBox;
}
public static ComponentWorkshop buildComponent (Start villagePiece, List pieces, Random random, int p1, int p2, int p3, int p4, int p5){
StructureBoundingBox structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(p1, p2, p3, 0, 0, 0, 6, 6, 12, p4);
return canVillageGoDeeper(structureboundingbox) && StructureComponent.findIntersecting(pieces, structureboundingbox) == null ? new ComponentWorkshop(villagePiece, p5, random, structureboundingbox, p4) : null;
}
@Override
public boolean addComponentParts (World world, Random random, StructureBoundingBox sbb)
{
if (this.averageGroundLevel < 0)
{
this.averageGroundLevel = this.getAverageGroundLevel(world, sbb);
if (this.averageGroundLevel < 0)
{
return true;
}
this.boundingBox.offset(0, this.averageGroundLevel - this.boundingBox.maxY + 4, 0);
}
int i = this.boundingBox.minX;
int j = this.boundingBox.minY;
int k = this.boundingBox.minZ;
//floor
fillWithBlocks(world, sbb, 0, 0, 0, 6, 0, 12, Blocks.planks, Blocks.planks, false);
fillWithBlocks(world, sbb, 3, 1, 0, 3, 1, 12, Blocks.rail, Blocks.rail, false);
//ceiling
fillWithBlocks(world, sbb, 0, 5, 0, 0, 5, 12, Blocks.stone_brick_stairs, Blocks.stone_brick_stairs, false);
fillWithBlocks(world, sbb, 1, 5, 0, 1, 5, 12, Blocks.stonebrick, Blocks.stonebrick, false);
fillWithBlocks(world, sbb, 1, 6, 0, 1, 6, 12, Blocks.stone_brick_stairs, Blocks.stone_brick_stairs, false);
fillWithBlocks(world, sbb, 2, 6, 0, 2, 6, 12, Blocks.stonebrick, Blocks.stonebrick, false);
fillWithBlocks(world, sbb, 2, 7, 0, 2, 7, 12, Blocks.stone_brick_stairs, Blocks.stone_brick_stairs, false);
fillWithBlocks(world, sbb, 3, 7, 0, 3, 7, 12, Blocks.stonebrick, Blocks.stonebrick, false);
fillWithBlocks(world, sbb, 4, 6, 0, 4, 6, 12, Blocks.stonebrick, Blocks.stonebrick, false);
fillWithBlocks(world, sbb, 5, 5, 0, 5, 5, 12, Blocks.stonebrick, Blocks.stonebrick, false);
fillWithBlocks(world, sbb, 5, 6, 0, 5, 6, 12, Blocks.stonebrick, Blocks.stonebrick, false);
//these stairs have to be done like this or they will be rotaded the wrong way
world.setBlock(i + 4, j + 7, k + 0, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 1, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 2, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 3, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 4, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 5, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 6, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 7, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 8, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 9, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 10, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 11, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 4, j + 7, k + 12, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 0, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 1, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 2, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 3, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 4, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 5, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 6, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 7, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 8, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 9, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 10, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 11, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 5, j + 6, k + 12, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 0, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 1, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 2, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 3, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 4, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 5, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 6, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 7, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 8, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 9, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 10, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 11, Blocks.stone_brick_stairs, 1, 0x20);
world.setBlock(i + 6, j + 5, k + 12, Blocks.stone_brick_stairs, 1, 0x20);
//walls
fillWithBlocks(world, sbb, 6, 1, 0, 6, 4, 12, Blocks.brick_block, Blocks.brick_block, false);
fillWithBlocks(world, sbb, 0, 1, 0, 0, 4, 12, Blocks.brick_block, Blocks.brick_block, false);
//put the sky windows in
world.setBlock(i + 3, j + 7, k + 3, Blocks.stained_glass, 9, 0x20);
world.setBlock(i + 3, j + 7, k + 6, Blocks.stained_glass, 9, 0x02);
world.setBlock(i + 3, j + 7, k + 9, Blocks.stained_glass, 9, 0x02);
//crafting table, might be swiched for a rolling machine or another railcraft crafting machine?
world.setBlock(i + 5, j + 1, k + 5, Blocks.crafting_table);
//torches on the wall, also have to be done like this or they will fall on the ground
world.setBlock(i + 1, j + 4, k + 0, Blocks.torch, 1, 0x20);
world.setBlock(i + 1, j + 4, k + 3, Blocks.torch, 1, 0x20);
world.setBlock(i + 1, j + 4, k + 6, Blocks.torch, 1, 0x20);
world.setBlock(i + 1, j + 4, k + 9, Blocks.torch, 1, 0x20);
world.setBlock(i + 1, j + 4, k + 12, Blocks.torch, 1, 0x20);
world.setBlock(i + 5, j + 4, k + 0, Blocks.torch, 2, 0x20);
world.setBlock(i + 5, j + 4, k + 3, Blocks.torch, 2, 0x20);
world.setBlock(i + 5, j + 4, k + 6, Blocks.torch, 2, 0x20);
world.setBlock(i + 5, j + 4, k + 9, Blocks.torch, 2, 0x20);
world.setBlock(i + 5, j + 4, k + 12, Blocks.torch, 2, 0x20);
spawnVillagers(world, sbb, 0, 0, 0, 2);
return true;
}
@Override
protected int getVillagerType (int par1)
{
return 456;
}
}
// this code goes intro the init of the mod
VillagerRegistry.instance().registerVillagerId(456);
VillagerRegistry.instance().registerVillagerSkin(456, texture);
VillagerRegistry.instance().registerVillageTradeHandler(456, new VillagerTradeHandler());
VillagerRegistry.instance().registerVillageCreationHandler(new WorkshopCreationHandeler());
try
{
MapGenStructureIO.func_143031_a(ComponentWorkshop.class, "bcadditions:Workshop");
}
catch (Throwable e){}
package buildcraftAdditions.villager;
import java.util.Random;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.village.MerchantRecipe;
import net.minecraft.village.MerchantRecipeList;
import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler;
public class VillagerTradeHandler implements IVillageTradeHandler {
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random)
{
//this is where the custom villager trades are specified
recipeList.add(new MerchantRecipe(new ItemStack(Blocks.log, 8, 0), null, new ItemStack(Blocks.planks, 64, 0)));
}
}
package buildcraftAdditions.villager;
import java.util.List;
import java.util.Random;
import net.minecraft.world.gen.structure.StructureVillagePieces.PieceWeight;
import net.minecraft.world.gen.structure.StructureVillagePieces.Start;
import cpw.mods.fml.common.registry.VillagerRegistry.IVillageCreationHandler;
public class WorkshopCreationHandeler implements IVillageCreationHandler {
@Override
public PieceWeight getVillagePieceWeight(Random random, int i) {
return new PieceWeight(ComponentWorkshop.class, 9, 1);
}
@Override
public Class<?> getComponentClass() {
return ComponentWorkshop.class;
}
@Override
public Object buildComponent(PieceWeight villagePiece, Start startPiece, List pieces, Random random, int p1, int p2, int p3, int p4, int p5) {
return ComponentWorkshop.buildComponent(startPiece, pieces, random, p1, p2, p3, p4, p5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment