Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
impiaaa committed Mar 21, 2016
1 parent 9629d63 commit 514a98e
Show file tree
Hide file tree
Showing 38 changed files with 310 additions and 561 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.boatcake.MyWorldGen;

public enum BlockPlacementOption {
ASGENERATED("gui.placement.asgenerated", 0, true, true, true), LOSSLESS(
"gui.placement.lossless", 1, false, false, false);
ASGENERATED("gui.placement.asgenerated", 0, true, true, true), LOSSLESS("gui.placement.lossless", 1, false, false,
false);

public String text;
public BlockPlacementOption next;
Expand All @@ -16,8 +16,8 @@ public enum BlockPlacementOption {
LOSSLESS.next = ASGENERATED;
}

private BlockPlacementOption(String text, int id, boolean generateChests,
boolean generateSpawners, boolean followPlacementRules) {
private BlockPlacementOption(String text, int id, boolean generateChests, boolean generateSpawners,
boolean followPlacementRules) {
this.text = text;
this.id = id;
this.generateChests = generateChests;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/boatcake/MyWorldGen/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ public abstract class CommonProxy {

public abstract void registerItem(Item item, int metadata, String itemName);

public abstract void registerBlock(Block block, int metadata,
String blockName);
public abstract void registerBlock(Block block, int metadata, String blockName);

public abstract void registerVariants(Block block, PropertyEnum prop,
String postfix);
public abstract void registerVariants(Block block, PropertyEnum prop, String postfix);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
public class ContainerAnchorInventory extends Container {
protected TileEntityAnchorInventory tileEntity;

public ContainerAnchorInventory(InventoryPlayer inventoryPlayer,
TileEntityAnchorInventory te) {
public ContainerAnchorInventory(InventoryPlayer inventoryPlayer, TileEntityAnchorInventory te) {
tileEntity = te;

/*
Expand All @@ -20,8 +19,7 @@ public ContainerAnchorInventory(InventoryPlayer inventoryPlayer,
*/
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
addSlotToContainer(new SlotPhantomBlock(tileEntity, j + i * 3,
62 + j * 18, 17 + i * 18));
addSlotToContainer(new SlotPhantomBlock(tileEntity, j + i * 3, 62 + j * 18, 17 + i * 18));
}
}
bindPlayerInventory(inventoryPlayer);
Expand All @@ -30,8 +28,7 @@ public ContainerAnchorInventory(InventoryPlayer inventoryPlayer,
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
8 + j * 18, 84 + i * 18));
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}

Expand All @@ -48,7 +45,7 @@ public boolean canInteractWith(EntityPlayer entityplayer) {
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotIdx) {
ItemStack stackCopy = null;
Slot slot = (Slot) inventorySlots.get(slotIdx);
Slot slot = inventorySlots.get(slotIdx);

// null checks and checks if the item can be stacked (maxStackSize > 1)
if (slot != null && slot.getHasStack()) {
Expand All @@ -63,8 +60,7 @@ public ItemStack transferStackInSlot(EntityPlayer player, int slotIdx) {
}
// places it into the tileEntity is possible since its in the player
// inventory
else if (!slot.isItemValid(stackInSlot)
|| !this.mergeItemStack(stackInSlot, 0, 9, false)) {
else if (!slot.isItemValid(stackInSlot) || !this.mergeItemStack(stackInSlot, 0, 9, false)) {
return null;
}

Expand Down
15 changes: 5 additions & 10 deletions src/main/java/net/boatcake/MyWorldGen/GuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@
public class GuiHandler implements IGuiHandler {

@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world,
int x, int y, int z) {
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
if (FMLCommonHandler.instance().getSide() != Side.CLIENT) {
return null;
}
switch (id) {
case 0:
return new GuiSaveSchematic();
case 1:
return new GuiLoadSchematic(new BlockPos(x, y, z),
DirectionUtils.getDirectionFromYaw(player.rotationYaw));
return new GuiLoadSchematic(new BlockPos(x, y, z), DirectionUtils.getDirectionFromYaw(player.rotationYaw));
case 2:
TileEntity tileEntity = world.getTileEntity(new BlockPos(x, y, z));
if (tileEntity instanceof TileEntityAnchorInventory) {
return new GuiAnchorInventory(player.inventory,
(TileEntityAnchorInventory) tileEntity);
return new GuiAnchorInventory(player.inventory, (TileEntityAnchorInventory) tileEntity);
}
return null;
default:
Expand All @@ -40,13 +37,11 @@ public Object getClientGuiElement(int id, EntityPlayer player, World world,
}

@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world,
int x, int y, int z) {
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
if (id == 2) {
TileEntity tileEntity = world.getTileEntity(new BlockPos(x, y, z));
if (tileEntity instanceof TileEntityAnchorInventory) {
return new ContainerAnchorInventory(player.inventory,
(TileEntityAnchorInventory) tileEntity);
return new ContainerAnchorInventory(player.inventory, (TileEntityAnchorInventory) tileEntity);
}
}
return null;
Expand Down
102 changes: 35 additions & 67 deletions src/main/java/net/boatcake/MyWorldGen/MyWorldGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,21 @@ public void postInit(FMLPostInitializationEvent event) {
FileUtils.extractSchematics(sourceFile);
}

FMLInterModComms
.sendMessage(
"OpenBlocks",
"donateUrl",
"https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=UHDDACLRN2T46&lc=US&item_name=MyWorldGen&currency_code=USD&bn=PP-DonationsBF:btn_donate_SM.gif:NonHosted");
FMLInterModComms.sendMessage("OpenBlocks", "donateUrl",
"https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=UHDDACLRN2T46&lc=US&item_name=MyWorldGen&currency_code=USD&bn=PP-DonationsBF:btn_donate_SM.gif:NonHosted");

sidedProxy.registerResourceHandler(worldGen);

if (materialAnchorBlock != null) {
for (BlockAnchorMaterial.AnchorType type : BlockAnchorMaterial.AnchorType
.values()) {
sidedProxy.registerBlock(materialAnchorBlock, type.id, MODID
+ ":" + type.name + "_anchor");
for (BlockAnchorMaterial.AnchorType type : BlockAnchorMaterial.AnchorType.values()) {
sidedProxy.registerBlock(materialAnchorBlock, type.id, MODID + ":" + type.name + "_anchor");
}
}
if (ignoreBlock != null) {
sidedProxy.registerBlock(ignoreBlock, 0, MODID + ":ignore");
}
if (inventoryAnchorBlock != null) {
sidedProxy.registerBlock(inventoryAnchorBlock, 0, MODID
+ ":anchorInventory");
sidedProxy.registerBlock(inventoryAnchorBlock, 0, MODID + ":anchorInventory");
}
if (wandLoad != null) {
sidedProxy.registerItem(wandLoad, 0, MODID + ":wandLoad");
Expand All @@ -122,9 +116,7 @@ public void init(FMLInitializationEvent event) throws Exception {
cfg.load();

enableItemsAndBlocks = cfg
.get("configuration",
"enableItemsAndBlocks",
true,
.get("configuration", "enableItemsAndBlocks", true,
"Turn this off if you're running a server and the clients don't have the mod installed")
.getBoolean(true);
if (!enableItemsAndBlocks) {
Expand All @@ -135,35 +127,29 @@ public void init(FMLInitializationEvent event) throws Exception {
creativeTab = new CreativeTabs("tabMyWorldGen") {
@Override
public Item getTabIconItem() {
return Item
.getItemFromBlock(materialAnchorBlock == null ? Blocks.grass
: materialAnchorBlock);
return Item.getItemFromBlock(materialAnchorBlock == null ? Blocks.grass : materialAnchorBlock);
}
};
}

try {
Property prop;
materialAnchorBlock = registerBlock("anchor",
BlockAnchorMaterial.class, BlockAnchorItem.class,
materialAnchorBlock = registerBlock("anchor", BlockAnchorMaterial.class, BlockAnchorItem.class,
BlockAnchorMaterialLogic.class);
new BlockPlacementMaterialAnchor(MODID + ":anchor");

if (materialAnchorBlock != null) {
sidedProxy.registerVariants(materialAnchorBlock,
BlockAnchorMaterial.TYPE_PROP, "_anchor");
sidedProxy.registerVariants(materialAnchorBlock, BlockAnchorMaterial.TYPE_PROP, "_anchor");
}

int defaultId;
if (materialAnchorBlock == null) {
defaultId = 1575;
} else {
defaultId = GameData.getBlockRegistry().getId(
materialAnchorBlock);
defaultId = GameData.getBlockRegistry().getId(materialAnchorBlock);
}
prop = cfg
.get("blocks", "materialAnchorBlock", defaultId,
"Default ID for when an ID map is not found in a schematic");
prop = cfg.get("blocks", "materialAnchorBlock", defaultId,
"Default ID for when an ID map is not found in a schematic");
materialAnchorBlockId = prop.getInt(defaultId);

ignoreBlock = registerBlock("ignore", BlockIgnore.class);
Expand All @@ -173,24 +159,20 @@ public Item getTabIconItem() {
} else {
defaultId = GameData.getBlockRegistry().getId(ignoreBlock);
}
prop = cfg
.get("blocks", "ignoreBlock", defaultId,
"Default ID for when an ID map is not found in a schematic");
prop = cfg.get("blocks", "ignoreBlock", defaultId,
"Default ID for when an ID map is not found in a schematic");
ignoreBlockId = prop.getInt(defaultId);

inventoryAnchorBlock = registerBlock("anchorInventory",
BlockAnchorInventory.class, ItemBlock.class,
inventoryAnchorBlock = registerBlock("anchorInventory", BlockAnchorInventory.class, ItemBlock.class,
BlockAnchorInventoryLogic.class);
new BlockPlacementIgnore(MODID + ":anchorInventory");
if (inventoryAnchorBlock == null) {
defaultId = 1577;
} else {
defaultId = GameData.getBlockRegistry().getId(
inventoryAnchorBlock);
defaultId = GameData.getBlockRegistry().getId(inventoryAnchorBlock);
}
prop = cfg
.get("blocks", "inventoryAnchorBlock", defaultId,
"Default ID for when an ID map is not found in a schematic");
prop = cfg.get("blocks", "inventoryAnchorBlock", defaultId,
"Default ID for when an ID map is not found in a schematic");
inventoryAnchorBlockId = prop.getInt(defaultId);

wandSave = registerItem("wandSave", ItemWandSave.class, cfg);
Expand All @@ -201,67 +183,53 @@ public Item getTabIconItem() {
throw new Exception("Self-reflection failed. Is the mod intact?", e);
}

String worldGenDir = cfg.get("configuration", "schematicDirectory",
"worldgen", "Subdirectory of .minecraft").getString();
String worldGenDir = cfg.get("configuration", "schematicDirectory", "worldgen", "Subdirectory of .minecraft")
.getString();
globalSchemDir = sidedProxy.getGlobalSchemDir(worldGenDir);

generateNothingWeight = cfg
.get("configuration", "generateNothingWeight", 10,
"Increase this number to generate fewer structures, decrease to generate more.")
.getInt(10);
generateNothingWeight = cfg.get("configuration", "generateNothingWeight", 10,
"Increase this number to generate fewer structures, decrease to generate more.").getInt(10);
generateTries = cfg
.get("configuration",
"generateTries",
128,
.get("configuration", "generateTries", 128,
"Increase this if you have structures with complex anchor block layouts. Higher numbers will make longer load times.")
.getInt(128);

baseGenerateChance = cfg
.get("configuration",
"baseGenerateChance",
1.0,
"Base chance for generating in a given chunk. Compounds with generateNothingWeight.",
0.0, 1.0).getDouble(1.0);
.get("configuration", "baseGenerateChance", 1.0,
"Base chance for generating in a given chunk. Compounds with generateNothingWeight.", 0.0, 1.0)
.getDouble(1.0);

if (cfg.hasChanged()) {
cfg.save();
}

worldGen = new WorldGenerator();

GameRegistry.registerTileEntity(TileEntityAnchorInventory.class,
"anchorInventory");
GameRegistry.registerTileEntity(TileEntityAnchorInventory.class, "anchorInventory");
GameRegistry.registerWorldGenerator(worldGen, 0);
}

private Block registerBlock(String name, Class<? extends Block> blockClass,
Class<? extends ItemBlock> itemBlockClass,
Class<? extends BlockAnchorLogic> matching, Object... itemCtorArgs)
throws Exception {
Class<? extends ItemBlock> itemBlockClass, Class<? extends BlockAnchorLogic> matching,
Object... itemCtorArgs) throws Exception {
Block block = null;
if (enableItemsAndBlocks) {
block = blockClass.getConstructor(Material.class).newInstance(
Material.circuits);
block = blockClass.getConstructor(Material.class).newInstance(Material.circuits);
block.setUnlocalizedName(name);
block.setCreativeTab(creativeTab);
GameRegistry.registerBlock(block, itemBlockClass, name,
itemCtorArgs);
GameRegistry.registerBlock(block, itemBlockClass, name, itemCtorArgs);
}
if (matching != null) {
matching.getConstructor(String.class).newInstance(
MyWorldGen.MODID + ":" + name);
matching.getConstructor(String.class).newInstance(MyWorldGen.MODID + ":" + name);
}
return block;
}

private Block registerBlock(String name, Class<? extends Block> blockClass)
throws Exception {
return registerBlock(name, blockClass, ItemBlock.class, null,
new Object[] {});
private Block registerBlock(String name, Class<? extends Block> blockClass) throws Exception {
return registerBlock(name, blockClass, ItemBlock.class, null, new Object[] {});
}

private Item registerItem(String name, Class<? extends Item> itemClass,
Configuration cfg) throws Exception {
private Item registerItem(String name, Class<? extends Item> itemClass, Configuration cfg) throws Exception {
Item item = null;
if (enableItemsAndBlocks) {
item = itemClass.getConstructor().newInstance();
Expand Down
Loading

0 comments on commit 514a98e

Please sign in to comment.