From 073817b0202dd5dfbf0ac777d01de8976c114df9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 24 Apr 2015 19:55:07 -0400 Subject: [PATCH] I failed, and somehow formated Mantle... --- build.properties | 4 +- src/mantle/Mantle.java | 14 +- src/mantle/blocks/BlockUtils.java | 8 +- src/mantle/blocks/MantleBlock.java | 4 +- .../abstracts/AdaptiveInventoryLogic.java | 47 ++-- .../abstracts/ExpandableInventoryLogic.java | 160 +++++++------ .../blocks/abstracts/InventoryBlock.java | 71 +++--- .../blocks/abstracts/InventoryLogic.java | 184 ++++++++------- .../blocks/abstracts/InventorySlab.java | 36 +-- .../blocks/abstracts/ItemBlockVariants.java | 36 +-- .../blocks/abstracts/MultiItemBlock.java | 33 ++- .../blocks/abstracts/MultiServantLogic.java | 149 ++++++------ src/mantle/blocks/iface/IActiveLogic.java | 4 +- src/mantle/blocks/iface/ICrop.java | 9 +- src/mantle/blocks/iface/IFacingLogic.java | 7 +- src/mantle/blocks/iface/IMasterLogic.java | 4 +- src/mantle/blocks/iface/IMasterNode.java | 4 +- src/mantle/blocks/iface/IServantLogic.java | 20 +- .../blocks/util/IBlockWithVariants.java | 4 +- src/mantle/books/BookData.java | 13 +- src/mantle/books/BookDataStore.java | 28 ++- src/mantle/books/ManualReader.java | 5 +- src/mantle/books/client/BookImage.java | 8 +- src/mantle/books/external/BookIS.java | 4 +- src/mantle/books/external/BookLoad.java | 31 ++- src/mantle/books/external/ZipLoader.java | 19 +- src/mantle/client/MProxyClient.java | 26 ++- src/mantle/client/ModelHelper.java | 4 +- src/mantle/client/ModelVariant.java | 4 +- src/mantle/client/gui/GuiManual.java | 133 +++++++---- src/mantle/client/gui/TurnPageButton.java | 9 +- src/mantle/client/pages/BlankPage.java | 4 +- src/mantle/client/pages/BookPage.java | 9 +- .../client/pages/ContentsTablePage.java | 44 ++-- src/mantle/client/pages/CraftingPage.java | 91 +++++--- src/mantle/client/pages/FurnacePage.java | 44 ++-- src/mantle/client/pages/PicturePage.java | 52 +++-- src/mantle/client/pages/SectionPage.java | 21 +- src/mantle/client/pages/SidebarPage.java | 40 ++-- src/mantle/client/pages/TextPage.java | 14 +- src/mantle/client/pages/TitlePage.java | 14 +- src/mantle/common/ComparisonHelper.java | 10 +- src/mantle/common/IDDumps.java | 3 +- src/mantle/common/MProxyCommon.java | 10 +- src/mantle/common/network/AbstractPacket.java | 18 +- src/mantle/common/network/PacketUpdateTE.java | 25 +- src/mantle/crash/CallableSuppConfig.java | 6 +- src/mantle/crash/CallableUnsuppConfig.java | 11 +- src/mantle/debug/DebugData.java | 5 +- src/mantle/debug/DebugHelper.java | 10 +- src/mantle/debug/IDebuggable.java | 2 +- src/mantle/event/ManualOpenEvent.java | 43 ++-- src/mantle/event/Migration.java | 78 ++++--- src/mantle/items/ItemUtils.java | 7 +- src/mantle/items/Manual.java | 30 +-- src/mantle/items/abstracts/CraftingItem.java | 27 ++- src/mantle/lib/CoreConfig.java | 22 +- src/mantle/lib/CoreRepo.java | 2 + src/mantle/lib/TabTools.java | 16 +- .../lib/client/MantleClientRegistry.java | 22 +- .../lib/environment/EnvironmentChecks.java | 9 +- src/mantle/math/Dozenal.java | 16 +- src/mantle/player/PlayerUtils.java | 6 +- src/mantle/pulsar/config/ForgeCFG.java | 31 ++- src/mantle/pulsar/config/IConfiguration.java | 3 +- src/mantle/pulsar/control/PulseManager.java | 214 +++++++++++------- src/mantle/pulsar/debug/EventSpy.java | 13 +- src/mantle/pulsar/internal/Configuration.java | 201 ++++++++++------ src/mantle/pulsar/internal/CrashHandler.java | 37 ++- .../pulsar/internal/logging/ILogger.java | 3 +- .../pulsar/internal/logging/JULLogger.java | 38 ++-- .../pulsar/internal/logging/Log4jLogger.java | 38 ++-- .../pulsar/internal/logging/LogManager.java | 32 ++- src/mantle/pulsar/pulse/Pulse.java | 11 +- src/mantle/pulsar/pulse/PulseMeta.java | 35 +-- src/mantle/utils/ItemMetaWrapper.java | 34 ++- src/mantle/utils/ItemStackNBTWrapper.java | 30 ++- src/mantle/utils/ItemStackWrapper.java | 34 ++- src/mantle/utils/RecipeRemover.java | 18 +- src/mantle/world/ChunkCoord.java | 21 +- src/mantle/world/CoordTuplePair.java | 3 +- src/mantle/world/DimensionCoordPair.java | 31 ++- src/mantle/world/DimensionCoordTuple.java | 36 +-- src/mantle/world/DirectionUtils.java | 4 +- 84 files changed, 1577 insertions(+), 1083 deletions(-) diff --git a/build.properties b/build.properties index ca0113d..43e5f71 100644 --- a/build.properties +++ b/build.properties @@ -1,5 +1,5 @@ mod_version=0.4 minecraft_version=1.8 -forge_version=11.14.1.1353 -mappings=snapshot_20150404 +forge_version=11.14.1.1392 +mappings=snapshot_20150424 diff --git a/src/mantle/Mantle.java b/src/mantle/Mantle.java index 7a9e6de..34ab38f 100644 --- a/src/mantle/Mantle.java +++ b/src/mantle/Mantle.java @@ -4,8 +4,6 @@ import static mantle.lib.CoreRepo.logger; import static mantle.lib.CoreRepo.modId; import static mantle.lib.CoreRepo.modName; import static mantle.lib.CoreRepo.modVersion; - -import LZMA.LzmaInputStream; import mantle.books.BookData; import mantle.books.BookDataStore; import mantle.common.IDDumps; @@ -24,8 +22,6 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; -import java.io.File; - /** * Mantle * @@ -39,11 +35,13 @@ public class Mantle /* Instance of this mod, used for grabbing prototype fields */ @Instance("mantle") public static Mantle instance; + /* Proxies for sides, used for graphics processing */ @SidedProxy(clientSide = "mantle.client.MProxyClient", serverSide = "mantle.common.MProxyCommon") - public static MProxyCommon proxy; + public static Manual mantleBook; + /** * Constructor * @@ -62,7 +60,7 @@ public class Mantle * @param evt The FMLPreInitializationEvent from FML */ @EventHandler - public void preInit (FMLPreInitializationEvent evt) + public void preInit(FMLPreInitializationEvent evt) { logger.info("Mantle (" + modVersion + ") -- Preparing for launch."); logger.info("Entering preinitialization phase."); @@ -82,7 +80,7 @@ public class Mantle * @param evt The FMLInitializationEvent from FML */ @EventHandler - public void Init (FMLInitializationEvent evt) + public void Init(FMLInitializationEvent evt) { logger.info("Entering initialization phase."); proxy.registerRenderer(); @@ -96,7 +94,7 @@ public class Mantle * @param evt The FMLPostInitializationEvent from FML */ @EventHandler - public void postInit (FMLPostInitializationEvent evt) + public void postInit(FMLPostInitializationEvent evt) { logger.info("Entering postinitialization phase."); proxy.readManuals(); diff --git a/src/mantle/blocks/BlockUtils.java b/src/mantle/blocks/BlockUtils.java index 28a1d95..b6c0523 100644 --- a/src/mantle/blocks/BlockUtils.java +++ b/src/mantle/blocks/BlockUtils.java @@ -7,23 +7,23 @@ import net.minecraftforge.fml.common.registry.GameData; public class BlockUtils { - public static Block getBlockFromItem (Item item) + public static Block getBlockFromItem(Item item) { return Block.getBlockFromItem(item); } @SuppressWarnings("unused") - public static Block getBlockFromItemStack (ItemStack itemStack) + public static Block getBlockFromItemStack(ItemStack itemStack) { return getBlockFromItem(itemStack.getItem()); } - public static String getUniqueName (Block block) + public static String getUniqueName(Block block) { return GameData.getBlockRegistry().getNameForObject(block).toString(); } - public static Block getBlockFromUniqueName (String uniqueName) + public static Block getBlockFromUniqueName(String uniqueName) { return GameData.getBlockRegistry().getObject(uniqueName); } diff --git a/src/mantle/blocks/MantleBlock.java b/src/mantle/blocks/MantleBlock.java index 9b33e86..552909e 100644 --- a/src/mantle/blocks/MantleBlock.java +++ b/src/mantle/blocks/MantleBlock.java @@ -28,14 +28,16 @@ public abstract class MantleBlock extends Block // IDebuggable support - Uses a stick for debug purposes. @Override - public void onBlockClicked (World world, BlockPos pos, EntityPlayer player) + public void onBlockClicked(World world, BlockPos pos, EntityPlayer player) { if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && player.getHeldItem() != null && (player.getHeldItem().getItem() == Items.stick || player.getHeldItem().getItem() instanceof IDebugItem)) { TileEntity te = world.getTileEntity(pos); if (te instanceof IDebuggable) + { DebugHelper.handleDebugData(((IDebuggable) te).getDebugInfo(player)); + } } super.onBlockClicked(world, pos, player); } diff --git a/src/mantle/blocks/abstracts/AdaptiveInventoryLogic.java b/src/mantle/blocks/abstracts/AdaptiveInventoryLogic.java index c6436bb..3f91f76 100644 --- a/src/mantle/blocks/abstracts/AdaptiveInventoryLogic.java +++ b/src/mantle/blocks/abstracts/AdaptiveInventoryLogic.java @@ -10,6 +10,7 @@ import net.minecraft.nbt.NBTTagCompound; public abstract class AdaptiveInventoryLogic extends InventoryLogic implements IFacingLogic { Random random = new Random(); + protected int inventorySize; public AdaptiveInventoryLogic() @@ -17,32 +18,32 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I super(0); } - protected void adjustInventory (int size, boolean forceAdjust) + protected void adjustInventory(int size, boolean forceAdjust) { - if (size != inventorySize || forceAdjust) + if (size != this.inventorySize || forceAdjust) { - inventorySize = size; + this.inventorySize = size; - ItemStack[] tempInv = inventory; - inventory = new ItemStack[size]; - int invLength = tempInv.length > inventory.length ? inventory.length : tempInv.length; - System.arraycopy(tempInv, 0, inventory, 0, invLength); + ItemStack[] tempInv = this.inventory; + this.inventory = new ItemStack[size]; + int invLength = tempInv.length > this.inventory.length ? this.inventory.length : tempInv.length; + System.arraycopy(tempInv, 0, this.inventory, 0, invLength); - if (tempInv.length > inventory.length) + if (tempInv.length > this.inventory.length) { - for (int i = inventory.length; i < tempInv.length; i++) + for (int i = this.inventory.length; i < tempInv.length; i++) { ItemStack stack = tempInv[i]; if (stack != null) { - float jumpX = random.nextFloat() * 0.8F + 0.1F; - float jumpY = random.nextFloat() * 0.8F + 0.1F; - float jumpZ = random.nextFloat() * 0.8F + 0.1F; + float jumpX = this.random.nextFloat() * 0.8F + 0.1F; + float jumpY = this.random.nextFloat() * 0.8F + 0.1F; + float jumpZ = this.random.nextFloat() * 0.8F + 0.1F; int offsetX = 0; int offsetY = 0; int offsetZ = 0; - switch (getTossDirection()) + switch (this.getTossDirection()) { case 0: // -y offsetY--; @@ -66,7 +67,7 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I while (stack.stackSize > 0) { - int itemSize = random.nextInt(21) + 10; + int itemSize = this.random.nextInt(21) + 10; if (itemSize > stack.stackSize) { @@ -74,8 +75,8 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I } stack.stackSize -= itemSize; - EntityItem entityitem = new EntityItem(worldObj, (double) ((float) pos.getX() + jumpX + offsetX), (double) ((float) pos.getY() + jumpY), - (double) ((float) pos.getZ() + jumpZ + offsetZ), new ItemStack(stack.getItem(), itemSize, stack.getItemDamage())); + EntityItem entityitem = new EntityItem(this.worldObj, (double) ((float) this.pos.getX() + jumpX + offsetX), (double) ((float) this.pos.getY() + jumpY), + (double) ((float) this.pos.getZ() + jumpZ + offsetZ), new ItemStack(stack.getItem(), itemSize, stack.getItemDamage())); if (stack.hasTagCompound()) { @@ -83,10 +84,10 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I } float offset = 0.05F; - entityitem.motionX = (double) ((float) random.nextGaussian() * offset); - entityitem.motionY = (double) ((float) random.nextGaussian() * offset + 0.2F); - entityitem.motionZ = (double) ((float) random.nextGaussian() * offset); - worldObj.spawnEntityInWorld(entityitem); + entityitem.motionX = (double) ((float) this.random.nextGaussian() * offset); + entityitem.motionY = (double) ((float) this.random.nextGaussian() * offset + 0.2F); + entityitem.motionZ = (double) ((float) this.random.nextGaussian() * offset); + this.worldObj.spawnEntityInWorld(entityitem); } } } @@ -94,8 +95,8 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I } } - public int getTossDirection () + public int getTossDirection() { - return getRenderDirection(); + return this.getRenderDirection(); } -} \ No newline at end of file +} diff --git a/src/mantle/blocks/abstracts/ExpandableInventoryLogic.java b/src/mantle/blocks/abstracts/ExpandableInventoryLogic.java index 62ffa6f..33e46db 100644 --- a/src/mantle/blocks/abstracts/ExpandableInventoryLogic.java +++ b/src/mantle/blocks/abstracts/ExpandableInventoryLogic.java @@ -1,14 +1,18 @@ package mantle.blocks.abstracts; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.world.World; import com.google.common.collect.Lists; -import net.minecraft.entity.player.*; -import net.minecraft.inventory.*; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.*; -import net.minecraft.util.BlockPos; -import net.minecraft.world.World; public abstract class ExpandableInventoryLogic extends InventoryLogic implements IInventory { @@ -19,82 +23,85 @@ public abstract class ExpandableInventoryLogic extends InventoryLogic implements } protected ArrayList inventory = Lists.newArrayList(); + protected String invName; @Override - public ItemStack getStackInSlot (int slot) + public ItemStack getStackInSlot(int slot) { - return slot < inventory.size() ? inventory.get(slot) : null; - } - - public boolean isStackInSlot (int slot) - { - return slot < inventory.size() && inventory.get(slot) != null; + return slot < this.inventory.size() ? this.inventory.get(slot) : null; } @Override - public int getSizeInventory () + public boolean isStackInSlot(int slot) { - return inventory.size(); + return slot < this.inventory.size() && this.inventory.get(slot) != null; } - public int getMaxSize () + @Override + public int getSizeInventory() + { + return this.inventory.size(); + } + + public int getMaxSize() { return 64; } @Override - public int getInventoryStackLimit () + public int getInventoryStackLimit() { return 64; } - public boolean canDropInventorySlot (int slot) + @Override + public boolean canDropInventorySlot(int slot) { return true; } @Override - public void setInventorySlotContents (int slot, ItemStack itemstack) + public void setInventorySlotContents(int slot, ItemStack itemstack) { - if (slot < inventory.size()) + if (slot < this.inventory.size()) { - inventory.set(slot, itemstack); + this.inventory.set(slot, itemstack); } - else if (slot == inventory.size()) + else if (slot == this.inventory.size()) { - inventory.add(itemstack); + this.inventory.add(itemstack); } - else if (slot < getMaxSize()) + else if (slot < this.getMaxSize()) { - inventory.ensureCapacity(slot); - inventory.set(slot, itemstack); + this.inventory.ensureCapacity(slot); + this.inventory.set(slot, itemstack); } else { return; } - if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) + if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) { - itemstack.stackSize = getInventoryStackLimit(); + itemstack.stackSize = this.getInventoryStackLimit(); } } @Override - public ItemStack decrStackSize (int slot, int quantity) + public ItemStack decrStackSize(int slot, int quantity) { - if (slot < inventory.size() && inventory.get(slot) != null) + if (slot < this.inventory.size() && this.inventory.get(slot) != null) { - if (inventory.get(slot).stackSize <= quantity) + if (this.inventory.get(slot).stackSize <= quantity) { - ItemStack stack = inventory.get(slot); - inventory.set(slot, null); + ItemStack stack = this.inventory.get(slot); + this.inventory.set(slot, null); return stack; } - ItemStack split = inventory.get(slot).splitStack(quantity); - if (inventory.get(slot).stackSize == 0) + ItemStack split = this.inventory.get(slot).splitStack(quantity); + if (this.inventory.get(slot).stackSize == 0) { - inventory.set(slot, null); + this.inventory.set(slot, null); } return split; } @@ -106,52 +113,58 @@ public abstract class ExpandableInventoryLogic extends InventoryLogic implements /* Supporting methods */ @Override - public boolean isUseableByPlayer (EntityPlayer entityplayer) + public boolean isUseableByPlayer(EntityPlayer entityplayer) { - if (worldObj.getTileEntity(pos) != this) + if (this.worldObj.getTileEntity(this.pos) != this) + { return false; - + } else - return entityplayer.getDistance((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D) <= 64D; + { + return entityplayer.getDistance((double) this.pos.getX() + 0.5D, (double) this.pos.getY() + 0.5D, (double) this.pos.getZ() + 0.5D) <= 64D; + } } - public abstract Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z); + @Override + public abstract Container getGuiContainer(InventoryPlayer inventoryplayer, World world, int x, int y, int z); /* NBT */ @Override - public void readFromNBT (NBTTagCompound tags) + public void readFromNBT(NBTTagCompound tags) { super.readFromNBT(tags); this.invName = tags.getString("InvName"); NBTTagList nbttaglist = tags.getTagList("Items", 9); - inventory = new ArrayList(); - inventory.ensureCapacity(nbttaglist.tagCount() > getMaxSize() ? getMaxSize() : nbttaglist.tagCount()); + this.inventory = new ArrayList(); + this.inventory.ensureCapacity(nbttaglist.tagCount() > this.getMaxSize() ? this.getMaxSize() : nbttaglist.tagCount()); for (int iter = 0; iter < nbttaglist.tagCount(); iter++) { NBTTagCompound tagList = nbttaglist.getCompoundTagAt(iter); byte slotID = tagList.getByte("Slot"); - if (slotID >= 0 && slotID < inventory.size()) + if (slotID >= 0 && slotID < this.inventory.size()) { - inventory.set(slotID, ItemStack.loadItemStackFromNBT(tagList)); + this.inventory.set(slotID, ItemStack.loadItemStackFromNBT(tagList)); } } } @Override - public void writeToNBT (NBTTagCompound tags) + public void writeToNBT(NBTTagCompound tags) { super.writeToNBT(tags); - if (invName != null) - tags.setString("InvName", invName); - NBTTagList nbttaglist = new NBTTagList(); - for (int iter = 0; iter < inventory.size(); iter++) + if (this.invName != null) { - if (inventory.get(iter) != null) + tags.setString("InvName", this.invName); + } + NBTTagList nbttaglist = new NBTTagList(); + for (int iter = 0; iter < this.inventory.size(); iter++) + { + if (this.inventory.get(iter) != null) { NBTTagCompound tagList = new NBTTagCompound(); tagList.setByte("Slot", (byte) iter); - inventory.get(iter).writeToNBT(tagList); + this.inventory.get(iter).writeToNBT(tagList); nbttaglist.appendTag(tagList); } } @@ -160,39 +173,46 @@ public abstract class ExpandableInventoryLogic extends InventoryLogic implements } /* Default implementations of hardly used methods */ - public ItemStack getStackInSlotOnClosing (int slot) + @Override + public ItemStack getStackInSlotOnClosing(int slot) { return null; } - public void openChest () + @Override + public void openChest() { } - public void closeChest () + @Override + public void closeChest() { } - protected abstract String getDefaultName (); + @Override + protected abstract String getDefaultName(); - public void setInvName (String name) + @Override + public void setInvName(String name) { this.invName = name; } - public String getInvName () + @Override + public String getInvName() { - return this.isInvNameLocalized() ? this.invName : getDefaultName(); + return this.isInvNameLocalized() ? this.invName : this.getDefaultName(); } - public boolean isInvNameLocalized () + @Override + public boolean isInvNameLocalized() { return this.invName != null && this.invName.length() > 0; } - public void cleanInventory () + public void cleanInventory() { - Iterator i1 = inventory.iterator(); + Iterator i1 = this.inventory.iterator(); while (i1.hasNext()) { if (i1.next() == null) @@ -203,18 +223,20 @@ public abstract class ExpandableInventoryLogic extends InventoryLogic implements } @Override - public boolean isItemValidForSlot (int slot, ItemStack itemstack) + public boolean isItemValidForSlot(int slot, ItemStack itemstack) { - if (slot < getSizeInventory()) + if (slot < this.getSizeInventory()) { - if (inventory.get(slot) == null || itemstack.stackSize + inventory.get(slot).stackSize <= getInventoryStackLimit()) + if (this.inventory.get(slot) == null || itemstack.stackSize + this.inventory.get(slot).stackSize <= this.getInventoryStackLimit()) + { return true; + } } else { - return slot < getMaxSize(); + return slot < this.getMaxSize(); } return false; } -} \ No newline at end of file +} diff --git a/src/mantle/blocks/abstracts/InventoryBlock.java b/src/mantle/blocks/abstracts/InventoryBlock.java index 9edc40c..140f2f8 100644 --- a/src/mantle/blocks/abstracts/InventoryBlock.java +++ b/src/mantle/blocks/abstracts/InventoryBlock.java @@ -2,31 +2,26 @@ package mantle.blocks.abstracts; import java.util.Random; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.renderer.EnumFaceDirection; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.relauncher.Side; import mantle.blocks.iface.IActiveLogic; import mantle.blocks.iface.IFacingLogic; import mantle.debug.DebugHelper; import mantle.debug.IDebuggable; -import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.BlockPos; -import net.minecraft.util.MathHelper; +import net.minecraft.util.EnumFacing; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.relauncher.Side; public abstract class InventoryBlock extends BlockContainer { @@ -38,24 +33,27 @@ public abstract class InventoryBlock extends BlockContainer } /* Logic backend */ - public TileEntity createNewTileEntity (World var1) + public TileEntity createNewTileEntity(World var1) { return null; } - public abstract TileEntity createNewTileEntity (World world, int metadata); + @Override + public abstract TileEntity createNewTileEntity(World world, int metadata); - public abstract Integer getGui (World world, int x, int y, int z, EntityPlayer entityplayer); + public abstract Integer getGui(World world, int x, int y, int z, EntityPlayer entityplayer); - public abstract Object getModInstance (); + public abstract Object getModInstance(); @Override - public boolean onBlockActivated (World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float clickX, float clickY, float clickZ) + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float clickX, float clickY, float clickZ) { if (player.isSneaking()) + { return false; + } - Integer integer = getGui(world, pos.getX(), pos.getY(), pos.getZ(), player); + Integer integer = this.getGui(world, pos.getX(), pos.getY(), pos.getZ(), player); if (integer == null || integer == -1) { return false; @@ -63,14 +61,16 @@ public abstract class InventoryBlock extends BlockContainer else { if (!world.isRemote) - player.openGui(getModInstance(), integer, world, pos.getX(), pos.getY(), pos.getZ()); + { + player.openGui(this.getModInstance(), integer, world, pos.getX(), pos.getY(), pos.getZ()); + } return true; } } /* Inventory */ @Override - public void breakBlock (World par1World, BlockPos pos, IBlockState meta) + public void breakBlock(World par1World, BlockPos pos, IBlockState meta) { TileEntity te = par1World.getTileEntity(pos); @@ -84,13 +84,13 @@ public abstract class InventoryBlock extends BlockContainer if (stack != null && logic.canDropInventorySlot(iter)) { - float jumpX = rand.nextFloat() * 0.8F + 0.1F; - float jumpY = rand.nextFloat() * 0.8F + 0.1F; - float jumpZ = rand.nextFloat() * 0.8F + 0.1F; + float jumpX = this.rand.nextFloat() * 0.8F + 0.1F; + float jumpY = this.rand.nextFloat() * 0.8F + 0.1F; + float jumpZ = this.rand.nextFloat() * 0.8F + 0.1F; while (stack.stackSize > 0) { - int itemSize = rand.nextInt(21) + 10; + int itemSize = this.rand.nextInt(21) + 10; if (itemSize > stack.stackSize) { @@ -107,9 +107,9 @@ public abstract class InventoryBlock extends BlockContainer } float offset = 0.05F; - entityitem.motionX = (double) ((float) rand.nextGaussian() * offset); - entityitem.motionY = (double) ((float) rand.nextGaussian() * offset + 0.2F); - entityitem.motionZ = (double) ((float) rand.nextGaussian() * offset); + entityitem.motionX = (double) ((float) this.rand.nextGaussian() * offset); + entityitem.motionY = (double) ((float) this.rand.nextGaussian() * offset + 0.2F); + entityitem.motionZ = (double) ((float) this.rand.nextGaussian() * offset); par1World.spawnEntityInWorld(entityitem); } } @@ -125,25 +125,26 @@ public abstract class InventoryBlock extends BlockContainer //This class does not have an actual block placed in the world @Override - public IBlockState onBlockPlaced (World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) + public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { this.side = side; return world.getBlockState(pos).getBlock().getStateFromMeta(meta); } @Override - @SuppressWarnings("deprecation") // TODO: Remove this when setDirection calls updated. - public void onBlockPlacedBy (World world, BlockPos pos, IBlockState state, EntityLivingBase entityliving, ItemStack stack) + @SuppressWarnings("deprecation") + // TODO: Remove this when setDirection calls updated. + public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entityliving, ItemStack stack) { TileEntity logic = world.getTileEntity(pos); if (logic instanceof IFacingLogic) { IFacingLogic direction = (IFacingLogic) logic; // TODO: Convert all setDirection calls to modern invokation, when that's ready. - if (side != null) + if (this.side != null) { - direction.setDirection(side, 0F, 0F, null); - side = null; + direction.setDirection(this.side, 0F, 0F, null); + this.side = null; } if (entityliving == null) { @@ -167,7 +168,7 @@ public abstract class InventoryBlock extends BlockContainer } @SuppressWarnings("unused") - public static boolean isActive (IBlockAccess world, BlockPos pos) + public static boolean isActive(IBlockAccess world, BlockPos pos) { TileEntity logic = world.getTileEntity(pos); if (logic instanceof IActiveLogic) @@ -177,16 +178,16 @@ public abstract class InventoryBlock extends BlockContainer return false; } - public int damageDropped (int meta) + public int damageDropped(int meta) { return meta; } /* IDebuggable */ @Override - public void onBlockClicked (World world, BlockPos pos, EntityPlayer player) + public void onBlockClicked(World world, BlockPos pos, EntityPlayer player) { - if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && player.getHeldItem() != null && player.getHeldItem().getItem() != null && player.getHeldItem().getItem() == Items.stick) + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && player.getHeldItem() != null && player.getHeldItem().getItem() != null && player.getHeldItem().getItem() == Items.stick) { TileEntity te = world.getTileEntity(pos); if (te instanceof IDebuggable) @@ -197,4 +198,4 @@ public abstract class InventoryBlock extends BlockContainer super.onBlockClicked(world, pos, player); } -} \ No newline at end of file +} diff --git a/src/mantle/blocks/abstracts/InventoryLogic.java b/src/mantle/blocks/abstracts/InventoryLogic.java index dc0a6e0..9bc1099 100644 --- a/src/mantle/blocks/abstracts/InventoryLogic.java +++ b/src/mantle/blocks/abstracts/InventoryLogic.java @@ -21,7 +21,9 @@ import net.minecraft.world.World; public abstract class InventoryLogic extends TileEntity implements IInventory, IDebuggable { protected ItemStack[] inventory; + protected String invName; + protected int stackSizeLimit; public InventoryLogic(int invSize) @@ -31,65 +33,65 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I public InventoryLogic(int invSize, int maxStackSize) { - inventory = new ItemStack[invSize]; - stackSizeLimit = maxStackSize; + this.inventory = new ItemStack[invSize]; + this.stackSizeLimit = maxStackSize; } /* Inventory management */ @Override - public ItemStack getStackInSlot (int slot) + public ItemStack getStackInSlot(int slot) { - return slot < inventory.length ? inventory[slot] : null; + return slot < this.inventory.length ? this.inventory[slot] : null; } - public boolean isStackInSlot (int slot) + public boolean isStackInSlot(int slot) { - return slot < inventory.length && inventory[slot] != null; + return slot < this.inventory.length && this.inventory[slot] != null; } @Override - public int getSizeInventory () + public int getSizeInventory() { - return inventory.length; + return this.inventory.length; } @Override - public int getInventoryStackLimit () + public int getInventoryStackLimit() { - return stackSizeLimit; + return this.stackSizeLimit; } - public boolean canDropInventorySlot (int slot) + public boolean canDropInventorySlot(int slot) { return true; } @Override - public void setInventorySlotContents (int slot, ItemStack itemstack) + public void setInventorySlotContents(int slot, ItemStack itemstack) { - inventory[slot] = itemstack; - if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) + this.inventory[slot] = itemstack; + if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) { - itemstack.stackSize = getInventoryStackLimit(); + itemstack.stackSize = this.getInventoryStackLimit(); } } @Override - public ItemStack decrStackSize (int slot, int quantity) + public ItemStack decrStackSize(int slot, int quantity) { - if (inventory[slot] != null) + if (this.inventory[slot] != null) { - if (inventory[slot].stackSize <= quantity) + if (this.inventory[slot].stackSize <= quantity) { - ItemStack stack = inventory[slot]; - inventory[slot] = null; + ItemStack stack = this.inventory[slot]; + this.inventory[slot] = null; return stack; } - ItemStack split = inventory[slot].splitStack(quantity); - if (inventory[slot].stackSize == 0) + ItemStack split = this.inventory[slot].splitStack(quantity); + if (this.inventory[slot].stackSize == 0) { - inventory[slot] = null; + this.inventory[slot] = null; } return split; } @@ -101,29 +103,32 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I /* Supporting methods */ @Override - public boolean isUseableByPlayer (EntityPlayer entityplayer) + public boolean isUseableByPlayer(EntityPlayer entityplayer) { - if (worldObj.getTileEntity(pos) != this) + if (this.worldObj.getTileEntity(this.pos) != this) + { return false; - + } else - return entityplayer.getDistance((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D) <= 64D; + { + return entityplayer.getDistance((double) this.pos.getX() + 0.5D, (double) this.pos.getY() + 0.5D, (double) this.pos.getZ() + 0.5D) <= 64D; + } } - public abstract Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z); + public abstract Container getGuiContainer(InventoryPlayer inventoryplayer, World world, int x, int y, int z); /* NBT */ @Override - public void readFromNBT (NBTTagCompound tags) + public void readFromNBT(NBTTagCompound tags) { super.readFromNBT(tags); - readInventoryFromNBT(tags); + this.readInventoryFromNBT(tags); } - public void readInventoryFromNBT (NBTTagCompound tags) + public void readInventoryFromNBT(NBTTagCompound tags) { - super.readFromNBT(tags); + super.readFromNBT(tags); NBTTagList nbttaglist = tags.getTagList("Items", 10); this.inventory = new ItemStack[this.getSizeInventory()]; @@ -142,31 +147,31 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I this.inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } - + //Not removed in case of things going terribly wrong -// super.readFromNBT(tags); -// this.invName = tags.getString("InvName"); -// NBTTagList nbttaglist = tags.getTagList("Items", 9); -// inventory = new ItemStack[getSizeInventory()]; -// for (int iter = 0; iter < nbttaglist.tagCount(); iter++) -// { -// NBTTagCompound tagList = (NBTTagCompound) nbttaglist.getCompoundTagAt(iter); -// byte slotID = tagList.getByte("Slot"); -// if (slotID >= 0 && slotID < inventory.length) -// { -// inventory[slotID] = ItemStack.loadItemStackFromNBT(tagList); -// } -// } + // super.readFromNBT(tags); + // this.invName = tags.getString("InvName"); + // NBTTagList nbttaglist = tags.getTagList("Items", 9); + // inventory = new ItemStack[getSizeInventory()]; + // for (int iter = 0; iter < nbttaglist.tagCount(); iter++) + // { + // NBTTagCompound tagList = (NBTTagCompound) nbttaglist.getCompoundTagAt(iter); + // byte slotID = tagList.getByte("Slot"); + // if (slotID >= 0 && slotID < inventory.length) + // { + // inventory[slotID] = ItemStack.loadItemStackFromNBT(tagList); + // } + // } } @Override - public void writeToNBT (NBTTagCompound tags) + public void writeToNBT(NBTTagCompound tags) { super.writeToNBT(tags); - writeInventoryToNBT(tags); + this.writeInventoryToNBT(tags); } - public void writeInventoryToNBT (NBTTagCompound tags) + public void writeInventoryToNBT(NBTTagCompound tags) { super.writeToNBT(tags); NBTTagList nbttaglist = new NBTTagList(); @@ -176,7 +181,7 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I if (this.inventory[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte)i); + nbttagcompound1.setByte("Slot", (byte) i); this.inventory[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } @@ -188,23 +193,23 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I { tags.setString("CustomName", this.invName); } - - //Not removed in case of things going terribly wrong -// if (invName != null) -// tags.setString("InvName", invName); -// NBTTagList nbttaglist = new NBTTagList(); -// for (int iter = 0; iter < inventory.length; iter++) -// { -// if (inventory[iter] != null) -// { -// NBTTagCompound tagList = new NBTTagCompound(); -// tagList.setByte("Slot", (byte) iter); -// inventory[iter].writeToNBT(tagList); -// nbttaglist.appendTag(tagList); -// } -// } -// -// tags.setTag("Items", nbttaglist); + + //Not removed in case of things going terribly wrong + // if (invName != null) + // tags.setString("InvName", invName); + // NBTTagList nbttaglist = new NBTTagList(); + // for (int iter = 0; iter < inventory.length; iter++) + // { + // if (inventory[iter] != null) + // { + // NBTTagCompound tagList = new NBTTagCompound(); + // tagList.setByte("Slot", (byte) iter); + // inventory[iter].writeToNBT(tagList); + // nbttaglist.appendTag(tagList); + // } + // } + // + // tags.setTag("Items", nbttaglist); } /* Cause of the heisenbug. Do not uncomment! */ @@ -212,75 +217,78 @@ public abstract class InventoryLogic extends TileEntity implements IInventory, I { super.readFromNBT(tags); } - + public void superWriteToNBT (NBTTagCompound tags) { super.writeToNBT(tags); }*/ /* Default implementations of hardly used methods */ - public ItemStack getStackInSlotOnClosing (int slot) + @Override + public ItemStack getStackInSlotOnClosing(int slot) { return null; } - public void openChest () + public void openChest() { } - public void closeChest () + public void closeChest() { } - protected abstract String getDefaultName (); + protected abstract String getDefaultName(); - public void setInvName (String name) + public void setInvName(String name) { this.invName = name; } - public String getInvName () + public String getInvName() { - return this.isInvNameLocalized() ? this.invName : getDefaultName(); + return this.isInvNameLocalized() ? this.invName : this.getDefaultName(); } public boolean hasCustomInventoryName() { - return isInvNameLocalized(); + return this.isInvNameLocalized(); } - - public boolean isInvNameLocalized () + + public boolean isInvNameLocalized() { return this.invName != null && this.invName.length() > 0; } @Override - public boolean isItemValidForSlot (int slot, ItemStack itemstack) + public boolean isItemValidForSlot(int slot, ItemStack itemstack) { - if (slot < getSizeInventory()) + if (slot < this.getSizeInventory()) { - if (inventory[slot] == null || itemstack.stackSize + inventory[slot].stackSize <= getInventoryStackLimit()) + if (this.inventory[slot] == null || itemstack.stackSize + this.inventory[slot].stackSize <= this.getInventoryStackLimit()) + { return true; + } } return false; } - public void placeBlock (EntityLivingBase entity, ItemStack stack) + public void placeBlock(EntityLivingBase entity, ItemStack stack) { } - public void removeBlock () + public void removeBlock() { } - + /* IDebuggable */ @Override - public DebugData getDebugInfo (EntityPlayer player) + public DebugData getDebugInfo(EntityPlayer player) { String[] strs = new String[1]; - strs[0] = "invName: " + invName + ", inventory.length: " + inventory.length + ", stackSizeLimit: " + stackSizeLimit; - return new DebugData(player, getClass(), strs); + strs[0] = "invName: " + this.invName + ", inventory.length: " + this.inventory.length + ", stackSizeLimit: " + this.stackSizeLimit; + return new DebugData(player, this.getClass(), strs); } -} \ No newline at end of file +} diff --git a/src/mantle/blocks/abstracts/InventorySlab.java b/src/mantle/blocks/abstracts/InventorySlab.java index bd39aa8..47869dd 100644 --- a/src/mantle/blocks/abstracts/InventorySlab.java +++ b/src/mantle/blocks/abstracts/InventorySlab.java @@ -25,66 +25,76 @@ public abstract class InventorySlab extends InventoryBlock /* Rendering */ @Override - public boolean isFullCube () + public boolean isFullCube() { return false; } @Override - public boolean isOpaqueCube () + public boolean isOpaqueCube() { return false; } @Override - public boolean shouldSideBeRendered (IBlockAccess world, BlockPos pos, EnumFacing side) + public boolean shouldSideBeRendered(IBlockAccess world, BlockPos pos, EnumFacing side) { if (side.getHorizontalIndex() > 1) + { return super.shouldSideBeRendered(world, pos, side); + } IBlockState iblockstate = world.getBlockState(pos); int meta = iblockstate.getBlock().getMetaFromState(iblockstate); boolean top = (meta | 8) == 1; if ((top && side == side.DOWN) || (!top && side == side.UP)) + { return true; + } return super.shouldSideBeRendered(world, pos, side); } @Override @SuppressWarnings("rawtypes") - public void addCollisionBoxesToList (World world, BlockPos pos, IBlockState state, AxisAlignedBB axisalignedbb, List arraylist, Entity entity) + public void addCollisionBoxesToList(World world, BlockPos pos, IBlockState state, AxisAlignedBB axisalignedbb, List arraylist, Entity entity) { - setBlockBoundsBasedOnState(world, pos); - super.addCollisionBoxesToList(world,pos ,state, axisalignedbb, arraylist, entity); + this.setBlockBoundsBasedOnState(world, pos); + super.addCollisionBoxesToList(world, pos, state, axisalignedbb, arraylist, entity); } - public void setBlockBoundsForItemRender () + @Override + public void setBlockBoundsForItemRender() { - setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F); + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F); } - public void setBlockBoundsBasedOnState (IBlockAccess world, BlockPos pos, IBlockState state) + public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos, IBlockState state) { IBlockState iblockstate = world.getBlockState(pos); int meta = iblockstate.getBlock().getMetaFromState(iblockstate) / 8; float minY = meta == 1 ? 0.5F : 0.0F; float maxY = meta == 1 ? 1.0F : 0.5F; - setBlockBounds(0.0F, minY, 0F, 1.0F, maxY, 1.0F); + this.setBlockBounds(0.0F, minY, 0F, 1.0F, maxY, 1.0F); } - public int onBlockPlaced (World par1World, int blockX, int blockY, int blockZ, int side, float clickX, float clickY, float clickZ, int metadata) + public int onBlockPlaced(World par1World, int blockX, int blockY, int blockZ, int side, float clickX, float clickY, float clickZ, int metadata) { if (side == 1) + { return metadata; + } if (side == 0 || clickY >= 0.5F) + { return metadata | 8; + } return metadata; } - public int damageDropped (int meta) + @Override + public int damageDropped(int meta) { return meta % 8; } -} \ No newline at end of file +} diff --git a/src/mantle/blocks/abstracts/ItemBlockVariants.java b/src/mantle/blocks/abstracts/ItemBlockVariants.java index e295195..20cd084 100644 --- a/src/mantle/blocks/abstracts/ItemBlockVariants.java +++ b/src/mantle/blocks/abstracts/ItemBlockVariants.java @@ -7,27 +7,27 @@ import net.minecraft.item.ItemStack; public class ItemBlockVariants extends ItemBlock { - private final IBlockWithVariants variantBlock; + private final IBlockWithVariants variantBlock; - public ItemBlockVariants(Block block) - { - super(block); + public ItemBlockVariants(Block block) + { + super(block); - this.variantBlock = (IBlockWithVariants) block; - this.setMaxDamage(0); - this.setHasSubtypes(true); - } + this.variantBlock = (IBlockWithVariants) block; + this.setMaxDamage(0); + this.setHasSubtypes(true); + } - @Override - public int getMetadata(int damage) - { - return damage; - } + @Override + public int getMetadata(int damage) + { + return damage; + } - @Override - public String getUnlocalizedName(ItemStack stack) - { - return super.getUnlocalizedName() + "." + this.variantBlock.getVariantNameFromStack(stack); - } + @Override + public String getUnlocalizedName(ItemStack stack) + { + return super.getUnlocalizedName() + "." + this.variantBlock.getVariantNameFromStack(stack); + } } diff --git a/src/mantle/blocks/abstracts/MultiItemBlock.java b/src/mantle/blocks/abstracts/MultiItemBlock.java index e100405..e515bf6 100644 --- a/src/mantle/blocks/abstracts/MultiItemBlock.java +++ b/src/mantle/blocks/abstracts/MultiItemBlock.java @@ -7,7 +7,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; /** - * + * * @author progwml6 * base class for itemBlocks with different unlocalized names based on metadata */ @@ -15,17 +15,24 @@ import net.minecraft.util.MathHelper; public class MultiItemBlock extends ItemBlock { private String blockType[]; + private String unlocalizedName; + private String append; + private int specialIndex[] = { -1, -1 }; public MultiItemBlock(Block b, String itemBlockUnlocalizedName, String[] blockTypes) { super(b); if (itemBlockUnlocalizedName.isEmpty()) + { this.unlocalizedName = super.getUnlocalizedName(); + } else + { this.unlocalizedName = itemBlockUnlocalizedName; + } this.blockType = blockTypes; this.append = ""; } @@ -38,33 +45,37 @@ public class MultiItemBlock extends ItemBlock this.append = "." + appendToEnd; } - public void setSpecialIndex (int clampIndex, int stringBuilderIndex) + public void setSpecialIndex(int clampIndex, int stringBuilderIndex) { - specialIndex[0] = clampIndex; - specialIndex[1] = stringBuilderIndex; + this.specialIndex[0] = clampIndex; + this.specialIndex[1] = stringBuilderIndex; } - public int getMetadata (int meta) + @Override + public int getMetadata(int meta) { return meta; } - public String getUnlocalizedName (ItemStack itemstack) + @Override + public String getUnlocalizedName(ItemStack itemstack) { - int pos = MathHelper.clamp_int(itemstack.getItemDamage(), 0, (specialIndex[0] > -1) ? specialIndex[0] : (blockType.length - 1)); - int sbIndex = (specialIndex[1] > -1) ? pos : (specialIndex[1] - pos); + int pos = MathHelper.clamp_int(itemstack.getItemDamage(), 0, (this.specialIndex[0] > -1) ? this.specialIndex[0] : (this.blockType.length - 1)); + int sbIndex = (this.specialIndex[1] > -1) ? pos : (this.specialIndex[1] - pos); if (sbIndex < 0) + { sbIndex = -1 * sbIndex; + } try { - return (new StringBuilder()).append(unlocalizedName).append(".").append(blockType[sbIndex - 1]).append(append).toString(); + return (new StringBuilder()).append(this.unlocalizedName).append(".").append(this.blockType[sbIndex - 1]).append(this.append).toString(); } catch (ArrayIndexOutOfBoundsException ex) { logger.warn("[MultiItemBlock] Caught array index error in getUnlocalizedName: " + ex.getMessage()); - logger.warn("[MultiItemBlock] Returning unlocalized name: " + getUnlocalizedName()); - return getUnlocalizedName(); + logger.warn("[MultiItemBlock] Returning unlocalized name: " + this.getUnlocalizedName()); + return this.getUnlocalizedName(); } } diff --git a/src/mantle/blocks/abstracts/MultiServantLogic.java b/src/mantle/blocks/abstracts/MultiServantLogic.java index 92de706..c157281 100644 --- a/src/mantle/blocks/abstracts/MultiServantLogic.java +++ b/src/mantle/blocks/abstracts/MultiServantLogic.java @@ -19,187 +19,196 @@ import net.minecraft.world.World; public class MultiServantLogic extends TileEntity implements IServantLogic, IDebuggable { boolean hasMaster; + BlockPos master; + Block masterBlock; + IBlockState state; - public boolean canUpdate () + public boolean canUpdate() { return false; } - public boolean getHasMaster () + public boolean getHasMaster() { - return hasMaster; + return this.hasMaster; } - public boolean hasValidMaster () + public boolean hasValidMaster() { - if (!hasMaster) + if (!this.hasMaster) + { return false; + } - if (worldObj.getBlockState(master).getBlock() == masterBlock && worldObj.getBlockState(master) == state) + if (this.worldObj.getBlockState(this.master).getBlock() == this.masterBlock && this.worldObj.getBlockState(this.master) == this.state) + { return true; - + } else { - hasMaster = false; - master = null; + this.hasMaster = false; + this.master = null; return false; } } - public BlockPos getMasterPosition () + @Override + public BlockPos getMasterPosition() { - return master; + return this.master; } - public void overrideMaster (BlockPos pos) + public void overrideMaster(BlockPos pos) { - hasMaster = true; - master = pos; - state = worldObj.getBlockState(master); - masterBlock = state.getBlock(); + this.hasMaster = true; + this.master = pos; + this.state = this.worldObj.getBlockState(this.master); + this.masterBlock = this.state.getBlock(); } - public void removeMaster () + public void removeMaster() { - hasMaster = false; - master = null; - masterBlock = null; - state = null; + this.hasMaster = false; + this.master = null; + this.masterBlock = null; + this.state = null; } @Override - public boolean setPotentialMaster (IMasterLogic master, World w, BlockPos pos) + public boolean setPotentialMaster(IMasterLogic master, World w, BlockPos pos) { - return !hasMaster; + return !this.hasMaster; } @Deprecated - public boolean verifyMaster (IMasterLogic logic, BlockPos pos) + public boolean verifyMaster(IMasterLogic logic, BlockPos pos) { - return master.equals(pos) && worldObj.getBlockState(pos) == state && worldObj.getBlockState(pos).getBlock() == masterBlock; + return this.master.equals(pos) && this.worldObj.getBlockState(pos) == this.state && this.worldObj.getBlockState(pos).getBlock() == this.masterBlock; } @Override - public boolean verifyMaster (IMasterLogic logic, World world, BlockPos pos) + public boolean verifyMaster(IMasterLogic logic, World world, BlockPos pos) { - if (hasMaster) + if (this.hasMaster) { - return hasValidMaster(); + return this.hasValidMaster(); } else { - overrideMaster(pos); + this.overrideMaster(pos); return true; } } @Override - public void invalidateMaster (IMasterLogic master, World w, BlockPos pos) + public void invalidateMaster(IMasterLogic master, World w, BlockPos pos) { - hasMaster = false; + this.hasMaster = false; master = null; } - public void notifyMasterOfChange () + @Override + public void notifyMasterOfChange() { - if (hasValidMaster()) + if (this.hasValidMaster()) { - IMasterLogic logic = (IMasterLogic) worldObj.getTileEntity(pos); - logic.notifyChange(this, pos); + IMasterLogic logic = (IMasterLogic) this.worldObj.getTileEntity(this.pos); + logic.notifyChange(this, this.pos); } } - public void readCustomNBT (NBTTagCompound tags) + public void readCustomNBT(NBTTagCompound tags) { - hasMaster = tags.getBoolean("TiedToMaster"); - if (hasMaster) + this.hasMaster = tags.getBoolean("TiedToMaster"); + if (this.hasMaster) { int xCenter = tags.getInteger("xCenter"); int yCenter = tags.getInteger("yCenter"); int zCenter = tags.getInteger("zCenter"); - master = new BlockPos(xCenter, yCenter, zCenter); - masterBlock = BlockUtils.getBlockFromUniqueName(tags.getString("MasterBlockName")); + this.master = new BlockPos(xCenter, yCenter, zCenter); + this.masterBlock = BlockUtils.getBlockFromUniqueName(tags.getString("MasterBlockName")); // TODO: Make this a byte. - state = Block.getStateById(tags.getInteger("masterState")); + this.state = Block.getStateById(tags.getInteger("masterState")); } } - public void writeCustomNBT (NBTTagCompound tags) + public void writeCustomNBT(NBTTagCompound tags) { - tags.setBoolean("TiedToMaster", hasMaster); - if (hasMaster) + tags.setBoolean("TiedToMaster", this.hasMaster); + if (this.hasMaster) { - tags.setInteger("xCenter", master.getX()); - tags.setInteger("yCenter", master.getY()); - tags.setInteger("zCenter", master.getZ()); - tags.setString("MasterBlockName", BlockUtils.getUniqueName(masterBlock)); + tags.setInteger("xCenter", this.master.getX()); + tags.setInteger("yCenter", this.master.getY()); + tags.setInteger("zCenter", this.master.getZ()); + tags.setString("MasterBlockName", BlockUtils.getUniqueName(this.masterBlock)); // TODO: Make this a byte. - tags.setInteger("masterState", Block.getStateId(state)); + tags.setInteger("masterState", Block.getStateId(this.state)); } } @Override - public void readFromNBT (NBTTagCompound tags) + public void readFromNBT(NBTTagCompound tags) { super.readFromNBT(tags); - readCustomNBT(tags); + this.readCustomNBT(tags); } @Override - public void writeToNBT (NBTTagCompound tags) + public void writeToNBT(NBTTagCompound tags) { super.writeToNBT(tags); - writeCustomNBT(tags); + this.writeCustomNBT(tags); } /* Packets */ @Override - public Packet getDescriptionPacket () + public Packet getDescriptionPacket() { NBTTagCompound tag = new NBTTagCompound(); - writeCustomNBT(tag); - return new S35PacketUpdateTileEntity(pos, 1, tag); + this.writeCustomNBT(tag); + return new S35PacketUpdateTileEntity(this.pos, 1, tag); } @Override - public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet) + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { - readCustomNBT(packet.getNbtCompound()); - worldObj.notifyLightSet(pos); - worldObj.markBlockForUpdate(pos); + this.readCustomNBT(packet.getNbtCompound()); + this.worldObj.notifyLightSet(this.pos); + this.worldObj.markBlockForUpdate(this.pos); } /* IDebuggable */ @Override - public DebugData getDebugInfo (EntityPlayer player) + public DebugData getDebugInfo(EntityPlayer player) { String[] strs = new String[2]; - strs[0] = "Location: x" + pos.getX() + ", y" + pos.getY() + ", z" + pos.getZ(); - if (hasMaster) + strs[0] = "Location: x" + this.pos.getX() + ", y" + this.pos.getY() + ", z" + this.pos.getZ(); + if (this.hasMaster) { - strs[1] = "masterBlock: " + masterBlock.toString() + ", masterMeat: " + state.toString(); + strs[1] = "masterBlock: " + this.masterBlock.toString() + ", masterMeat: " + this.state.toString(); } else { strs[1] = "No active master."; } - return new DebugData(player, getClass(), strs); + return new DebugData(player, this.getClass(), strs); } - public World getWorld () + @Override + public World getWorld() { - return worldObj; + return this.worldObj; } @Deprecated - public boolean setMaster (BlockPos pos) + public boolean setMaster(BlockPos pos) { - if (!hasMaster || worldObj.getBlockState(master) != state || (worldObj.getBlockState(master).getBlock() != masterBlock)) + if (!this.hasMaster || this.worldObj.getBlockState(this.master) != this.state || (this.worldObj.getBlockState(this.master).getBlock() != this.masterBlock)) { - overrideMaster(pos); + this.overrideMaster(pos); return true; } else diff --git a/src/mantle/blocks/iface/IActiveLogic.java b/src/mantle/blocks/iface/IActiveLogic.java index c670f8d..51e7e5c 100644 --- a/src/mantle/blocks/iface/IActiveLogic.java +++ b/src/mantle/blocks/iface/IActiveLogic.java @@ -7,7 +7,7 @@ package mantle.blocks.iface; */ public interface IActiveLogic { - public boolean getActive (); + public boolean getActive(); - public void setActive (boolean flag); + public void setActive(boolean flag); } diff --git a/src/mantle/blocks/iface/ICrop.java b/src/mantle/blocks/iface/ICrop.java index da0b3fb..9473de2 100644 --- a/src/mantle/blocks/iface/ICrop.java +++ b/src/mantle/blocks/iface/ICrop.java @@ -1,6 +1,5 @@ package mantle.blocks.iface; - import java.util.Collections; import java.util.List; @@ -24,11 +23,11 @@ public interface ICrop * @param type * @return A list of items harvested. If no items are returned, NO_YIELD should be passed. */ - public List harvestCrop (IBlockAccess world, BlockPos pos, HarvestType type); + public List harvestCrop(IBlockAccess world, BlockPos pos, HarvestType type); - public boolean isFullyGrown (IBlockAccess world, BlockPos pos); + public boolean isFullyGrown(IBlockAccess world, BlockPos pos); - public boolean hasYield (IBlockAccess world, BlockPos pos); + public boolean hasYield(IBlockAccess world, BlockPos pos); - public void growthTick (IBlockAccess world, BlockPos pos); + public void growthTick(IBlockAccess world, BlockPos pos); } diff --git a/src/mantle/blocks/iface/IFacingLogic.java b/src/mantle/blocks/iface/IFacingLogic.java index a9667ed..ae1c76d 100644 --- a/src/mantle/blocks/iface/IFacingLogic.java +++ b/src/mantle/blocks/iface/IFacingLogic.java @@ -11,11 +11,10 @@ import net.minecraft.util.EnumFacing; public interface IFacingLogic { - public byte getRenderDirection (); + public byte getRenderDirection(); - public EnumFacing getForgeDirection (); + public EnumFacing getForgeDirection(); - - public void setDirection(EnumFacing facing, float yaw, float pitch, EntityLivingBase player); + public void setDirection(EnumFacing facing, float yaw, float pitch, EntityLivingBase player); } diff --git a/src/mantle/blocks/iface/IMasterLogic.java b/src/mantle/blocks/iface/IMasterLogic.java index cd3acca..9a9e690 100644 --- a/src/mantle/blocks/iface/IMasterLogic.java +++ b/src/mantle/blocks/iface/IMasterLogic.java @@ -5,8 +5,8 @@ import net.minecraft.util.BlockPos; public interface IMasterLogic { /** Called when servants change their state - * + * * @param pos servant position */ - public void notifyChange (IServantLogic servant, BlockPos pos); + public void notifyChange(IServantLogic servant, BlockPos pos); } diff --git a/src/mantle/blocks/iface/IMasterNode.java b/src/mantle/blocks/iface/IMasterNode.java index 1906f92..f33b884 100644 --- a/src/mantle/blocks/iface/IMasterNode.java +++ b/src/mantle/blocks/iface/IMasterNode.java @@ -2,7 +2,7 @@ package mantle.blocks.iface; public interface IMasterNode extends IMasterLogic, IServantLogic { - public boolean isCurrentlyMaster (); + public boolean isCurrentlyMaster(); - public boolean isEquivalentMaster (IMasterLogic master); + public boolean isEquivalentMaster(IMasterLogic master); } diff --git a/src/mantle/blocks/iface/IServantLogic.java b/src/mantle/blocks/iface/IServantLogic.java index 4ca6e86..aeaf726 100644 --- a/src/mantle/blocks/iface/IServantLogic.java +++ b/src/mantle/blocks/iface/IServantLogic.java @@ -5,37 +5,37 @@ import net.minecraft.world.World; public interface IServantLogic { - public BlockPos getMasterPosition (); + public BlockPos getMasterPosition(); /** The block should already have a valid master */ - public void notifyMasterOfChange (); + public void notifyMasterOfChange(); /** Checks if this block can be tied to this master - * + * * @param master * @param world the world of master * @param pos position of master * @return whether the servant can be tied to this master */ - public boolean setPotentialMaster (IMasterLogic master, World world, BlockPos pos); + public boolean setPotentialMaster(IMasterLogic master, World world, BlockPos pos); /** Used to set and verify that this is the block's master - * + * * @param master - * @param world + * @param world * @param pos position of master * @return Is this block tied to this master? */ - public boolean verifyMaster (IMasterLogic master, World world, BlockPos pos); + public boolean verifyMaster(IMasterLogic master, World world, BlockPos pos); /** Exactly what it says on the tin - * + * * @param master - * @param world + * @param world * @param pos position of master */ - public void invalidateMaster (IMasterLogic master, World world, BlockPos pos); + public void invalidateMaster(IMasterLogic master, World world, BlockPos pos); } diff --git a/src/mantle/blocks/util/IBlockWithVariants.java b/src/mantle/blocks/util/IBlockWithVariants.java index dc9458f..4c56312 100644 --- a/src/mantle/blocks/util/IBlockWithVariants.java +++ b/src/mantle/blocks/util/IBlockWithVariants.java @@ -4,5 +4,5 @@ import net.minecraft.item.ItemStack; public interface IBlockWithVariants { - String getVariantNameFromStack(ItemStack stack); -} \ No newline at end of file + String getVariantNameFromStack(ItemStack stack); +} diff --git a/src/mantle/books/BookData.java b/src/mantle/books/BookData.java index 4fd63f4..09fa53e 100644 --- a/src/mantle/books/BookData.java +++ b/src/mantle/books/BookData.java @@ -8,23 +8,32 @@ import org.w3c.dom.Document; public class BookData { public String unlocalizedName = ""; + public String toolTip = ""; + public String modID = ""; + public ResourceLocation leftImage = new ResourceLocation("mantle", "textures/gui/bookleft.png"); + public ResourceLocation rightImage = new ResourceLocation("mantle", "textures/gui/bookright.png"); + public ResourceLocation itemImage = new ResourceLocation("mantle", "textures/items/mantlebook_blue.png"); + public Document doc = ManualReader.readManual("/assets/mantle/manuals/test.xml"); + //font can be left null if so, the default from mantle will be used public FontRenderer font; + public Boolean isTranslatable = false; + public boolean isFromZip = false; - public Document getDoc () + public Document getDoc() { return this.doc; } - public String getFullUnlocalizedName () + public String getFullUnlocalizedName() { return this.modID + ":" + this.unlocalizedName; } diff --git a/src/mantle/books/BookDataStore.java b/src/mantle/books/BookDataStore.java index de7f13f..7129607 100644 --- a/src/mantle/books/BookDataStore.java +++ b/src/mantle/books/BookDataStore.java @@ -8,44 +8,50 @@ import com.google.common.collect.Lists; public class BookDataStore { private static HashBiMap data = HashBiMap.create(); + private static HashBiMap intMap = HashBiMap.create(); - private static List zipBooks= Lists.newArrayList(); - public static void addBook (BookData bd) + + private static List zipBooks = Lists.newArrayList(); + + public static void addBook(BookData bd) { int insertOrder = data.size(); data.put(bd.getFullUnlocalizedName(), bd); intMap.put(insertOrder, bd.getFullUnlocalizedName()); - if(bd.isFromZip) + if (bd.isFromZip) + { zipBooks.add(bd.getFullUnlocalizedName()); - + } + } - public static BookData getBookfromName (String ModID, String unlocalizedName) + public static BookData getBookfromName(String ModID, String unlocalizedName) { return getBookFromName(ModID + ":" + unlocalizedName); } - public static BookData getBookFromName (String fullBookName) + public static BookData getBookFromName(String fullBookName) { return data.get(fullBookName); } - public static BookData getBookfromID (int bookIDNum) + public static BookData getBookfromID(int bookIDNum) { return data.get(intMap.get(bookIDNum)); } - public static int getIDFromName (String FullUnlocalizedName) + public static int getIDFromName(String FullUnlocalizedName) { return intMap.inverse().get(FullUnlocalizedName); } - public static int getIDFromBook (BookData b) + public static int getIDFromBook(BookData b) { return getIDFromName(data.inverse().get(b)); } - - public static List getZipBooks(){ + + public static List getZipBooks() + { return zipBooks; } } diff --git a/src/mantle/books/ManualReader.java b/src/mantle/books/ManualReader.java index 5e9a204..6b2ac49 100644 --- a/src/mantle/books/ManualReader.java +++ b/src/mantle/books/ManualReader.java @@ -13,7 +13,7 @@ import org.w3c.dom.Document; public class ManualReader { - public static Document readManual (String location) + public static Document readManual(String location) { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); @@ -29,7 +29,8 @@ public class ManualReader return null; } } - public static Document readManual (InputStream is, String filenameOrLocation) + + public static Document readManual(InputStream is, String filenameOrLocation) { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); diff --git a/src/mantle/books/client/BookImage.java b/src/mantle/books/client/BookImage.java index 8482568..62c42b4 100644 --- a/src/mantle/books/client/BookImage.java +++ b/src/mantle/books/client/BookImage.java @@ -3,12 +3,16 @@ package mantle.books.client; import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.util.ResourceLocation; -public class BookImage { +public class BookImage +{ public int height, width; + public DynamicTexture texture; + public ResourceLocation resource; - public BookImage(int width, int height, DynamicTexture texture, ResourceLocation resource) { + public BookImage(int width, int height, DynamicTexture texture, ResourceLocation resource) + { this.width = width; this.height = height; this.texture = texture; diff --git a/src/mantle/books/external/BookIS.java b/src/mantle/books/external/BookIS.java index f0ecd76..e38af7f 100644 --- a/src/mantle/books/external/BookIS.java +++ b/src/mantle/books/external/BookIS.java @@ -14,9 +14,9 @@ public class BookIS public int stackSize; - public int getStackSize () + public int getStackSize() { - return stackSize >= 0 ? stackSize : 1; + return this.stackSize >= 0 ? this.stackSize : 1; } } diff --git a/src/mantle/books/external/BookLoad.java b/src/mantle/books/external/BookLoad.java index 1c0bc0c..6ef315c 100644 --- a/src/mantle/books/external/BookLoad.java +++ b/src/mantle/books/external/BookLoad.java @@ -4,17 +4,26 @@ import com.google.gson.JsonObject; public class BookLoad { -public String unlocalizedName; -public String tooltip; -public boolean translatable; -public String BookIcon; -public String LeftImage; -public String rightImage; -public BookIS[] registerItemStacks; -public JsonObject[] smallRecipes; -public JsonObject[] largeRecipes; -public JsonObject[] furnaceRecipes; -public JsonObject[] manualIcons; + public String unlocalizedName; + public String tooltip; + + public boolean translatable; + + public String BookIcon; + + public String LeftImage; + + public String rightImage; + + public BookIS[] registerItemStacks; + + public JsonObject[] smallRecipes; + + public JsonObject[] largeRecipes; + + public JsonObject[] furnaceRecipes; + + public JsonObject[] manualIcons; } diff --git a/src/mantle/books/external/ZipLoader.java b/src/mantle/books/external/ZipLoader.java index 97c663c..3bc19bb 100644 --- a/src/mantle/books/external/ZipLoader.java +++ b/src/mantle/books/external/ZipLoader.java @@ -1,5 +1,7 @@ package mantle.books.external; +import static mantle.lib.CoreRepo.logger; + import java.awt.image.BufferedImage; import java.io.File; import java.util.Enumeration; @@ -9,7 +11,6 @@ import java.util.zip.ZipFile; import javax.imageio.ImageIO; -import static mantle.lib.CoreRepo.logger; import mantle.books.BookData; import mantle.books.BookDataStore; import mantle.books.ManualReader; @@ -21,8 +22,9 @@ import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.JsonToNBT; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.relauncher.Side; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; @@ -33,14 +35,11 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.relauncher.Side; - public class ZipLoader { public static Map loadedIS = Maps.newHashMap(); - public static BookData loadZip (File f) + public static BookData loadZip(File f) { BookLoad bl; String flName = ""; @@ -187,9 +186,9 @@ public class ZipLoader b.isTranslatable = bl.translatable; b.leftImage = bl.LeftImage == null ? new ResourceLocation("mantle", "textures/gui/bookleft.png") : MantleClientRegistry.getBookImageFromCache(bl.LeftImage).resource; b.rightImage = bl.rightImage == null ? new ResourceLocation("mantle", "textures/gui/bookright.png") - : MantleClientRegistry.getBookImageFromCache(bl.rightImage).resource; + : MantleClientRegistry.getBookImageFromCache(bl.rightImage).resource; b.itemImage = bl.BookIcon == null ? new ResourceLocation("mantle", "textures/items/mantlebook_blue.png") - : MantleClientRegistry.getBookImageFromCache(bl.BookIcon).resource; + : MantleClientRegistry.getBookImageFromCache(bl.BookIcon).resource; b.isFromZip = true; BookDataStore.addBook(b); } @@ -226,12 +225,12 @@ public class ZipLoader return null; } - public static boolean isImage (String ext) + public static boolean isImage(String ext) { return ext.equalsIgnoreCase("png"); } - public static ItemStack[] getISArray (JsonArray a) + public static ItemStack[] getISArray(JsonArray a) { ItemStack[] is = new ItemStack[a.size()]; ItemStack loadedStack; diff --git a/src/mantle/client/MProxyClient.java b/src/mantle/client/MProxyClient.java index e0d1635..dc13871 100644 --- a/src/mantle/client/MProxyClient.java +++ b/src/mantle/client/MProxyClient.java @@ -20,10 +20,8 @@ import mantle.client.pages.SidebarPage; import mantle.client.pages.TextPage; import mantle.client.pages.TitlePage; import mantle.common.MProxyCommon; -import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; public class MProxyClient extends MProxyCommon @@ -32,29 +30,31 @@ public class MProxyClient extends MProxyCommon public static final String MINECRAFT_ASCII_PATH = "minecraft:textures/font/ascii.png"; /* Registers any rendering code. */ - public void registerRenderer () + @Override + public void registerRenderer() { ModelHelper.registerItem(Mantle.mantleBook, "mantleBook"); } public static Map> pageClasses = new HashMap>(); - public static void registerManualPage (String type, Class clazz) + public static void registerManualPage(String type, Class clazz) { pageClasses.put(type, clazz); } - public static Class getPageClass (String type) + public static Class getPageClass(String type) { return pageClasses.get(type); } - public void readManuals () + @Override + public void readManuals() { - initManualPages(); + this.initManualPages(); } - void initManualPages () + void initManualPages() { MProxyClient.registerManualPage("crafting", CraftingPage.class); MProxyClient.registerManualPage("picture", PicturePage.class); @@ -69,17 +69,23 @@ public class MProxyClient extends MProxyCommon } @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 (ID == manualGuiID) { ItemStack stack = player.getCurrentEquippedItem(); if (stack == null) + { logger.error("Null stack in book."); + } if (stack != null && stack.getItem() == null) + { logger.error("Null item in book."); + } if (stack != null && stack.getItem() != null && stack.getItem().getUnlocalizedName() == null) + { logger.error("Null unlocalized name in book."); + } else { return new GuiManual(stack, MProxyClient.getBookDataFromStack(stack)); @@ -88,7 +94,7 @@ public class MProxyClient extends MProxyCommon return null; } - private static BookData getBookDataFromStack (ItemStack stack) + private static BookData getBookDataFromStack(ItemStack stack) { return BookDataStore.getBookFromName(stack.getItem().getUnlocalizedName(stack)); } diff --git a/src/mantle/client/ModelHelper.java b/src/mantle/client/ModelHelper.java index d8c031f..aca485c 100644 --- a/src/mantle/client/ModelHelper.java +++ b/src/mantle/client/ModelHelper.java @@ -9,7 +9,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) -public class ModelHelper +public class ModelHelper { public static void registerItem(Item item, int metadata, String itemName) { @@ -31,4 +31,4 @@ public class ModelHelper { registerItem(item, 0, itemName); } -} \ No newline at end of file +} diff --git a/src/mantle/client/ModelVariant.java b/src/mantle/client/ModelVariant.java index bee1882..6a070fe 100644 --- a/src/mantle/client/ModelVariant.java +++ b/src/mantle/client/ModelVariant.java @@ -31,7 +31,7 @@ public class ModelVariant Item item = Item.getItemFromBlock(block); this.registerItemModel(item, variant.getName(), variant.getMeta()); - ModelBakery.addVariantName(item, (MOD_ID + ":") + variant.getName()); + ModelBakery.addVariantName(item, (this.MOD_ID + ":") + variant.getName()); } } @@ -58,6 +58,6 @@ public class ModelVariant private ModelResourceLocation getModelResource(String name, String type) { - return new ModelResourceLocation((MOD_ID + ":") + name, type); + return new ModelResourceLocation((this.MOD_ID + ":") + name, type); } } diff --git a/src/mantle/client/gui/GuiManual.java b/src/mantle/client/gui/GuiManual.java index d6a4214..b3f8aa1 100644 --- a/src/mantle/client/gui/GuiManual.java +++ b/src/mantle/client/gui/GuiManual.java @@ -10,6 +10,8 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import org.lwjgl.opengl.GL11; import org.w3c.dom.Document; @@ -17,28 +19,37 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - @SideOnly(Side.CLIENT) public class GuiManual extends GuiScreen { ItemStack itemstackBook; + Document manual; + public RenderItem renderitem = Minecraft.getMinecraft().getRenderItem(); + int bookImageWidth = 206; + int bookImageHeight = 200; + int bookTotalPages = 1; + int currentPage; + int maxPages; + BookData bData; private TurnPageButton buttonNextPage; + private TurnPageButton buttonPreviousPage; + private static ResourceLocation bookRight;// = new ResourceLocation("mantle", "textures/gui/bookright.png"); + private static ResourceLocation bookLeft;// = new ResourceLocation("mantle", "textures/gui/bookleft.png"); BookPage pageLeft; + BookPage pageRight; public FontRenderer fonts = Minecraft.getMinecraft().fontRendererObj; @@ -47,10 +58,12 @@ public class GuiManual extends GuiScreen { this.mc = Minecraft.getMinecraft(); this.itemstackBook = stack; - currentPage = 0; //Stack page - manual = data.getDoc(); + this.currentPage = 0; //Stack page + this.manual = data.getDoc(); if (data.font != null) + { this.fonts = data.font; + } bookLeft = data.leftImage; bookRight = data.rightImage; this.bData = data; @@ -69,50 +82,64 @@ public class GuiManual extends GuiScreen this.initGui(); }*/ + @Override @SuppressWarnings("unchecked") - public void initGui () + public void initGui() { - maxPages = manual.getElementsByTagName("page").getLength(); - updateText(); + this.maxPages = this.manual.getElementsByTagName("page").getLength(); + this.updateText(); int xPos = (this.width) / 2; //TODO Width? //TODO buttonList - this.buttonList.add(this.buttonNextPage = new TurnPageButton(1, xPos + bookImageWidth - 50, 180, true, bData)); - this.buttonList.add(this.buttonPreviousPage = new TurnPageButton(2, xPos - bookImageWidth + 24, 180, false, bData)); + this.buttonList.add(this.buttonNextPage = new TurnPageButton(1, xPos + this.bookImageWidth - 50, 180, true, this.bData)); + this.buttonList.add(this.buttonPreviousPage = new TurnPageButton(2, xPos - this.bookImageWidth + 24, 180, false, this.bData)); } - protected void actionPerformed (GuiButton button) + @Override + protected void actionPerformed(GuiButton button) { if (button.enabled) { if (button.id == 1) - currentPage += 2; + { + this.currentPage += 2; + } if (button.id == 2) - currentPage -= 2; + { + this.currentPage -= 2; + } - updateText(); + this.updateText(); } } - void updateText () + void updateText() { - if (maxPages % 2 == 1) + if (this.maxPages % 2 == 1) { - if (currentPage > maxPages) - currentPage = maxPages; + if (this.currentPage > this.maxPages) + { + this.currentPage = this.maxPages; + } } else { - if (currentPage >= maxPages) - currentPage = maxPages - 2; + if (this.currentPage >= this.maxPages) + { + this.currentPage = this.maxPages - 2; + } + } + if (this.currentPage % 2 == 1) + { + this.currentPage--; + } + if (this.currentPage < 0) + { + this.currentPage = 0; } - if (currentPage % 2 == 1) - currentPage--; - if (currentPage < 0) - currentPage = 0; - NodeList nList = manual.getElementsByTagName("page"); + NodeList nList = this.manual.getElementsByTagName("page"); - Node node = nList.item(currentPage); + Node node = nList.item(this.currentPage); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; @@ -121,9 +148,9 @@ public class GuiManual extends GuiScreen { try { - pageLeft = clazz.newInstance(); - pageLeft.init(this, 0); - pageLeft.readPageFromXML(element); + this.pageLeft = clazz.newInstance(); + this.pageLeft.init(this, 0); + this.pageLeft.readPageFromXML(element); } catch (Exception e) { @@ -131,11 +158,11 @@ public class GuiManual extends GuiScreen } else { - pageLeft = null; + this.pageLeft = null; } } - node = nList.item(currentPage + 1); + node = nList.item(this.currentPage + 1); if (node != null && node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; @@ -144,9 +171,9 @@ public class GuiManual extends GuiScreen { try { - pageRight = clazz.newInstance(); - pageRight.init(this, 1); - pageRight.readPageFromXML(element); + this.pageRight = clazz.newInstance(); + this.pageRight.init(this, 1); + this.pageRight.readPageFromXML(element); } catch (Exception e) { @@ -154,16 +181,17 @@ public class GuiManual extends GuiScreen } else { - pageLeft = null; + this.pageLeft = null; } } else { - pageRight = null; + this.pageRight = null; } } - public void drawScreen (int par1, int par2, float par3) + @Override + public void drawScreen(int par1, int par2, float par3) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(bookRight); @@ -178,23 +206,32 @@ public class GuiManual extends GuiScreen super.drawScreen(par1, par2, par3); //16, 12, 220, 12 - if (pageLeft != null) - pageLeft.renderBackgroundLayer(localWidth + 16, localHeight + 12); - if (pageRight != null) - pageRight.renderBackgroundLayer(localWidth + 220, localHeight + 12); - if (pageLeft != null) - pageLeft.renderContentLayer(localWidth + 16, localHeight + 12, bData.isTranslatable); - if (pageRight != null) - pageRight.renderContentLayer(localWidth + 220, localHeight + 12, bData.isTranslatable); + if (this.pageLeft != null) + { + this.pageLeft.renderBackgroundLayer(localWidth + 16, localHeight + 12); + } + if (this.pageRight != null) + { + this.pageRight.renderBackgroundLayer(localWidth + 220, localHeight + 12); + } + if (this.pageLeft != null) + { + this.pageLeft.renderContentLayer(localWidth + 16, localHeight + 12, this.bData.isTranslatable); + } + if (this.pageRight != null) + { + this.pageRight.renderContentLayer(localWidth + 220, localHeight + 12, this.bData.isTranslatable); + } } - public Minecraft getMC () + public Minecraft getMC() { - return mc; + return this.mc; } - public boolean doesGuiPauseGame () + @Override + public boolean doesGuiPauseGame() { return false; } diff --git a/src/mantle/client/gui/TurnPageButton.java b/src/mantle/client/gui/TurnPageButton.java index 2aa2844..f5a7fb2 100644 --- a/src/mantle/client/gui/TurnPageButton.java +++ b/src/mantle/client/gui/TurnPageButton.java @@ -4,12 +4,11 @@ import mantle.books.BookData; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.ResourceLocation; - -import org.lwjgl.opengl.GL11; - import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.opengl.GL11; + @SideOnly(Side.CLIENT) public class TurnPageButton extends GuiButton { @@ -17,6 +16,7 @@ public class TurnPageButton extends GuiButton * True for pointing right (next page), false for pointing left (previous page). */ private final boolean nextPage; + private static ResourceLocation background;// = new ResourceLocation("tinker", "textures/gui/bookleft.png"); public TurnPageButton(int par1, int par2, int par3, boolean par4, BookData data) @@ -29,7 +29,8 @@ public class TurnPageButton extends GuiButton /** * Draws this button to the screen. */ - public void drawButton (Minecraft par1Minecraft, int par2, int par3) + @Override + public void drawButton(Minecraft par1Minecraft, int par2, int par3) { if (this.visible) { diff --git a/src/mantle/client/pages/BlankPage.java b/src/mantle/client/pages/BlankPage.java index d9fa597..8815653 100644 --- a/src/mantle/client/pages/BlankPage.java +++ b/src/mantle/client/pages/BlankPage.java @@ -6,12 +6,12 @@ public class BlankPage extends BookPage { @Override - public void readPageFromXML (Element element) + public void readPageFromXML(Element element) { } @Override - public void renderContentLayer (int localwidth, int localheight, boolean isTranslatable) + public void renderContentLayer(int localwidth, int localheight, boolean isTranslatable) { } diff --git a/src/mantle/client/pages/BookPage.java b/src/mantle/client/pages/BookPage.java index f9359cd..8667107 100644 --- a/src/mantle/client/pages/BookPage.java +++ b/src/mantle/client/pages/BookPage.java @@ -7,19 +7,20 @@ import org.w3c.dom.Element; public abstract class BookPage { protected GuiManual manual; + protected int side; - public void init (GuiManual manual, int side) + public void init(GuiManual manual, int side) { this.manual = manual; this.side = side; } - public abstract void readPageFromXML (Element element); + public abstract void readPageFromXML(Element element); - public void renderBackgroundLayer (int localwidth, int localheight) + public void renderBackgroundLayer(int localwidth, int localheight) { } - public abstract void renderContentLayer (int localwidth, int localheight, boolean isTranslatable); + public abstract void renderContentLayer(int localwidth, int localheight, boolean isTranslatable); } diff --git a/src/mantle/client/pages/ContentsTablePage.java b/src/mantle/client/pages/ContentsTablePage.java index f36f414..a27f39f 100644 --- a/src/mantle/client/pages/ContentsTablePage.java +++ b/src/mantle/client/pages/ContentsTablePage.java @@ -13,51 +13,61 @@ import org.w3c.dom.NodeList; public class ContentsTablePage extends BookPage { String text; + String[] iconText; + ItemStack[] icons; @Override - public void readPageFromXML (Element element) + public void readPageFromXML(Element element) { NodeList nodes = element.getElementsByTagName("text"); if (nodes != null) - text = nodes.item(0).getTextContent(); + { + this.text = nodes.item(0).getTextContent(); + } nodes = element.getElementsByTagName("link"); - iconText = new String[nodes.getLength()]; - icons = new ItemStack[nodes.getLength()]; + this.iconText = new String[nodes.getLength()]; + this.icons = new ItemStack[nodes.getLength()]; for (int i = 0; i < nodes.getLength(); i++) { NodeList children = nodes.item(i).getChildNodes(); - iconText[i] = children.item(1).getTextContent(); - icons[i] = MantleClientRegistry.getManualIcon(children.item(3).getTextContent()); + this.iconText[i] = children.item(1).getTextContent(); + this.icons[i] = MantleClientRegistry.getManualIcon(children.item(3).getTextContent()); } } @Override - public void renderContentLayer (int localWidth, int localHeight, boolean isTranslatable) + public void renderContentLayer(int localWidth, int localHeight, boolean isTranslatable) { - if (text != null) + if (this.text != null) { if (isTranslatable) - text = StatCollector.translateToLocal(text); - manual.fonts.drawString("\u00a7n" + text, localWidth + 25 + manual.fonts.getStringWidth(text) / 2, localHeight + 4, 0); + { + this.text = StatCollector.translateToLocal(this.text); + } + this.manual.fonts.drawString("\u00a7n" + this.text, localWidth + 25 + this.manual.fonts.getStringWidth(this.text) / 2, localHeight + 4, 0); } GL11.glEnable(GL12.GL_RESCALE_NORMAL); RenderHelper.enableGUIStandardItemLighting(); - manual.renderitem.zLevel = 100; - for (int i = 0; i < icons.length; i++) + this.manual.renderitem.zLevel = 100; + for (int i = 0; i < this.icons.length; i++) { - manual.renderitem.renderItemIntoGUI(icons[i], localWidth + 16, localHeight + 18 * i + 18); + this.manual.renderitem.renderItemIntoGUI(this.icons[i], localWidth + 16, localHeight + 18 * i + 18); int yOffset = 18; if (isTranslatable) - iconText[i] = StatCollector.translateToLocal(iconText[i]); + { + this.iconText[i] = StatCollector.translateToLocal(this.iconText[i]); + } - if (iconText[i].length() > 40) + if (this.iconText[i].length() > 40) + { yOffset = 13; - manual.fonts.drawString(iconText[i], localWidth + 38, localHeight + 18 * i + yOffset, 0); + } + this.manual.fonts.drawString(this.iconText[i], localWidth + 38, localHeight + 18 * i + yOffset, 0); } - manual.renderitem.zLevel = 0; + this.manual.renderitem.zLevel = 0; RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); } diff --git a/src/mantle/client/pages/CraftingPage.java b/src/mantle/client/pages/CraftingPage.java index ba28944..0af7be8 100644 --- a/src/mantle/client/pages/CraftingPage.java +++ b/src/mantle/client/pages/CraftingPage.java @@ -14,94 +14,127 @@ import org.w3c.dom.NodeList; public class CraftingPage extends BookPage { String text; + String size; + ItemStack[] icons; @Override - public void readPageFromXML (Element element) + public void readPageFromXML(Element element) { NodeList nodes = element.getElementsByTagName("text"); if (nodes != null) - text = nodes.item(0).getTextContent(); + { + this.text = nodes.item(0).getTextContent(); + } nodes = element.getElementsByTagName("name"); if (nodes != null) - icons = MantleClientRegistry.getRecipeIcons(nodes.item(0).getTextContent()); + { + this.icons = MantleClientRegistry.getRecipeIcons(nodes.item(0).getTextContent()); + } nodes = element.getElementsByTagName("size"); if (nodes != null) - size = nodes.item(0).getTextContent(); + { + this.size = nodes.item(0).getTextContent(); + } } @Override - public void renderContentLayer (int localWidth, int localHeight, boolean isTranslatable) + public void renderContentLayer(int localWidth, int localHeight, boolean isTranslatable) { if (isTranslatable) - text = StatCollector.translateToLocal(text); - if (size.equals("two")) - drawCraftingPage(text, icons, 2, localWidth, localHeight + 12); - if (size.equals("three")) - drawCraftingPage(text, icons, 3, localWidth + (side != 1 ? 6 : 0), localHeight + 12); + { + this.text = StatCollector.translateToLocal(this.text); + } + if (this.size.equals("two")) + { + this.drawCraftingPage(this.text, this.icons, 2, localWidth, localHeight + 12); + } + if (this.size.equals("three")) + { + this.drawCraftingPage(this.text, this.icons, 3, localWidth + (this.side != 1 ? 6 : 0), localHeight + 12); + } } - public void drawCraftingPage (String info, ItemStack[] icons, int recipeSize, int localWidth, int localHeight) + public void drawCraftingPage(String info, ItemStack[] icons, int recipeSize, int localWidth, int localHeight) { if (info != null) - manual.fonts.drawString("\u00a7n" + info, localWidth + 50, localHeight + 4, 0); + { + this.manual.fonts.drawString("\u00a7n" + info, localWidth + 50, localHeight + 4, 0); + } GL11.glScalef(2f, 2f, 2f); GL11.glEnable(GL12.GL_RESCALE_NORMAL); RenderHelper.enableGUIStandardItemLighting(); - manual.renderitem.zLevel = 100; + this.manual.renderitem.zLevel = 100; if (recipeSize == 2) { - manual.renderitem.renderItemAndEffectIntoGUI(icons[0], (localWidth + 126) / 2, (localHeight + 68) / 2); + this.manual.renderitem.renderItemAndEffectIntoGUI(icons[0], (localWidth + 126) / 2, (localHeight + 68) / 2); if (icons[0].stackSize > 1) - manual.renderitem.renderItemOverlayIntoGUI(manual.fonts, icons[0], (localWidth + 126) / 2, (localHeight + 68) / 2, String.valueOf(icons[0].stackSize)); + { + this.manual.renderitem.renderItemOverlayIntoGUI(this.manual.fonts, icons[0], (localWidth + 126) / 2, (localHeight + 68) / 2, String.valueOf(icons[0].stackSize)); + } for (int i = 0; i < icons.length - 1; i++) { if (icons[i + 1] != null) - manual.renderitem.renderItemAndEffectIntoGUI(icons[i + 1], (localWidth + 14 + 36 * (i % 2)) / 2, (localHeight + 36 * (i / 2) + 52) / 2); + { + this.manual.renderitem.renderItemAndEffectIntoGUI(icons[i + 1], (localWidth + 14 + 36 * (i % 2)) / 2, (localHeight + 36 * (i / 2) + 52) / 2); + } } } if (recipeSize == 3) { - manual.renderitem.renderItemAndEffectIntoGUI(icons[0], (localWidth + 138) / 2, (localHeight + 70) / 2); + this.manual.renderitem.renderItemAndEffectIntoGUI(icons[0], (localWidth + 138) / 2, (localHeight + 70) / 2); if (icons[0].stackSize > 1) - manual.renderitem.renderItemOverlayIntoGUI(manual.fonts, icons[0], (localWidth + 126) / 2, (localHeight + 68) / 2, String.valueOf(icons[0].stackSize)); + { + this.manual.renderitem.renderItemOverlayIntoGUI(this.manual.fonts, icons[0], (localWidth + 126) / 2, (localHeight + 68) / 2, String.valueOf(icons[0].stackSize)); + } for (int i = 0; i < icons.length - 1; i++) { if (icons[i + 1] != null) - manual.renderitem.renderItemAndEffectIntoGUI(icons[i + 1], (localWidth - 2 + 36 * (i % 3)) / 2, (localHeight + 36 * (i / 3) + 34) / 2); + { + this.manual.renderitem.renderItemAndEffectIntoGUI(icons[i + 1], (localWidth - 2 + 36 * (i % 3)) / 2, (localHeight + 36 * (i / 3) + 34) / 2); + } } } - manual.renderitem.zLevel = 0; + this.manual.renderitem.zLevel = 0; GL11.glScalef(0.5F, 0.5F, 0.5F); RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); } - public void renderBackgroundLayer (int localwidth, int localheight) + @Override + public void renderBackgroundLayer(int localwidth, int localheight) { - if (size.equals("two")) - drawBackground(2, localwidth, localheight + 12); + if (this.size.equals("two")) + { + this.drawBackground(2, localwidth, localheight + 12); + } - if (size.equals("three")) - drawBackground(3, localwidth + (side != 1 ? 6 : 0), localheight + 12); + if (this.size.equals("three")) + { + this.drawBackground(3, localwidth + (this.side != 1 ? 6 : 0), localheight + 12); + } } private static final ResourceLocation background = new ResourceLocation("mantle", "textures/gui/bookcrafting.png"); - public void drawBackground (int size, int localWidth, int localHeight) + public void drawBackground(int size, int localWidth, int localHeight) { - manual.getMC().getTextureManager().bindTexture(background); + this.manual.getMC().getTextureManager().bindTexture(background); if (size == 2) - manual.drawTexturedModalRect(localWidth + 8, localHeight + 46, 0, 116, 154, 78); + { + this.manual.drawTexturedModalRect(localWidth + 8, localHeight + 46, 0, 116, 154, 78); + } if (size == 3) - manual.drawTexturedModalRect(localWidth - 8, localHeight + 28, 0, 0, 183, 114); + { + this.manual.drawTexturedModalRect(localWidth - 8, localHeight + 28, 0, 0, 183, 114); + } } } diff --git a/src/mantle/client/pages/FurnacePage.java b/src/mantle/client/pages/FurnacePage.java index 601a7d8..e58ec75 100644 --- a/src/mantle/client/pages/FurnacePage.java +++ b/src/mantle/client/pages/FurnacePage.java @@ -14,42 +14,51 @@ import org.w3c.dom.NodeList; public class FurnacePage extends BookPage { String text; + ItemStack[] icons; @Override - public void readPageFromXML (Element element) + public void readPageFromXML(Element element) { NodeList nodes = element.getElementsByTagName("text"); if (nodes != null) - text = nodes.item(0).getTextContent(); + { + this.text = nodes.item(0).getTextContent(); + } nodes = element.getElementsByTagName("recipe"); if (nodes != null) - icons = MantleClientRegistry.getRecipeIcons(nodes.item(0).getTextContent()); + { + this.icons = MantleClientRegistry.getRecipeIcons(nodes.item(0).getTextContent()); + } } @Override - public void renderContentLayer (int localWidth, int localHeight, boolean isTranslatable) + public void renderContentLayer(int localWidth, int localHeight, boolean isTranslatable) { - if (text != null) + if (this.text != null) { if (isTranslatable) - text = StatCollector.translateToLocal(text); - manual.fonts.drawString("\u00a7n" + text, localWidth + 50, localHeight + 4, 0); + { + this.text = StatCollector.translateToLocal(this.text); + } + this.manual.fonts.drawString("\u00a7n" + this.text, localWidth + 50, localHeight + 4, 0); } GL11.glScalef(2f, 2f, 2f); GL11.glEnable(GL12.GL_RESCALE_NORMAL); RenderHelper.enableGUIStandardItemLighting(); - manual.renderitem.zLevel = 100; + this.manual.renderitem.zLevel = 100; - manual.renderitem.renderItemAndEffectIntoGUI(MantleClientRegistry.getManualIcon("coal"), (localWidth + 38) / 2, (localHeight + 110) / 2); - manual.renderitem.renderItemAndEffectIntoGUI(icons[0], (localWidth + 106) / 2, (localHeight + 74) / 2); - manual.renderitem.renderItemAndEffectIntoGUI(icons[1], (localWidth + 38) / 2, (localHeight + 38) / 2); + this.manual.renderitem.renderItemAndEffectIntoGUI(MantleClientRegistry.getManualIcon("coal"), (localWidth + 38) / 2, (localHeight + 110) / 2); + this.manual.renderitem.renderItemAndEffectIntoGUI(this.icons[0], (localWidth + 106) / 2, (localHeight + 74) / 2); + this.manual.renderitem.renderItemAndEffectIntoGUI(this.icons[1], (localWidth + 38) / 2, (localHeight + 38) / 2); - if (icons[0].stackSize > 1) - manual.renderitem.renderItemOverlayIntoGUI(manual.fonts, icons[0], (localWidth + 106) / 2, (localHeight + 74) / 2, String.valueOf(icons[0].stackSize)); + if (this.icons[0].stackSize > 1) + { + this.manual.renderitem.renderItemOverlayIntoGUI(this.manual.fonts, this.icons[0], (localWidth + 106) / 2, (localHeight + 74) / 2, String.valueOf(this.icons[0].stackSize)); + } - manual.renderitem.zLevel = 0; + this.manual.renderitem.zLevel = 0; GL11.glScalef(0.5F, 0.5F, 0.5F); RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); @@ -57,9 +66,10 @@ public class FurnacePage extends BookPage private static final ResourceLocation background = new ResourceLocation("mantle", "textures/gui/bookfurnace.png"); - public void renderBackgroundLayer (int localWidth, int localHeight) + @Override + public void renderBackgroundLayer(int localWidth, int localHeight) { - manual.getMC().getTextureManager().bindTexture(background); - manual.drawTexturedModalRect(localWidth + 32, localHeight + 32, 0, 0, 111, 114); + this.manual.getMC().getTextureManager().bindTexture(background); + this.manual.drawTexturedModalRect(localWidth + 32, localHeight + 32, 0, 0, 111, 114); } } diff --git a/src/mantle/client/pages/PicturePage.java b/src/mantle/client/pages/PicturePage.java index eeda9fc..b63edc8 100644 --- a/src/mantle/client/pages/PicturePage.java +++ b/src/mantle/client/pages/PicturePage.java @@ -1,62 +1,70 @@ package mantle.client.pages; +import static mantle.lib.CoreRepo.logger; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import static mantle.lib.CoreRepo.logger; + import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class PicturePage extends BookPage { String text; + String location; + ResourceLocation background; @Override - public void readPageFromXML (Element element) + public void readPageFromXML(Element element) { NodeList nodes = element.getElementsByTagName("text"); if (nodes != null) - text = nodes.item(0).getTextContent(); + { + this.text = nodes.item(0).getTextContent(); + } nodes = element.getElementsByTagName("location"); if (nodes != null) { - location = nodes.item(0).getTextContent(); - background = new ResourceLocation(location); - if(background == null) + this.location = nodes.item(0).getTextContent(); + this.background = new ResourceLocation(this.location); + if (this.background == null) { logger.warn(nodes.item(0).getTextContent() + " could not be found in the image cache(location)!"); } } //this borked stuffs somehow unless someone is interested in using it this stays disabled for now - /* nodes = element.getElementsByTagName("bookImage"); - if (nodes != null) - { - //TODO 1.7 null check all of this - background = MantleClientRegistry.imageCache.get(nodes.item(0).getTextContent()).resource; - if(background == null){ - logger.warn(nodes.item(0).getTextContent() + " could not be found in the image cache(bookimage)!"); - } - }*/ + /* nodes = element.getElementsByTagName("bookImage"); + if (nodes != null) + { + //TODO 1.7 null check all of this + background = MantleClientRegistry.imageCache.get(nodes.item(0).getTextContent()).resource; + if(background == null){ + logger.warn(nodes.item(0).getTextContent() + " could not be found in the image cache(bookimage)!"); + } + }*/ } @Override - public void renderContentLayer (int localWidth, int localHeight, boolean isTranslatable) + public void renderContentLayer(int localWidth, int localHeight, boolean isTranslatable) { if (isTranslatable) - text = StatCollector.translateToLocal(text); - manual.fonts.drawSplitString(text, localWidth + 8, localHeight, 178, 0); + { + this.text = StatCollector.translateToLocal(this.text); + } + this.manual.fonts.drawSplitString(this.text, localWidth + 8, localHeight, 178, 0); } - public void renderBackgroundLayer (int localWidth, int localHeight) + @Override + public void renderBackgroundLayer(int localWidth, int localHeight) { - if (background != null) + if (this.background != null) { - manual.getMC().getTextureManager().bindTexture(background); + this.manual.getMC().getTextureManager().bindTexture(this.background); } //manual.getMC().renderEngine.bindTexture(location); - manual.drawTexturedModalRect(localWidth, localHeight + 12, 0, 0, 170, 144); + this.manual.drawTexturedModalRect(localWidth, localHeight + 12, 0, 0, 170, 144); } } diff --git a/src/mantle/client/pages/SectionPage.java b/src/mantle/client/pages/SectionPage.java index b1ca875..972f580 100644 --- a/src/mantle/client/pages/SectionPage.java +++ b/src/mantle/client/pages/SectionPage.java @@ -8,29 +8,34 @@ import org.w3c.dom.NodeList; public class SectionPage extends BookPage { String title; + String body; @Override - public void readPageFromXML (Element element) + public void readPageFromXML(Element element) { NodeList nodes = element.getElementsByTagName("title"); if (nodes != null) - title = nodes.item(0).getTextContent(); + { + this.title = nodes.item(0).getTextContent(); + } nodes = element.getElementsByTagName("text"); if (nodes != null) - body = nodes.item(0).getTextContent(); + { + this.body = nodes.item(0).getTextContent(); + } } @Override - public void renderContentLayer (int localWidth, int localHeight, boolean isTranslatable) + public void renderContentLayer(int localWidth, int localHeight, boolean isTranslatable) { if (isTranslatable) { - title = StatCollector.translateToLocal(title); - body = StatCollector.translateToLocal(body); + this.title = StatCollector.translateToLocal(this.title); + this.body = StatCollector.translateToLocal(this.body); } - manual.fonts.drawSplitString("\u00a7n" + title, localWidth + 70, localHeight + 4, 178, 0); - manual.fonts.drawSplitString(body, localWidth, localHeight + 16, 190, 0); + this.manual.fonts.drawSplitString("\u00a7n" + this.title, localWidth + 70, localHeight + 4, 178, 0); + this.manual.fonts.drawSplitString(this.body, localWidth, localHeight + 16, 190, 0); } } diff --git a/src/mantle/client/pages/SidebarPage.java b/src/mantle/client/pages/SidebarPage.java index cda297f..adb4ad6 100644 --- a/src/mantle/client/pages/SidebarPage.java +++ b/src/mantle/client/pages/SidebarPage.java @@ -13,52 +13,58 @@ import org.w3c.dom.NodeList; public class SidebarPage extends BookPage { String text; + String[] iconText; + ItemStack[] icons; @Override - public void readPageFromXML (Element element) + public void readPageFromXML(Element element) { NodeList nodes = element.getElementsByTagName("text"); if (nodes != null) - text = nodes.item(0).getTextContent(); + { + this.text = nodes.item(0).getTextContent(); + } nodes = element.getElementsByTagName("item"); - iconText = new String[nodes.getLength()]; - icons = new ItemStack[nodes.getLength()]; + this.iconText = new String[nodes.getLength()]; + this.icons = new ItemStack[nodes.getLength()]; for (int i = 0; i < nodes.getLength(); i++) { NodeList children = nodes.item(i).getChildNodes(); - iconText[i] = children.item(1).getTextContent(); - icons[i] = MantleClientRegistry.getManualIcon(children.item(3).getTextContent()); + this.iconText[i] = children.item(1).getTextContent(); + this.icons[i] = MantleClientRegistry.getManualIcon(children.item(3).getTextContent()); } } @Override - public void renderContentLayer (int localWidth, int localHeight, boolean isTranslatable) + public void renderContentLayer(int localWidth, int localHeight, boolean isTranslatable) { if (isTranslatable) { - text = StatCollector.translateToLocal(text); + this.text = StatCollector.translateToLocal(this.text); } - manual.fonts.drawSplitString(text, localWidth, localHeight, 178, 0); + this.manual.fonts.drawSplitString(this.text, localWidth, localHeight, 178, 0); GL11.glEnable(GL12.GL_RESCALE_NORMAL); RenderHelper.enableGUIStandardItemLighting(); - manual.renderitem.zLevel = 100; - int offset = text.length() / 4 + 10; - for (int i = 0; i < icons.length; i++) + this.manual.renderitem.zLevel = 100; + int offset = this.text.length() / 4 + 10; + for (int i = 0; i < this.icons.length; i++) { if (isTranslatable) { - iconText[i] = StatCollector.translateToLocal(iconText[i]); + this.iconText[i] = StatCollector.translateToLocal(this.iconText[i]); } - manual.renderitem.renderItemIntoGUI(icons[i], localWidth + 8, localHeight + 18 * i + offset); + this.manual.renderitem.renderItemIntoGUI(this.icons[i], localWidth + 8, localHeight + 18 * i + offset); int yOffset = 39; - if (iconText[i].length() > 40) + if (this.iconText[i].length() > 40) + { yOffset = 34; - manual.fonts.drawSplitString(iconText[i], localWidth + 30, localHeight + 18 * i + offset, 140, 0); + } + this.manual.fonts.drawSplitString(this.iconText[i], localWidth + 30, localHeight + 18 * i + offset, 140, 0); } - manual.renderitem.zLevel = 0; + this.manual.renderitem.zLevel = 0; RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); } diff --git a/src/mantle/client/pages/TextPage.java b/src/mantle/client/pages/TextPage.java index 00c52fa..09e7fbe 100644 --- a/src/mantle/client/pages/TextPage.java +++ b/src/mantle/client/pages/TextPage.java @@ -10,18 +10,22 @@ public class TextPage extends BookPage String text; @Override - public void readPageFromXML (Element element) + public void readPageFromXML(Element element) { NodeList nodes = element.getElementsByTagName("text"); if (nodes != null) - text = nodes.item(0).getTextContent(); + { + this.text = nodes.item(0).getTextContent(); + } } @Override - public void renderContentLayer (int localWidth, int localHeight, boolean IsTranslatable) + public void renderContentLayer(int localWidth, int localHeight, boolean IsTranslatable) { if (IsTranslatable) - text = StatCollector.translateToLocal(text); - manual.fonts.drawSplitString(text, localWidth, localHeight, 178, 0); + { + this.text = StatCollector.translateToLocal(this.text); + } + this.manual.fonts.drawSplitString(this.text, localWidth, localHeight, 178, 0); } } diff --git a/src/mantle/client/pages/TitlePage.java b/src/mantle/client/pages/TitlePage.java index b103bc6..fdc9590 100644 --- a/src/mantle/client/pages/TitlePage.java +++ b/src/mantle/client/pages/TitlePage.java @@ -10,18 +10,22 @@ public class TitlePage extends BookPage String text; @Override - public void readPageFromXML (Element element) + public void readPageFromXML(Element element) { NodeList nodes = element.getElementsByTagName("text"); if (nodes != null) - text = nodes.item(0).getTextContent(); + { + this.text = nodes.item(0).getTextContent(); + } } @Override - public void renderContentLayer (int localWidth, int localHeight, boolean isTranslatable) + public void renderContentLayer(int localWidth, int localHeight, boolean isTranslatable) { if (isTranslatable) - text = StatCollector.translateToLocal(text); - manual.fonts.drawSplitString(text, localWidth, localHeight, 178, 0); + { + this.text = StatCollector.translateToLocal(this.text); + } + this.manual.fonts.drawSplitString(this.text, localWidth, localHeight, 178, 0); } } diff --git a/src/mantle/common/ComparisonHelper.java b/src/mantle/common/ComparisonHelper.java index 0a89577..55a8fba 100644 --- a/src/mantle/common/ComparisonHelper.java +++ b/src/mantle/common/ComparisonHelper.java @@ -6,24 +6,24 @@ import net.minecraft.item.ItemStack; public class ComparisonHelper { - public static boolean areEquivalent (Item item, Block block) + public static boolean areEquivalent(Item item, Block block) { return item == Item.getItemFromBlock(block); } - public static boolean areEquivalent (Block block1, Block block2) + public static boolean areEquivalent(Block block1, Block block2) { return block1 == block2; } - public static boolean areEquivalent (Item item1, Item item2) + public static boolean areEquivalent(Item item1, Item item2) { return item1 == item2; } //@TODO make this a more verbose comparison - public static boolean areEquivalent (ItemStack is1, ItemStack is2) + public static boolean areEquivalent(ItemStack is1, ItemStack is2) { - return is1.getItem() == is2.getItem(); + return is1.getItem() == is2.getItem(); } } diff --git a/src/mantle/common/IDDumps.java b/src/mantle/common/IDDumps.java index 7d65fe5..4e9da89 100644 --- a/src/mantle/common/IDDumps.java +++ b/src/mantle/common/IDDumps.java @@ -8,7 +8,8 @@ import net.minecraft.world.biome.BiomeGenBase; public class IDDumps { - public static void dump(){ + public static void dump() + { if (CoreConfig.dumpBiomeIDs) { for (BiomeGenBase b : BiomeGenBase.getBiomeGenArray()) diff --git a/src/mantle/common/MProxyCommon.java b/src/mantle/common/MProxyCommon.java index cfccaf9..5efc875 100644 --- a/src/mantle/common/MProxyCommon.java +++ b/src/mantle/common/MProxyCommon.java @@ -9,24 +9,26 @@ public class MProxyCommon implements IGuiHandler public static int manualGuiID = -1; @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 < 0) + { return null; + } return null; } @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) { return null; } - public void registerRenderer () + public void registerRenderer() { } - public void readManuals () + public void readManuals() { } } diff --git a/src/mantle/common/network/AbstractPacket.java b/src/mantle/common/network/AbstractPacket.java index 8d2b14a..39d0151 100644 --- a/src/mantle/common/network/AbstractPacket.java +++ b/src/mantle/common/network/AbstractPacket.java @@ -7,7 +7,7 @@ import net.minecraft.entity.player.EntityPlayer; /** * AbstractPacket class. Should be the parent of all packets wishing to use the * PacketPipeline. - * + * * @author sirgingalot */ public abstract class AbstractPacket @@ -17,41 +17,41 @@ public abstract class AbstractPacket * Encode the packet data into the ByteBuf stream. Complex data sets may * need specific data handlers (See * @link{cpw.mods.fml.common.network.ByteBuffUtils}) - * + * * @param ctx * channel context * @param buffer * the buffer to encode into */ - public abstract void encodeInto (ChannelHandlerContext ctx, ByteBuf buffer); + public abstract void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer); /** * Decode the packet data from the ByteBuf stream. Complex data sets may * need specific data handlers (See * @link{cpw.mods.fml.common.network.ByteBuffUtils}) - * + * * @param ctx * channel context * @param buffer * the buffer to decode from */ - public abstract void decodeInto (ChannelHandlerContext ctx, ByteBuf buffer); + public abstract void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer); /** * Handle a packet on the client side. Note this occurs after decoding has * completed. - * + * * @param player * the player reference */ - public abstract void handleClientSide (EntityPlayer player); + public abstract void handleClientSide(EntityPlayer player); /** * Handle a packet on the server side. Note this occurs after decoding has * completed. - * + * * @param player * the player reference */ - public abstract void handleServerSide (EntityPlayer player); + public abstract void handleServerSide(EntityPlayer player); } diff --git a/src/mantle/common/network/PacketUpdateTE.java b/src/mantle/common/network/PacketUpdateTE.java index d351403..18ecd13 100644 --- a/src/mantle/common/network/PacketUpdateTE.java +++ b/src/mantle/common/network/PacketUpdateTE.java @@ -11,6 +11,7 @@ import net.minecraft.util.BlockPos; public class PacketUpdateTE extends AbstractPacket { private BlockPos pos; + private NBTTagCompound data; public PacketUpdateTE() @@ -25,15 +26,15 @@ public class PacketUpdateTE extends AbstractPacket } @Override - public void encodeInto (ChannelHandlerContext ctx, ByteBuf buffer) + public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { PacketBuffer pbuff = new PacketBuffer(buffer); - pbuff.writeInt(pos.getX()); - pbuff.writeShort(pos.getY()); - pbuff.writeInt(pos.getZ()); + pbuff.writeInt(this.pos.getX()); + pbuff.writeShort(this.pos.getY()); + pbuff.writeInt(this.pos.getZ()); try { - pbuff.writeNBTTagCompoundToBuffer(data); + pbuff.writeNBTTagCompoundToBuffer(this.data); } catch (Exception e) { @@ -42,13 +43,13 @@ public class PacketUpdateTE extends AbstractPacket } @Override - public void decodeInto (ChannelHandlerContext ctx, ByteBuf buffer) + public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { PacketBuffer pbuff = new PacketBuffer(buffer); - pos = new BlockPos(pbuff.readInt(), pbuff.readShort(), pbuff.readInt()); + this.pos = new BlockPos(pbuff.readInt(), pbuff.readShort(), pbuff.readInt()); try { - data = pbuff.readNBTTagCompoundFromBuffer(); + this.data = pbuff.readNBTTagCompoundFromBuffer(); } catch (Exception e) { @@ -57,18 +58,18 @@ public class PacketUpdateTE extends AbstractPacket } @Override - public void handleClientSide (EntityPlayer player) + public void handleClientSide(EntityPlayer player) { - TileEntity te = player.worldObj.getTileEntity(pos); + TileEntity te = player.worldObj.getTileEntity(this.pos); if (te != null) { - te.readFromNBT(data); + te.readFromNBT(this.data); } } @Override - public void handleServerSide (EntityPlayer player) + public void handleServerSide(EntityPlayer player) { } diff --git a/src/mantle/crash/CallableSuppConfig.java b/src/mantle/crash/CallableSuppConfig.java index 94819cc..089033c 100644 --- a/src/mantle/crash/CallableSuppConfig.java +++ b/src/mantle/crash/CallableSuppConfig.java @@ -18,15 +18,15 @@ public class CallableSuppConfig implements ICrashCallable } @Override - public String call () throws Exception + public String call() throws Exception { return "Environment healthy."; } @Override - public String getLabel () + public String getLabel() { - return modId + " Environment"; + return this.modId + " Environment"; } } diff --git a/src/mantle/crash/CallableUnsuppConfig.java b/src/mantle/crash/CallableUnsuppConfig.java index 036fb01..5e0b0bb 100644 --- a/src/mantle/crash/CallableUnsuppConfig.java +++ b/src/mantle/crash/CallableUnsuppConfig.java @@ -9,6 +9,7 @@ public class CallableUnsuppConfig implements ICrashCallable { private String modId; + private List modIds; public CallableUnsuppConfig(String modId, List modIds) @@ -18,17 +19,17 @@ public class CallableUnsuppConfig implements ICrashCallable } @Override - public String getLabel () + public String getLabel() { - return modId + " Environment"; + return this.modId + " Environment"; } @Override - public String call () throws Exception + public String call() throws Exception { String str = "DO NOT REPORT THIS CRASH! Unsupported mods in environment: "; Boolean firstEntry = true; - for (String id : modIds) + for (String id : this.modIds) { str = str + (firstEntry ? id : ", " + id); firstEntry = false; @@ -37,4 +38,4 @@ public class CallableUnsuppConfig implements ICrashCallable return str; } -} \ No newline at end of file +} diff --git a/src/mantle/debug/DebugData.java b/src/mantle/debug/DebugData.java index 86fd9f5..94b6a4c 100644 --- a/src/mantle/debug/DebugData.java +++ b/src/mantle/debug/DebugData.java @@ -11,7 +11,10 @@ public class DebugData { public final EntityPlayer player; - @SuppressWarnings("rawtypes") public final Class cl; + + @SuppressWarnings("rawtypes") + public final Class cl; + public final String[] strings; @SuppressWarnings("rawtypes") diff --git a/src/mantle/debug/DebugHelper.java b/src/mantle/debug/DebugHelper.java index 304835e..88c4c30 100644 --- a/src/mantle/debug/DebugHelper.java +++ b/src/mantle/debug/DebugHelper.java @@ -19,15 +19,19 @@ public class DebugHelper // No instantiation } - public static void handleDebugData (DebugData data) + public static void handleDebugData(DebugData data) { if (debug_enableChat) + { handleChatDebug(data); + } if (debug_enableConsole) + { handleConsoleDebug(data); + } } - private static void handleChatDebug (DebugData data) + private static void handleChatDebug(DebugData data) { EntityPlayer player = data.player; String prefix = "[" + data.cl.getSimpleName() + "] "; @@ -37,7 +41,7 @@ public class DebugHelper } } - private static void handleConsoleDebug (DebugData data) + private static void handleConsoleDebug(DebugData data) { String player = data.player.getGameProfile().getName(); String prefix = "[" + player + ":" + data.cl.getSimpleName() + "] "; diff --git a/src/mantle/debug/IDebuggable.java b/src/mantle/debug/IDebuggable.java index b972df9..8f3fee9 100644 --- a/src/mantle/debug/IDebuggable.java +++ b/src/mantle/debug/IDebuggable.java @@ -12,6 +12,6 @@ import net.minecraft.entity.player.EntityPlayer; public interface IDebuggable { - public DebugData getDebugInfo (EntityPlayer player); + public DebugData getDebugInfo(EntityPlayer player); } diff --git a/src/mantle/event/ManualOpenEvent.java b/src/mantle/event/ManualOpenEvent.java index 04d8667..8c3bf34 100644 --- a/src/mantle/event/ManualOpenEvent.java +++ b/src/mantle/event/ManualOpenEvent.java @@ -1,28 +1,35 @@ package mantle.event; -import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.eventhandler.Event; -public abstract class ManualOpenEvent extends Event { +public abstract class ManualOpenEvent extends Event +{ - public ItemStack bookStack; - public EntityPlayer player; + public ItemStack bookStack; - public ManualOpenEvent(ItemStack book, EntityPlayer player) { - this.bookStack = book; - this.player = player; - } + public EntityPlayer player; - public static class Pre extends ManualOpenEvent { - public Pre(ItemStack book, EntityPlayer player) { - super(book, player); - } - } + public ManualOpenEvent(ItemStack book, EntityPlayer player) + { + this.bookStack = book; + this.player = player; + } - public static class Post extends ManualOpenEvent { - public Post(ItemStack book, EntityPlayer player) { - super(book, player); - } - } + public static class Pre extends ManualOpenEvent + { + public Pre(ItemStack book, EntityPlayer player) + { + super(book, player); + } + } + + public static class Post extends ManualOpenEvent + { + public Post(ItemStack book, EntityPlayer player) + { + super(book, player); + } + } } diff --git a/src/mantle/event/Migration.java b/src/mantle/event/Migration.java index 6a3c689..699dfa4 100644 --- a/src/mantle/event/Migration.java +++ b/src/mantle/event/Migration.java @@ -1,21 +1,27 @@ package mantle.event; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; +import static mantle.lib.CoreRepo.logger; + +import java.util.List; +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; import net.minecraftforge.fml.common.ModContainer; import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent; import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent.MissingMapping; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import static mantle.lib.CoreRepo.logger; -import java.util.List; -import java.util.Map; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; public abstract class Migration { Map remapItem = Maps.newHashMap(); + Map remapBlock = Maps.newHashMap(); + List ignore = Lists.newArrayList(); + private ModContainer mod; private String modID; @@ -25,8 +31,8 @@ public abstract class Migration */ public Migration(ModContainer m) { - mod = m; - modID = m.getModId(); + this.mod = m; + this.modID = m.getModId(); } /* @@ -34,28 +40,29 @@ public abstract class Migration * Use an encapsulated object of form Map to store this. * The prefix will be created using the ID given during construction during processing. */ - public void addMigration (String old, Item newItem) + public void addMigration(String old, Item newItem) { - remapItem.put(modID + ":" + old, newItem); + this.remapItem.put(this.modID + ":" + old, newItem); } /* - * Add a new migration to the internal replacement map e.g. "olditem" -> "newitem" (without ID prefix!). - * Use an encapsulated object of form Map to store this. - * The prefix will be created using the ID given during construction during processing. - */ - public void addMigration (String old, Block newBlock) + * Add a new migration to the internal replacement map e.g. "olditem" -> "newitem" (without ID prefix!). + * Use an encapsulated object of form Map to store this. + * The prefix will be created using the ID given during construction during processing. + */ + public void addMigration(String old, Block newBlock) { - remapBlock.put(modID + ":" + old, newBlock); + this.remapBlock.put(this.modID + ":" + old, newBlock); } + /* * Register an old ID that's been removed entirely. This isn't suitable for renaming operations! * Store this in a List seperate to the rename mapping. * @param id ID to be removed (without ID prefix!). */ - public void addRemoval (String id) + public void addRemoval(String id) { - ignore.add(modID + ":" + id); + this.ignore.add(this.modID + ":" + id); } /* @@ -63,26 +70,35 @@ public abstract class Migration * This works on the assumption the FML event will have a list of string IDs that are missing. * During this phase, check for old IDs and remap as needed, or destroy ones marked for removal. */ - public void processMigrationEvent (FMLMissingMappingsEvent event) { - if ((!remapBlock.isEmpty() || !remapItem.isEmpty())) { - event.applyModContainer(mod); + public void processMigrationEvent(FMLMissingMappingsEvent event) + { + if ((!this.remapBlock.isEmpty() || !this.remapItem.isEmpty())) + { + event.applyModContainer(this.mod); List l = event.get(); - if(l != null) + if (l != null) { - for (MissingMapping miss : event.get()) { - if (remapItem.containsKey(miss.name)) - miss.remap(remapItem.get(miss.name)); - else if (remapBlock.containsKey(miss.name)) - miss.remap(remapBlock.get(miss.name)); - else if (ignore.contains(miss.name)) + for (MissingMapping miss : event.get()) + { + if (this.remapItem.containsKey(miss.name)) + { + miss.remap(this.remapItem.get(miss.name)); + } + else if (this.remapBlock.containsKey(miss.name)) + { + miss.remap(this.remapBlock.get(miss.name)); + } + else if (this.ignore.contains(miss.name)) + { miss.ignore(); + } } } else { - logger.error("migration list from FML empty for mod " + modID); + logger.error("migration list from FML empty for mod " + this.modID); } } } -} \ No newline at end of file +} diff --git a/src/mantle/items/ItemUtils.java b/src/mantle/items/ItemUtils.java index f359e98..c8ac743 100644 --- a/src/mantle/items/ItemUtils.java +++ b/src/mantle/items/ItemUtils.java @@ -5,11 +5,12 @@ import net.minecraftforge.fml.common.registry.GameData; public class ItemUtils { - public static String getUniqueName (Item item) + public static String getUniqueName(Item item) { - return (String)GameData.getItemRegistry().getNameForObject(item); + return (String) GameData.getItemRegistry().getNameForObject(item); } - public static Item getItemFromUniqueName (String uniqueName) + + public static Item getItemFromUniqueName(String uniqueName) { return GameData.getItemRegistry().getObject(uniqueName); } diff --git a/src/mantle/items/Manual.java b/src/mantle/items/Manual.java index d09da98..84194cb 100644 --- a/src/mantle/items/Manual.java +++ b/src/mantle/items/Manual.java @@ -1,13 +1,10 @@ package mantle.items; -import net.minecraftforge.common.MinecraftForge; - -import mantle.event.ManualOpenEvent; - import java.util.List; import mantle.Mantle; import mantle.books.BookDataStore; +import mantle.event.ManualOpenEvent; import mantle.items.abstracts.CraftingItem; import mantle.lib.CoreRepo; import net.minecraft.creativetab.CreativeTabs; @@ -15,6 +12,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -22,18 +20,20 @@ public class Manual extends CraftingItem { public final String modID; + static String[] name = new String[] { "beginner", "toolstation", "smeltery", "diary" }; + static String[] textureName = new String[] { "tinkerbook_diary", "tinkerbook_toolstation", "tinkerbook_smeltery", "tinkerbook_blue" }; public Manual() { super(name, textureName, "", "mantle", null); - modID = CoreRepo.modId; + this.modID = CoreRepo.modId; } - public void updateManual () + public void updateManual() { - updateData(new String[] { "test" }, new String[] { "mantlebook_blue" }, "", "mantle"); + this.updateData(new String[] { "test" }, new String[] { "mantlebook_blue" }, "", "mantle"); } public Manual(String[] name, String[] textureName, String folder, String modTexturePrefix, CreativeTabs tab, String modID) @@ -43,10 +43,10 @@ public class Manual extends CraftingItem } @Override - public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player) + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { - ManualOpenEvent.Pre preOpenEvent = new ManualOpenEvent.Pre(stack, player); - MinecraftForge.EVENT_BUS.post(preOpenEvent); + ManualOpenEvent.Pre preOpenEvent = new ManualOpenEvent.Pre(stack, player); + MinecraftForge.EVENT_BUS.post(preOpenEvent); player.openGui(Mantle.instance, mantle.client.MProxyClient.manualGuiID, world, 0, 0, 0); ManualOpenEvent.Post postOpenEvent = new ManualOpenEvent.Post(stack, player); @@ -57,20 +57,20 @@ public class Manual extends CraftingItem @Override @SideOnly(Side.CLIENT) - @SuppressWarnings({"unchecked", "rawtypes"}) - public void addInformation (ItemStack stack, EntityPlayer player, List list, boolean par4) + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) { list.add("\u00a7o" + StatCollector.translateToLocal(BookDataStore.getBookfromID(stack.getItemDamage()).toolTip)); } @Override - public String getUnlocalizedName () + public String getUnlocalizedName() { - return modID + ":" + super.getUnlocalizedName(); + return this.modID + ":" + super.getUnlocalizedName(); } @Override - public String getUnlocalizedName (ItemStack par1ItemStack) + public String getUnlocalizedName(ItemStack par1ItemStack) { return super.getUnlocalizedName(par1ItemStack); } diff --git a/src/mantle/items/abstracts/CraftingItem.java b/src/mantle/items/abstracts/CraftingItem.java index e7ae7aa..c54d848 100644 --- a/src/mantle/items/abstracts/CraftingItem.java +++ b/src/mantle/items/abstracts/CraftingItem.java @@ -6,14 +6,15 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; public class CraftingItem extends Item { public String modTexPrefix; + public String[] textureNames; + public String[] unlocalizedNames; + public String folder; public CraftingItem(String[] names, String[] tex, String folder, String modTexturePrefix, CreativeTabs tab) @@ -31,7 +32,7 @@ public class CraftingItem extends Item this.folder = folder; } - public void updateData (String[] names, String[] tex, String folder, String modTexturePrefix) + public void updateData(String[] names, String[] tex, String folder, String modTexturePrefix) { this.modTexPrefix = modTexturePrefix; this.textureNames = tex; @@ -39,18 +40,24 @@ public class CraftingItem extends Item this.folder = folder; } - public String getUnlocalizedName (ItemStack stack) + @Override + public String getUnlocalizedName(ItemStack stack) { - int arr = MathHelper.clamp_int(stack.getItemDamage(), 0, unlocalizedNames.length); - return getUnlocalizedName() + "." + unlocalizedNames[arr]; + int arr = MathHelper.clamp_int(stack.getItemDamage(), 0, this.unlocalizedNames.length); + return this.getUnlocalizedName() + "." + this.unlocalizedNames[arr]; } - @SuppressWarnings({"unchecked","rawtypes"}) - public void getSubItems (Item b, CreativeTabs tab, List list) + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void getSubItems(Item b, CreativeTabs tab, List list) { - for (int i = 0; i < unlocalizedNames.length; i++) - if (!(textureNames[i].equals(""))) + for (int i = 0; i < this.unlocalizedNames.length; i++) + { + if (!(this.textureNames[i].equals(""))) + { list.add(new ItemStack(b, 1, i)); + } + } } } diff --git a/src/mantle/lib/CoreConfig.java b/src/mantle/lib/CoreConfig.java index d17030b..e0e5d20 100644 --- a/src/mantle/lib/CoreConfig.java +++ b/src/mantle/lib/CoreConfig.java @@ -6,11 +6,11 @@ import static mantle.lib.CoreRepo.modId; import java.io.File; import java.io.IOException; -import org.apache.commons.io.FilenameUtils; - import mantle.books.external.ZipLoader; import net.minecraftforge.common.config.Configuration; +import org.apache.commons.io.FilenameUtils; + /** * Mantle configuration handler * @@ -21,6 +21,7 @@ import net.minecraftforge.common.config.Configuration; public class CoreConfig { static Configuration config; + public static File configFolder; /** @@ -28,14 +29,16 @@ public class CoreConfig * * @param mainConfigFolder Configuration folder (as a Java File) */ - public static void loadConfiguration (File mainConfigFolder) + public static void loadConfiguration(File mainConfigFolder) { logger.info("Loading configuration from disk."); try { configFolder = new File(mainConfigFolder.getCanonicalPath(), "SlimeKnights"); if (!configFolder.exists()) + { configFolder.mkdirs(); + } } catch (IOException e) { @@ -63,7 +66,7 @@ public class CoreConfig /** * Checks for MANTLE_DBGCONSOLE/CHAT config overrides in system environment for compile time testing, and other dev work. **/ - private static void checkSysOverrides () + private static void checkSysOverrides() { if (System.getenv("MANTLE_DBGCONSOLE") != null) { @@ -77,12 +80,14 @@ public class CoreConfig } } - public static void loadBookLocations () + public static void loadBookLocations() { for (File f : configFolder.listFiles()) { - if(f.isFile() && FilenameUtils.getExtension(f.getAbsolutePath()).equalsIgnoreCase("zip")) + if (f.isFile() && FilenameUtils.getExtension(f.getAbsolutePath()).equalsIgnoreCase("zip")) + { ZipLoader.loadZip(f); + } } } @@ -92,10 +97,13 @@ public class CoreConfig // Debug Helpers public static boolean debug_enableConsole = false; + public static boolean debug_enableChat = false; + public static boolean dumpBiomeIDs = false; + public static boolean dumpPotionIDs = false; + public static boolean dumpEnchantIDs = false; - } diff --git a/src/mantle/lib/CoreRepo.java b/src/mantle/lib/CoreRepo.java index 45fb33e..7419f54 100644 --- a/src/mantle/lib/CoreRepo.java +++ b/src/mantle/lib/CoreRepo.java @@ -14,7 +14,9 @@ public final class CoreRepo { public static final String modId = "mantle"; + public static final String modName = "Mantle"; + public static final String modVersion = "${version}"; public static final Logger logger = LogManager.getLogger("Mantle"); diff --git a/src/mantle/lib/TabTools.java b/src/mantle/lib/TabTools.java index 489edb6..fe93f97 100644 --- a/src/mantle/lib/TabTools.java +++ b/src/mantle/lib/TabTools.java @@ -13,18 +13,20 @@ public class TabTools extends CreativeTabs super(label); } - public void init (ItemStack stack) + public void init(ItemStack stack) { - display = stack; + this.display = stack; } - public ItemStack getIconItemStack () + @Override + public ItemStack getIconItemStack() { - return display; + return this.display; } - public Item getTabIconItem () + @Override + public Item getTabIconItem() { - return display.getItem(); + return this.display.getItem(); } -} \ No newline at end of file +} diff --git a/src/mantle/lib/client/MantleClientRegistry.java b/src/mantle/lib/client/MantleClientRegistry.java index f4423c7..e8b1e9b 100644 --- a/src/mantle/lib/client/MantleClientRegistry.java +++ b/src/mantle/lib/client/MantleClientRegistry.java @@ -3,39 +3,43 @@ package mantle.lib.client; import java.util.HashMap; import java.util.Map; -import com.google.common.collect.Maps; - import mantle.books.client.BookImage; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import com.google.common.collect.Maps; + public class MantleClientRegistry { public static Map manualIcons = Maps.newHashMap(); + public static Map recipeIcons = Maps.newHashMap(); + public static HashMap imageCache = Maps.newHashMap(); public static ItemStack defaultStack = new ItemStack(Items.iron_ingot); - public static BookImage getBookImageFromCache (String s) + public static BookImage getBookImageFromCache(String s) { return imageCache.get(s); } - public static void registerManualIcon (String name, ItemStack stack) + public static void registerManualIcon(String name, ItemStack stack) { manualIcons.put(name, stack); } - public static ItemStack getManualIcon (String textContent) + public static ItemStack getManualIcon(String textContent) { ItemStack stack = manualIcons.get(textContent); if (stack != null) + { return stack; + } return defaultStack; } - public static void registerManualSmallRecipe (String name, ItemStack output, ItemStack... stacks) + public static void registerManualSmallRecipe(String name, ItemStack output, ItemStack... stacks) { ItemStack[] recipe = new ItemStack[5]; recipe[0] = output; @@ -43,7 +47,7 @@ public class MantleClientRegistry recipeIcons.put(name, recipe); } - public static void registerManualLargeRecipe (String name, ItemStack output, ItemStack... stacks) + public static void registerManualLargeRecipe(String name, ItemStack output, ItemStack... stacks) { ItemStack[] recipe = new ItemStack[10]; recipe[0] = output; @@ -51,7 +55,7 @@ public class MantleClientRegistry recipeIcons.put(name, recipe); } - public static void registerManualFurnaceRecipe (String name, ItemStack output, ItemStack input) + public static void registerManualFurnaceRecipe(String name, ItemStack output, ItemStack input) { ItemStack[] recipe = new ItemStack[2]; recipe[0] = output; @@ -59,7 +63,7 @@ public class MantleClientRegistry recipeIcons.put(name, recipe); } - public static ItemStack[] getRecipeIcons (String recipeName) + public static ItemStack[] getRecipeIcons(String recipeName) { return recipeIcons.get(recipeName); } diff --git a/src/mantle/lib/environment/EnvironmentChecks.java b/src/mantle/lib/environment/EnvironmentChecks.java index 94c072f..1ad9f01 100644 --- a/src/mantle/lib/environment/EnvironmentChecks.java +++ b/src/mantle/lib/environment/EnvironmentChecks.java @@ -5,7 +5,6 @@ import static mantle.lib.CoreRepo.modId; import java.util.List; -import com.google.common.collect.Lists; import mantle.crash.CallableSuppConfig; import mantle.crash.CallableUnsuppConfig; import mantle.lib.CoreConfig; @@ -15,6 +14,8 @@ import net.minecraftforge.fml.common.ICrashCallable; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.relauncher.Side; +import com.google.common.collect.Lists; + /** * Environment Checks * @@ -37,14 +38,16 @@ public class EnvironmentChecks * Note: This code adds additional data to crashlogs. It does not trigger any crashes. */ @SuppressWarnings("rawtypes") - public static void verifyEnvironmentSanity () + public static void verifyEnvironmentSanity() { List modIds = Lists.newArrayList(); if (FMLCommonHandler.instance().getSide() == Side.CLIENT && FMLClientHandler.instance().hasOptifine() || Loader.isModLoaded("optifine")) { if (!CoreConfig.silenceEnvChecks) + { logger.error("[Environment Checks] Optifine detected. This may cause issues due to base edits or ASM usage."); + } hasOptifine = true; modIds.add("optifine"); } @@ -55,7 +58,9 @@ public class EnvironmentChecks if (cl != null) { if (!CoreConfig.silenceEnvChecks) + { logger.error("[Environment Checks] Bukkit implementation detected. This may cause issues. Bukkit implementations include Craftbukkit and spigot. Please try Sponge instead"); + } modIds.add("bukkit"); } } diff --git a/src/mantle/math/Dozenal.java b/src/mantle/math/Dozenal.java index 883fa15..ea8ec13 100644 --- a/src/mantle/math/Dozenal.java +++ b/src/mantle/math/Dozenal.java @@ -8,32 +8,32 @@ package mantle.math; * @author mDiyo */ -import com.google.common.collect.Lists; - import java.util.LinkedList; +import com.google.common.collect.Lists; + public class Dozenal { @SuppressWarnings("unused") - public static String convertToDozenal (byte i) + public static String convertToDozenal(byte i) { return convertDecimal(i); } @SuppressWarnings("unused") - public static String convertToDozenal (short i) + public static String convertToDozenal(short i) { return convertDecimal(i); } @SuppressWarnings("unused") - public static String convertToDozenal (int i) + public static String convertToDozenal(int i) { return convertDecimal(i); } - public static String convertDecimal (int i) + public static String convertDecimal(int i) { int num = i; LinkedList list = Lists.newLinkedList(); @@ -50,7 +50,7 @@ public class Dozenal return builder.toString(); } - public static char getDozenalCharacter (int i) + public static char getDozenalCharacter(int i) { assert i < 12 : "Base 10 number should be less than 12"; @@ -84,4 +84,4 @@ public class Dozenal return 'Q'; } -} \ No newline at end of file +} diff --git a/src/mantle/player/PlayerUtils.java b/src/mantle/player/PlayerUtils.java index 5c00465..e97ffa4 100644 --- a/src/mantle/player/PlayerUtils.java +++ b/src/mantle/player/PlayerUtils.java @@ -5,7 +5,7 @@ import net.minecraft.util.ChatComponentText; /** * Misc utils for dealing with players. - * + * * @author progwml6 */ public class PlayerUtils @@ -14,10 +14,12 @@ public class PlayerUtils /** * Sends a given message to a specific player (due to 1.7 axing addChatMessage()) */ - public static void sendChatMessage (EntityPlayer p, String message) + public static void sendChatMessage(EntityPlayer p, String message) { if (p != null && message != null && !message.isEmpty()) + { p.addChatComponentMessage(new ChatComponentText(message)); + } } } diff --git a/src/mantle/pulsar/config/ForgeCFG.java b/src/mantle/pulsar/config/ForgeCFG.java index 948bfb0..c75e344 100644 --- a/src/mantle/pulsar/config/ForgeCFG.java +++ b/src/mantle/pulsar/config/ForgeCFG.java @@ -1,19 +1,22 @@ package mantle.pulsar.config; -import net.minecraftforge.fml.common.Loader; +import java.io.File; + import mantle.pulsar.pulse.PulseMeta; import net.minecraftforge.common.config.Configuration; - -import java.io.*; +import net.minecraftforge.fml.common.Loader; /** * Mantle specific pulsar addon class to support using the forge CFG format for configurations * @author progwml6 */ -public class ForgeCFG implements IConfiguration{ +public class ForgeCFG implements IConfiguration +{ private static Configuration config; + private final String confPath; + private final String description; /** @@ -24,26 +27,32 @@ public class ForgeCFG implements IConfiguration{ * @param confName The config file name (without path or .cfg suffix) * @param description The description for the group that the config entries will be placed in. */ - public ForgeCFG(String confName, String description) { + public ForgeCFG(String confName, String description) + { this.confPath = Loader.instance().getConfigDir().toString() + File.separator + confName + ".cfg"; this.description = description; } @Override - public void load() { - config = new Configuration(new File(confPath)); + public void load() + { + config = new Configuration(new File(this.confPath)); config.load(); } @Override - public boolean isModuleEnabled(PulseMeta meta) { - return config.get(description, meta.getId(), meta.isEnabled(), meta.getDescription()).getBoolean(meta.isEnabled()); + public boolean isModuleEnabled(PulseMeta meta) + { + return config.get(this.description, meta.getId(), meta.isEnabled(), meta.getDescription()).getBoolean(meta.isEnabled()); } @Override - public void flush() { - if(config.hasChanged()) + public void flush() + { + if (config.hasChanged()) + { config.save(); + } } } diff --git a/src/mantle/pulsar/config/IConfiguration.java b/src/mantle/pulsar/config/IConfiguration.java index 01c67eb..cf14e24 100755 --- a/src/mantle/pulsar/config/IConfiguration.java +++ b/src/mantle/pulsar/config/IConfiguration.java @@ -7,7 +7,8 @@ import mantle.pulsar.pulse.PulseMeta; * * @author Arkan */ -public interface IConfiguration { +public interface IConfiguration +{ /** * Perform any configuration loading required. diff --git a/src/mantle/pulsar/control/PulseManager.java b/src/mantle/pulsar/control/PulseManager.java index 557aa53..08e512a 100755 --- a/src/mantle/pulsar/control/PulseManager.java +++ b/src/mantle/pulsar/control/PulseManager.java @@ -5,10 +5,13 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; -import com.google.common.eventbus.SubscriberExceptionContext; -import com.google.common.eventbus.SubscriberExceptionHandler; +import mantle.pulsar.config.IConfiguration; +import mantle.pulsar.internal.Configuration; +import mantle.pulsar.internal.CrashHandler; +import mantle.pulsar.internal.logging.ILogger; +import mantle.pulsar.internal.logging.LogManager; +import mantle.pulsar.pulse.Pulse; +import mantle.pulsar.pulse.PulseMeta; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLModContainer; import net.minecraftforge.fml.common.Loader; @@ -16,13 +19,10 @@ import net.minecraftforge.fml.common.ModContainer; import net.minecraftforge.fml.common.event.FMLEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import mantle.pulsar.config.IConfiguration; -import mantle.pulsar.internal.Configuration; -import mantle.pulsar.internal.CrashHandler; -import mantle.pulsar.pulse.PulseMeta; -import mantle.pulsar.internal.logging.ILogger; -import mantle.pulsar.internal.logging.LogManager; -import mantle.pulsar.pulse.Pulse; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; +import com.google.common.eventbus.SubscriberExceptionContext; +import com.google.common.eventbus.SubscriberExceptionHandler; /** * Manager class for a given mods Pulses. @@ -36,17 +36,23 @@ import mantle.pulsar.pulse.Pulse; * @author Arkan */ @SuppressWarnings("unused") -public class PulseManager { +public class PulseManager +{ private ILogger log; + private final boolean useConfig; private final LinkedHashMap pulses = new LinkedHashMap(); private boolean blockNewRegistrations = false; + private boolean configLoaded = false; + private IConfiguration conf; + private EventBus bus; + private String id; /** @@ -56,10 +62,11 @@ public class PulseManager { * * @param configName The config file name. */ - public PulseManager(String configName) { - init(); - useConfig = true; - conf = new Configuration(configName, log); + public PulseManager(String configName) + { + this.init(); + this.useConfig = true; + this.conf = new Configuration(configName, this.log); } /** @@ -70,23 +77,25 @@ public class PulseManager { * * @param config Configuration handler. */ - public PulseManager(IConfiguration config) { - init(); - useConfig = true; - conf = config; + public PulseManager(IConfiguration config) + { + this.init(); + this.useConfig = true; + this.conf = config; } /** * Shared initialiser code between all the constructors. */ - private void init() { + private void init() + { String modId = Loader.instance().activeModContainer().getModId(); this.id = modId; - log = LogManager.getLogger("Pulsar-" + modId); + this.log = LogManager.getLogger("Pulsar-" + modId); FMLCommonHandler.instance().registerCrashCallable(new CrashHandler(modId, this)); // Attach us to the mods FML bus and setup our own bus - bus = new EventBus(new BusExceptionHandler(modId)); - attachToContainerEventBus(this); + this.bus = new EventBus(new BusExceptionHandler(modId)); + this.attachToContainerEventBus(this); } /** @@ -96,18 +105,24 @@ public class PulseManager { * * @param pulse The Pulse to register. */ - public void registerPulse(Object pulse) { - if (blockNewRegistrations) throw new RuntimeException("A mod tried to register a plugin after preinit! Pulse: " - + pulse); - if (!configLoaded) { - conf.load(); - configLoaded = true; + public void registerPulse(Object pulse) + { + if (this.blockNewRegistrations) + { + throw new RuntimeException("A mod tried to register a plugin after preinit! Pulse: " + + pulse); + } + if (!this.configLoaded) + { + this.conf.load(); + this.configLoaded = true; } String id, description, deps; boolean forced, enabled, defaultEnabled, missingDeps = false; - try { + try + { Pulse p = pulse.getClass().getAnnotation(Pulse.class); id = p.id(); description = p.description(); @@ -115,18 +130,26 @@ public class PulseManager { forced = p.forced(); enabled = p.defaultEnable(); defaultEnabled = p.defaultEnable(); - } catch (NullPointerException ex) { + } + catch (NullPointerException ex) + { throw new RuntimeException("Could not parse @Pulse annotation for Pulse: " + pulse); } // Work around Java not allowing default-null fields. - if (description.equals("")) description = null; + if (description.equals("")) + { + description = null; + } - if (!deps.equals("")) { + if (!deps.equals("")) + { String[] parsedDeps = deps.split(";"); - for (String s : parsedDeps) { - if (!Loader.isModLoaded(s)) { - log.info("Skipping Pulse " + id + "; missing dependency: " + s); + for (String s : parsedDeps) + { + if (!Loader.isModLoaded(s)) + { + this.log.info("Skipping Pulse " + id + "; missing dependency: " + s); missingDeps = true; enabled = false; break; @@ -135,12 +158,13 @@ public class PulseManager { } PulseMeta meta = new PulseMeta(id, description, forced, enabled, defaultEnabled); - meta.setEnabled(!missingDeps && getEnabledFromConfig(meta)); + meta.setEnabled(!missingDeps && this.getEnabledFromConfig(meta)); - if (meta.isEnabled()) { - pulses.put(pulse, meta); + if (meta.isEnabled()) + { + this.pulses.put(pulse, meta); // Attach Pulse to internal event bus - bus.register(pulse); + this.bus.register(pulse); } } @@ -149,24 +173,32 @@ public class PulseManager { * * @param obj Object to register. */ - private void attachToContainerEventBus(Object obj) { - ModContainer cnt = Loader.instance().activeModContainer(); - log.debug("Attaching [" + obj + "] to event bus for container [" + cnt + "]"); - try { - FMLModContainer mc = (FMLModContainer)cnt; + private void attachToContainerEventBus(Object obj) + { + ModContainer cnt = Loader.instance().activeModContainer(); + this.log.debug("Attaching [" + obj + "] to event bus for container [" + cnt + "]"); + try + { + FMLModContainer mc = (FMLModContainer) cnt; Field ebf = mc.getClass().getDeclaredField("eventBus"); boolean access = ebf.isAccessible(); ebf.setAccessible(true); - EventBus eb = (EventBus)ebf.get(mc); + EventBus eb = (EventBus) ebf.get(mc); ebf.setAccessible(access); eb.register(obj); - } catch (NoSuchFieldException nsfe) { + } + catch (NoSuchFieldException nsfe) + { throw new RuntimeException("Pulsar >> Incompatible FML mod container (missing eventBus field) - wrong Forge version?"); - } catch (IllegalAccessException iae) { + } + catch (IllegalAccessException iae) + { throw new RuntimeException("Pulsar >> Security Manager blocked access to eventBus on mod container. Cannot continue."); - } catch (ClassCastException cce) { + } + catch (ClassCastException cce) + { throw new RuntimeException("Pulsar >> Something in the mod container had the wrong type? " + cce.getMessage()); } } @@ -179,34 +211,32 @@ public class PulseManager { * @param evt An event object. */ @Subscribe - public void propagateEvent(FMLEvent evt) { - if (evt instanceof FMLPreInitializationEvent) preInit((FMLPreInitializationEvent) evt); - bus.post(evt); - } - - private boolean getEnabledFromConfig(PulseMeta meta) { - if (meta.isForced() || !useConfig) return true; // Forced or no config set. - - return conf.isModuleEnabled(meta); - } - - public void preInit(FMLPreInitializationEvent evt) { - if (!blockNewRegistrations) conf.flush(); // First preInit call, so flush config - blockNewRegistrations = true; - } - - private boolean hasRequiredPulses(Map.Entry entry) { - String deps = entry.getKey().getClass().getAnnotation(Pulse.class).pulsesRequired(); - if (!deps.equals("")) { - String[] parsedDeps = deps.split(";"); - for (String s : parsedDeps) { - if (!isPulseLoaded(s)) { - log.info("Skipping Pulse " + entry.getValue().getId() + "; missing pulse: " + s); - return false; - } - } + public void propagateEvent(FMLEvent evt) + { + if (evt instanceof FMLPreInitializationEvent) + { + this.preInit((FMLPreInitializationEvent) evt); } - return true; + this.bus.post(evt); + } + + private boolean getEnabledFromConfig(PulseMeta meta) + { + if (meta.isForced() || !this.useConfig) + { + return true; // Forced or no config set. + } + + return this.conf.isModuleEnabled(meta); + } + + public void preInit(FMLPreInitializationEvent evt) + { + if (!this.blockNewRegistrations) + { + this.conf.flush(); // First preInit call, so flush config + } + this.blockNewRegistrations = true; } /** @@ -215,42 +245,50 @@ public class PulseManager { * @param pulseId The ID to check. * @return Whether the ID was present. */ - public boolean isPulseLoaded(String pulseId) { - for(Map.Entry entry : pulses.entrySet()) { - if (entry.getValue().getId().equals(pulseId)) { + public boolean isPulseLoaded(String pulseId) + { + for (Map.Entry entry : this.pulses.entrySet()) + { + if (entry.getValue().getId().equals(pulseId)) + { return true; } } return false; } - public Collection getAllPulseMetadata() { - return pulses.values(); + public Collection getAllPulseMetadata() + { + return this.pulses.values(); } /** * Needed because Google EventBus is a derp and by default swallows exceptions (dafuq guys?) */ - private class BusExceptionHandler implements SubscriberExceptionHandler { + private class BusExceptionHandler implements SubscriberExceptionHandler + { private final String id; /** * @param id Mod ID to include in exception raises. */ - public BusExceptionHandler(String id) { + public BusExceptionHandler(String id) + { this.id = id; } @Override - public void handleException(Throwable exception, SubscriberExceptionContext ctx) { - FMLCommonHandler.instance().raiseException(exception, "Pulsar/" + id + " >> Exception uncaught in [" + public void handleException(Throwable exception, SubscriberExceptionContext ctx) + { + FMLCommonHandler.instance().raiseException(exception, "Pulsar/" + this.id + " >> Exception uncaught in [" + ctx.getSubscriber().getClass().getName() + ":" + ctx.getSubscriberMethod().getName() + "] for event [" + ctx.getEvent().getClass().getSimpleName() + "]", true); } } @Override - public String toString() { - return "PulseManager[" + id + "]"; + public String toString() + { + return "PulseManager[" + this.id + "]"; } } diff --git a/src/mantle/pulsar/debug/EventSpy.java b/src/mantle/pulsar/debug/EventSpy.java index 6fa6bb5..36d11aa 100755 --- a/src/mantle/pulsar/debug/EventSpy.java +++ b/src/mantle/pulsar/debug/EventSpy.java @@ -1,25 +1,28 @@ package mantle.pulsar.debug; -import com.google.common.eventbus.Subscribe; import mantle.pulsar.internal.logging.ILogger; import mantle.pulsar.internal.logging.LogManager; import mantle.pulsar.pulse.Pulse; import net.minecraftforge.fml.common.Loader; +import com.google.common.eventbus.Subscribe; + /** * Debug Pulse to 'eavesdrop' on the PulseManager event bus traffic. * * @author Arkan */ @SuppressWarnings("unused") -@Pulse(id="EventSpy", description="we iz in ur buses, monitorin ur eventz", forced=true) -public class EventSpy { +@Pulse(id = "EventSpy", description = "we iz in ur buses, monitorin ur eventz", forced = true) +public class EventSpy +{ private final ILogger log = LogManager.getLogger("EventSpy/" + Loader.instance().activeModContainer().getModId()); @Subscribe - public void receive(Object evt) { - log.info("Received event: " + evt); + public void receive(Object evt) + { + this.log.info("Received event: " + evt); } } diff --git a/src/mantle/pulsar/internal/Configuration.java b/src/mantle/pulsar/internal/Configuration.java index ab5ba54..44769e9 100755 --- a/src/mantle/pulsar/internal/Configuration.java +++ b/src/mantle/pulsar/internal/Configuration.java @@ -1,29 +1,39 @@ package mantle.pulsar.internal; -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.HashMap; +import java.util.Map; + +import mantle.pulsar.config.IConfiguration; +import mantle.pulsar.internal.logging.ILogger; +import mantle.pulsar.pulse.PulseMeta; +import net.minecraftforge.fml.common.Loader; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; -import net.minecraftforge.fml.common.Loader; -import mantle.pulsar.config.IConfiguration; -import mantle.pulsar.internal.logging.ILogger; -import mantle.pulsar.pulse.PulseMeta; /** * Default Gson Configuration helper. * * @author Arkan */ -public class Configuration implements IConfiguration { +public class Configuration implements IConfiguration +{ private static final int CONFIG_LEVEL = 1; private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + private final String confPath; + private final ILogger logger; private Map modules; @@ -36,111 +46,151 @@ public class Configuration implements IConfiguration { * @param confName The config file name (without path or .json suffix) * @param logger The logger to send debug info to. */ - public Configuration(String confName, ILogger logger) { + public Configuration(String confName, ILogger logger) + { this.confPath = Loader.instance().getConfigDir().toString() + File.separator + confName + ".json"; this.logger = logger; } @Override - public void load() { - getModulesFromJson(); + public void load() + { + this.getModulesFromJson(); } @Override - public boolean isModuleEnabled(PulseMeta meta) { - ConfigEntry entry = modules.get(meta.getId()); - if (entry == null) { - modules.put(meta.getId(), new ConfigEntry(meta.isDefaultEnabled(), meta.getDescription())); + public boolean isModuleEnabled(PulseMeta meta) + { + ConfigEntry entry = this.modules.get(meta.getId()); + if (entry == null) + { + this.modules.put(meta.getId(), new ConfigEntry(meta.isDefaultEnabled(), meta.getDescription())); return meta.isEnabled(); - } else { + } + else + { return entry.getEnabled(); } } @Override - public void flush() { - writeModulesToJson(); + public void flush() + { + this.writeModulesToJson(); } - private void getModulesFromJson() { + private void getModulesFromJson() + { // Step 1: Does the file exist? - File f = new File(confPath); - if (!f.exists()) { - logger.info("Couldn't find config file; will generate a new one later."); - modules = new HashMap(); + File f = new File(this.confPath); + if (!f.exists()) + { + this.logger.info("Couldn't find config file; will generate a new one later."); + this.modules = new HashMap(); return; } // Step 2: File exists. Let's make sure it's usable. - if (!(f.canRead() && f.canWrite())) { - throw new FileNotReadWritableException("Could not read/write Pulsar config: " + confPath); + if (!(f.canRead() && f.canWrite())) + { + throw new FileNotReadWritableException("Could not read/write Pulsar config: " + this.confPath); } // Step 3: Good enough. Read it. - try { - try { - modules = parseV1Config(f); - } catch (Exception ex) { - logger.warn("Failed to parse " + f.getName() + " using the v1 parser; trying the v0 parser."); - Map conf = parseV0Config(f); - logger.info("Found valid v0 configuration. Upgrading it."); - modules = conf; - writeModulesToJson(); - logger.info("Upgrade complete! Config is now in v1 format."); + try + { + try + { + this.modules = this.parseV1Config(f); } - } catch (Exception ex) { - logger.warn("Invalid config file. Discarding."); + catch (Exception ex) + { + this.logger.warn("Failed to parse " + f.getName() + " using the v1 parser; trying the v0 parser."); + Map conf = this.parseV0Config(f); + this.logger.info("Found valid v0 configuration. Upgrading it."); + this.modules = conf; + this.writeModulesToJson(); + this.logger.info("Upgrade complete! Config is now in v1 format."); + } + } + catch (Exception ex) + { + this.logger.warn("Invalid config file. Discarding."); ex.printStackTrace(); - modules = new HashMap(); + this.modules = new HashMap(); } } - private Map parseV0Config(File f) throws Exception { - try { + private Map parseV0Config(File f) throws Exception + { + try + { JsonReader reader = new JsonReader(new InputStreamReader(new FileInputStream(f))); - Map m = gson.fromJson(reader, new TypeToken>(){}.getType()); // NASTY! - if (m == null) { + Map m = gson.fromJson(reader, new TypeToken>() + { + }.getType()); // NASTY! + if (m == null) + { throw new NullPointerException("Gson returned null."); } Map out = new HashMap(); - for (Map.Entry e : m.entrySet()) { + for (Map.Entry e : m.entrySet()) + { out.put(e.getKey(), new ConfigEntry(e.getValue())); } return out; - } catch (FileNotFoundException fnfe) { + } + catch (FileNotFoundException fnfe) + { throw new RuntimeException("This shouldn't be possible... " + fnfe); } } - private Map parseV1Config(File f) throws Exception { - try { + private Map parseV1Config(File f) throws Exception + { + try + { JsonReader reader = new JsonReader(new InputStreamReader(new FileInputStream(f))); GsonConfig c = gson.fromJson(reader, GsonConfig.class); - if (c.getConfigVersion() > 1) throw new RuntimeException("Pulsar config is from a newer version! Remove it! " + f.getAbsolutePath()); - if (c.getModules() == null) throw new IllegalArgumentException("Not a valid GsonConfig. Try v0 parsing."); + if (c.getConfigVersion() > 1) + { + throw new RuntimeException("Pulsar config is from a newer version! Remove it! " + f.getAbsolutePath()); + } + if (c.getModules() == null) + { + throw new IllegalArgumentException("Not a valid GsonConfig. Try v0 parsing."); + } return c.getModules(); - } catch (FileNotFoundException fnfe) { + } + catch (FileNotFoundException fnfe) + { throw new RuntimeException("This shouldn't be possible... " + fnfe); } } - private void writeModulesToJson() { - try { - JsonWriter writer = new JsonWriter(new OutputStreamWriter(new FileOutputStream(new File(confPath)))); + private void writeModulesToJson() + { + try + { + JsonWriter writer = new JsonWriter(new OutputStreamWriter(new FileOutputStream(new File(this.confPath)))); writer.setIndent(" "); - GsonConfig out = new GsonConfig(CONFIG_LEVEL, modules); + GsonConfig out = new GsonConfig(CONFIG_LEVEL, this.modules); gson.toJson(out, GsonConfig.class, writer); writer.close(); - } catch (Exception ex) { - logger.warn("Could not write config? " + confPath); + } + catch (Exception ex) + { + this.logger.warn("Could not write config? " + this.confPath); } } /** * Internal exception for an unreadable/unwritable config. */ - private static class FileNotReadWritableException extends RuntimeException { - public FileNotReadWritableException(String message) { + private static class FileNotReadWritableException extends RuntimeException + { + public FileNotReadWritableException(String message) + { super(message); } } @@ -148,53 +198,54 @@ public class Configuration implements IConfiguration { /** * Internal data holder, for use in the map and JSON. */ - private static class ConfigEntry { + private static class ConfigEntry + { private Boolean enabled; + private String description = null; - public ConfigEntry(Boolean enabled) { + public ConfigEntry(Boolean enabled) + { this.enabled = enabled; } - public ConfigEntry(Boolean enabled, String description) { + public ConfigEntry(Boolean enabled, String description) + { this(enabled); this.description = description; } - public Boolean getEnabled() { - return enabled; - } - - public void setEnabled(Boolean enabled) { - this.enabled = enabled; - } - - public String getDescription() { - return description; + public Boolean getEnabled() + { + return this.enabled; } } /** * Internal representation of a version 1+ config file. */ - private static class GsonConfig { + private static class GsonConfig + { private int CONFIG_VERSION = 0; private Map modules; - public GsonConfig(int version, Map modules) { + public GsonConfig(int version, Map modules) + { this.CONFIG_VERSION = version; this.modules = modules; } - public int getConfigVersion() { - return CONFIG_VERSION; + public int getConfigVersion() + { + return this.CONFIG_VERSION; } - public Map getModules() { - return modules; + public Map getModules() + { + return this.modules; } } diff --git a/src/mantle/pulsar/internal/CrashHandler.java b/src/mantle/pulsar/internal/CrashHandler.java index 30a4603..aa9233d 100755 --- a/src/mantle/pulsar/internal/CrashHandler.java +++ b/src/mantle/pulsar/internal/CrashHandler.java @@ -1,46 +1,59 @@ package mantle.pulsar.internal; -import net.minecraftforge.fml.common.ICrashCallable; import mantle.pulsar.control.PulseManager; import mantle.pulsar.pulse.PulseMeta; +import net.minecraftforge.fml.common.ICrashCallable; /** * FML crash callable for Pulse Managers; dumps a list of loaded pulses to the error log. * * @author Arkan */ -public class CrashHandler implements ICrashCallable { +public class CrashHandler implements ICrashCallable +{ private String id; + private PulseManager manager; - public CrashHandler(String modId, PulseManager manager) { + public CrashHandler(String modId, PulseManager manager) + { this.id = "Pulsar/" + modId + " loaded Pulses"; this.manager = manager; } @Override - public String getLabel() { - return id; + public String getLabel() + { + return this.id; } @Override - public String call() throws Exception { + public String call() throws Exception + { String out = "\n"; - for (PulseMeta meta : manager.getAllPulseMetadata()) { + for (PulseMeta meta : this.manager.getAllPulseMetadata()) + { String state = getStateFromMeta(meta); out += "\t\t- " + meta.getId() + " (" + state + ")\n"; // Yes, yes, manual indenting, I know... } return out; } - private static String getStateFromMeta(PulseMeta meta) { - if (meta.isForced()) { + private static String getStateFromMeta(PulseMeta meta) + { + if (meta.isForced()) + { return "Enabled/Forced"; - } else { - if (meta.isEnabled()) { + } + else + { + if (meta.isEnabled()) + { return "Enabled/Not Forced"; - } else { + } + else + { return "Disabled/Not Forced"; } } diff --git a/src/mantle/pulsar/internal/logging/ILogger.java b/src/mantle/pulsar/internal/logging/ILogger.java index 2d26787..d1b38d6 100755 --- a/src/mantle/pulsar/internal/logging/ILogger.java +++ b/src/mantle/pulsar/internal/logging/ILogger.java @@ -6,7 +6,8 @@ package mantle.pulsar.internal.logging; * @author Arkan */ @SuppressWarnings("unused") -public interface ILogger { +public interface ILogger +{ public void fatal(String msg); diff --git a/src/mantle/pulsar/internal/logging/JULLogger.java b/src/mantle/pulsar/internal/logging/JULLogger.java index 13cbd43..b632936 100755 --- a/src/mantle/pulsar/internal/logging/JULLogger.java +++ b/src/mantle/pulsar/internal/logging/JULLogger.java @@ -7,42 +7,50 @@ import java.util.logging.Logger; * * @author Arkan */ -public class JULLogger implements ILogger { +public class JULLogger implements ILogger +{ private final Logger log; - public JULLogger(String name) { - log = Logger.getLogger(name); + public JULLogger(String name) + { + this.log = Logger.getLogger(name); } @Override - public void fatal(String msg) { - log.severe(msg); // JUL doesn't -have- fatal... + public void fatal(String msg) + { + this.log.severe(msg); // JUL doesn't -have- fatal... } @Override - public void severe(String msg) { - log.severe(msg); + public void severe(String msg) + { + this.log.severe(msg); } @Override - public void warn(String msg) { - log.warning(msg); + public void warn(String msg) + { + this.log.warning(msg); } @Override - public void info(String msg) { - log.info(msg); + public void info(String msg) + { + this.log.info(msg); } @Override - public void debug(String msg) { - log.fine(msg); // Good enough. + public void debug(String msg) + { + this.log.fine(msg); // Good enough. } @Override - public void trace(String msg) { - log.finest(msg); // Closest we'll get. + public void trace(String msg) + { + this.log.finest(msg); // Closest we'll get. } } diff --git a/src/mantle/pulsar/internal/logging/Log4jLogger.java b/src/mantle/pulsar/internal/logging/Log4jLogger.java index 9f38239..ab6c80d 100755 --- a/src/mantle/pulsar/internal/logging/Log4jLogger.java +++ b/src/mantle/pulsar/internal/logging/Log4jLogger.java @@ -7,42 +7,50 @@ import org.apache.logging.log4j.Logger; * * @author Arkan */ -public class Log4jLogger implements ILogger { +public class Log4jLogger implements ILogger +{ private final Logger log; - public Log4jLogger(String name) { - log = org.apache.logging.log4j.LogManager.getLogger(name); + public Log4jLogger(String name) + { + this.log = org.apache.logging.log4j.LogManager.getLogger(name); } @Override - public void fatal(String msg) { - log.fatal(msg); + public void fatal(String msg) + { + this.log.fatal(msg); } @Override - public void severe(String msg) { - log.error(msg); + public void severe(String msg) + { + this.log.error(msg); } @Override - public void warn(String msg) { - log.warn(msg); + public void warn(String msg) + { + this.log.warn(msg); } @Override - public void info(String msg) { - log.info(msg); + public void info(String msg) + { + this.log.info(msg); } @Override - public void debug(String msg) { - log.debug(msg); + public void debug(String msg) + { + this.log.debug(msg); } @Override - public void trace(String msg) { - log.trace(msg); + public void trace(String msg) + { + this.log.trace(msg); } } diff --git a/src/mantle/pulsar/internal/logging/LogManager.java b/src/mantle/pulsar/internal/logging/LogManager.java index b727ebf..16b2ba9 100755 --- a/src/mantle/pulsar/internal/logging/LogManager.java +++ b/src/mantle/pulsar/internal/logging/LogManager.java @@ -5,9 +5,12 @@ package mantle.pulsar.internal.logging; * * @author Arkan */ -public class LogManager { +public class LogManager +{ - private LogManager() {} // Singleton. + private LogManager() + { + } // Singleton. private static final boolean useLog4j2; @@ -16,22 +19,33 @@ public class LogManager { * * If it's present, we can assume we should be using the damn thing. */ - static { + static + { boolean l4j = false; - try { + try + { Class cl = Class.forName("org.apache.logging.log4j.LogManager"); - if (cl == null) throw new ClassNotFoundException("This should never happen..."); + if (cl == null) + { + throw new ClassNotFoundException("This should never happen..."); + } l4j = true; - } catch (ClassNotFoundException cnfe) { + } + catch (ClassNotFoundException cnfe) + { // Ignore } useLog4j2 = l4j; } - public static ILogger getLogger(String name) { - if (useLog4j2) { + public static ILogger getLogger(String name) + { + if (useLog4j2) + { return new Log4jLogger(name); - } else { + } + else + { return new JULLogger(name); } } diff --git a/src/mantle/pulsar/pulse/Pulse.java b/src/mantle/pulsar/pulse/Pulse.java index 9ebce64..ad9366c 100755 --- a/src/mantle/pulsar/pulse/Pulse.java +++ b/src/mantle/pulsar/pulse/Pulse.java @@ -1,6 +1,10 @@ package mantle.pulsar.pulse; -import java.lang.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; /** * Metadata annotation for IPulse implementations. @@ -11,9 +15,10 @@ import java.lang.annotation.*; * @author Arkan */ @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) +@Target({ ElementType.TYPE }) @Documented -public @interface Pulse { +public @interface Pulse +{ /** * @return This Pulses UID - Much like FML mods have mod IDs. diff --git a/src/mantle/pulsar/pulse/PulseMeta.java b/src/mantle/pulsar/pulse/PulseMeta.java index 7059a9e..c1ef504 100755 --- a/src/mantle/pulsar/pulse/PulseMeta.java +++ b/src/mantle/pulsar/pulse/PulseMeta.java @@ -5,12 +5,15 @@ package mantle.pulsar.pulse; * * @author Arkan */ -public class PulseMeta { +public class PulseMeta +{ private String id, description; + private boolean forced, enabled, defaultEnabled; - public PulseMeta(String id, String description, boolean forced, boolean enabled, boolean defaultEnabled) { + public PulseMeta(String id, String description, boolean forced, boolean enabled, boolean defaultEnabled) + { this.id = id; this.description = description; this.forced = forced; @@ -18,27 +21,33 @@ public class PulseMeta { this.defaultEnabled = defaultEnabled; } - public String getId() { - return id; + public String getId() + { + return this.id; } - public String getDescription() { - return description; + public String getDescription() + { + return this.description; } - public boolean isForced() { - return forced; + public boolean isForced() + { + return this.forced; } - public boolean isEnabled() { - return enabled; + public boolean isEnabled() + { + return this.enabled; } - public void setEnabled(boolean enabled) { + public void setEnabled(boolean enabled) + { this.enabled = enabled; } - public boolean isDefaultEnabled() { - return defaultEnabled; + public boolean isDefaultEnabled() + { + return this.defaultEnabled; } } diff --git a/src/mantle/utils/ItemMetaWrapper.java b/src/mantle/utils/ItemMetaWrapper.java index e44c59c..36df03e 100644 --- a/src/mantle/utils/ItemMetaWrapper.java +++ b/src/mantle/utils/ItemMetaWrapper.java @@ -3,11 +3,14 @@ package mantle.utils; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -public class ItemMetaWrapper { +public class ItemMetaWrapper +{ public final Item item; + public final Integer meta; - public ItemMetaWrapper(Item item, Integer meta) { + public ItemMetaWrapper(Item item, Integer meta) + { this.item = item; this.meta = meta; } @@ -19,21 +22,32 @@ public class ItemMetaWrapper { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || this.getClass() != o.getClass()) + { + return false; + } ItemMetaWrapper itemMeta = (ItemMetaWrapper) o; - if (item != null ? !(item == itemMeta.item) : itemMeta.item != null) return false; - return !(meta != null ? !meta.equals(itemMeta.meta) : itemMeta.meta != null); + if (this.item != null ? !(this.item == itemMeta.item) : itemMeta.item != null) + { + return false; + } + return !(this.meta != null ? !this.meta.equals(itemMeta.meta) : itemMeta.meta != null); } @Override - public int hashCode() { - int result = item != null ? item.hashCode() : 0; - result = 31 * result + (meta != null ? meta.hashCode() : 0); + public int hashCode() + { + int result = this.item != null ? this.item.hashCode() : 0; + result = 31 * result + (this.meta != null ? this.meta.hashCode() : 0); return result; } } diff --git a/src/mantle/utils/ItemStackNBTWrapper.java b/src/mantle/utils/ItemStackNBTWrapper.java index 932cf62..bd78329 100644 --- a/src/mantle/utils/ItemStackNBTWrapper.java +++ b/src/mantle/utils/ItemStackNBTWrapper.java @@ -2,17 +2,26 @@ package mantle.utils; import net.minecraft.item.ItemStack; -public class ItemStackNBTWrapper { +public class ItemStackNBTWrapper +{ public final ItemStack stack; - public ItemStackNBTWrapper(ItemStack stack) { + public ItemStackNBTWrapper(ItemStack stack) + { this.stack = stack; } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || this.getClass() != o.getClass()) + { + return false; + } ItemStackNBTWrapper that = (ItemStackNBTWrapper) o; @@ -20,11 +29,12 @@ public class ItemStackNBTWrapper { } @Override - public int hashCode() { - int result = stack.getItem() != null ? stack.getItem().hashCode() : 0; - result = 31 * result + stack.getItemDamage(); - result = 31 * result + (stack.getTagCompound() != null ? stack.getTagCompound().hashCode() : 0); - result = 31 * result + stack.stackSize; + public int hashCode() + { + int result = this.stack.getItem() != null ? this.stack.getItem().hashCode() : 0; + result = 31 * result + this.stack.getItemDamage(); + result = 31 * result + (this.stack.getTagCompound() != null ? this.stack.getTagCompound().hashCode() : 0); + result = 31 * result + this.stack.stackSize; return result; } } diff --git a/src/mantle/utils/ItemStackWrapper.java b/src/mantle/utils/ItemStackWrapper.java index 261762f..b8eb378 100644 --- a/src/mantle/utils/ItemStackWrapper.java +++ b/src/mantle/utils/ItemStackWrapper.java @@ -3,35 +3,49 @@ package mantle.utils; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -public class ItemStackWrapper extends ItemMetaWrapper { +public class ItemStackWrapper extends ItemMetaWrapper +{ public final Integer stacksize; - public ItemStackWrapper(Item item, Integer meta, Integer stacksize) { + public ItemStackWrapper(Item item, Integer meta, Integer stacksize) + { super(item, meta); this.stacksize = stacksize; } - public ItemStackWrapper(ItemStack stack, Integer stacksize) { + public ItemStackWrapper(ItemStack stack, Integer stacksize) + { super(stack); this.stacksize = stacksize; } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || this.getClass() != o.getClass()) + { + return false; + } + if (!super.equals(o)) + { + return false; + } ItemStackWrapper that = (ItemStackWrapper) o; - return !(stacksize != null ? !stacksize.equals(that.stacksize) : that.stacksize != null); + return !(this.stacksize != null ? !this.stacksize.equals(that.stacksize) : that.stacksize != null); } @Override - public int hashCode() { + public int hashCode() + { int result = super.hashCode(); - result = 31 * result + (stacksize != null ? stacksize.hashCode() : 0); + result = 31 * result + (this.stacksize != null ? this.stacksize.hashCode() : 0); return result; } } diff --git a/src/mantle/utils/RecipeRemover.java b/src/mantle/utils/RecipeRemover.java index 3ddbef9..8da1de6 100644 --- a/src/mantle/utils/RecipeRemover.java +++ b/src/mantle/utils/RecipeRemover.java @@ -15,13 +15,15 @@ import net.minecraftforge.common.ChestGenHooks; @SuppressWarnings("unchecked") public class RecipeRemover { - public static void removeShapedRecipes (List removelist) + public static void removeShapedRecipes(List removelist) { for (ItemStack stack : removelist) + { removeShapedRecipe(stack); + } } - public static void removeAnyRecipe (ItemStack resultItem) + public static void removeAnyRecipe(ItemStack resultItem) { List recipes = CraftingManager.getInstance().getRecipeList(); for (int i = 0; i < recipes.size(); i++) @@ -35,7 +37,7 @@ public class RecipeRemover } } - public static void removeShapedRecipe (ItemStack resultItem) + public static void removeShapedRecipe(ItemStack resultItem) { List recipes = CraftingManager.getInstance().getRecipeList(); for (int i = 0; i < recipes.size(); i++) @@ -54,7 +56,7 @@ public class RecipeRemover } } - public static void removeShapelessRecipe (ItemStack resultItem) + public static void removeShapelessRecipe(ItemStack resultItem) { List recipes = CraftingManager.getInstance().getRecipeList(); for (int i = 0; i < recipes.size(); i++) @@ -73,24 +75,24 @@ public class RecipeRemover } } - public static void removeFurnaceRecipe (ItemStack resultItem) + public static void removeFurnaceRecipe(ItemStack resultItem) { Map recipes = FurnaceRecipes.instance().getSmeltingList(); recipes.remove(resultItem); } - public static void removeFurnaceRecipe (Item i, int metadata) + public static void removeFurnaceRecipe(Item i, int metadata) { removeFurnaceRecipe(new ItemStack(i, 1, metadata)); } - public static void removeFurnaceRecipe (Item i) + public static void removeFurnaceRecipe(Item i) { removeFurnaceRecipe(new ItemStack(i, 1, 32767)); } //removes from all vanilla worldgen chests :D - public static void removeFromChests (ItemStack resultItem) + public static void removeFromChests(ItemStack resultItem) { ChestGenHooks.getInfo(ChestGenHooks.BONUS_CHEST).removeItem(resultItem); ChestGenHooks.getInfo(ChestGenHooks.VILLAGE_BLACKSMITH).removeItem(resultItem); diff --git a/src/mantle/world/ChunkCoord.java b/src/mantle/world/ChunkCoord.java index e6154e2..30bbfff 100644 --- a/src/mantle/world/ChunkCoord.java +++ b/src/mantle/world/ChunkCoord.java @@ -9,12 +9,13 @@ import net.minecraft.world.chunk.Chunk; * Standardized implementation for representing and manipulating Chunk Coordinates. Provides standard Java Collection interaction. * From COFH LIB(modified to use mantle's coordtuple instead) * @author King Lemming - * + * */ public final class ChunkCoord implements Comparable, Serializable { public int chunkX; + public int chunkZ; public ChunkCoord(Chunk chunk) @@ -37,26 +38,26 @@ public final class ChunkCoord implements Comparable, Serializable this.chunkZ = z; } - public int getCenterX () + public int getCenterX() { return (this.chunkX << 4) + 8; } - public int getCenterZ () + public int getCenterZ() { return (this.chunkZ << 4) + 8; } - public ChunkCoord copy () + public ChunkCoord copy() { - return new ChunkCoord(chunkX, chunkZ); + return new ChunkCoord(this.chunkX, this.chunkZ); } @Override - public boolean equals (Object obj) + public boolean equals(Object obj) { if (!(obj instanceof ChunkCoord)) @@ -68,16 +69,16 @@ public final class ChunkCoord implements Comparable, Serializable } @Override - public int hashCode () + public int hashCode() { - int hash = chunkX; + int hash = this.chunkX; hash *= 31 + this.chunkZ; return hash; } @Override - public String toString () + public String toString() { return "[" + this.chunkX + ", " + this.chunkZ + "]"; @@ -85,7 +86,7 @@ public final class ChunkCoord implements Comparable, Serializable /* Comparable */ @Override - public int compareTo (ChunkCoord other) + public int compareTo(ChunkCoord other) { return this.chunkX == other.chunkX ? this.chunkZ - other.chunkZ : this.chunkX - other.chunkX; diff --git a/src/mantle/world/CoordTuplePair.java b/src/mantle/world/CoordTuplePair.java index 2bee4f4..5a59570 100644 --- a/src/mantle/world/CoordTuplePair.java +++ b/src/mantle/world/CoordTuplePair.java @@ -10,6 +10,7 @@ import net.minecraft.util.BlockPos; public class CoordTuplePair { public BlockPos a; + public BlockPos b; public CoordTuplePair(BlockPos a, BlockPos b) @@ -23,4 +24,4 @@ public class CoordTuplePair this.a = new BlockPos(aX, aY, aZ); this.b = new BlockPos(bX, bY, bZ); } -} \ No newline at end of file +} diff --git a/src/mantle/world/DimensionCoordPair.java b/src/mantle/world/DimensionCoordPair.java index 660b3c5..8f8a8f6 100644 --- a/src/mantle/world/DimensionCoordPair.java +++ b/src/mantle/world/DimensionCoordPair.java @@ -8,49 +8,56 @@ package mantle.world; public class DimensionCoordPair { public final int dim; + public final int x; + public final int z; public DimensionCoordPair(int worldID, int posX, int posZ) { - dim = worldID; - x = posX; - z = posZ; + this.dim = worldID; + this.x = posX; + this.z = posZ; } - public boolean equalCoords (int worldID, int posX, int posZ) + public boolean equalCoords(int worldID, int posX, int posZ) { return this.dim == posX && this.x == posX && this.z == posZ; } @Override - public boolean equals (Object obj) + public boolean equals(Object obj) { if (obj == null) + { return false; + } - if (getClass() == obj.getClass()) + if (this.getClass() == obj.getClass()) { DimensionCoordPair coord = (DimensionCoordPair) obj; if (this.dim == coord.dim && this.x == coord.x && this.z == coord.z) + { return true; + } } return false; } @Override - public int hashCode () + public int hashCode() { final int prime = 37; int result = 1; - result = prime * result + dim; - result = prime * result + x; - result = prime * result + z; + result = prime * result + this.dim; + result = prime * result + this.x; + result = prime * result + this.z; return result; } - public String toString () + @Override + public String toString() { - return "Dim: " + dim + ", X: " + x + ", Z: " + z; + return "Dim: " + this.dim + ", X: " + this.x + ", Z: " + this.z; } } diff --git a/src/mantle/world/DimensionCoordTuple.java b/src/mantle/world/DimensionCoordTuple.java index 8ee1bdd..b35fe04 100644 --- a/src/mantle/world/DimensionCoordTuple.java +++ b/src/mantle/world/DimensionCoordTuple.java @@ -9,51 +9,57 @@ package mantle.world; public class DimensionCoordTuple { public final int dim; + public final int x; + public final int y; + public final int z; public DimensionCoordTuple(int worldID, int posX, int posY, int posZ) { - dim = worldID; - y = posY; - x = posX; - z = posZ; + this.dim = worldID; + this.y = posY; + this.x = posX; + this.z = posZ; } - public boolean equalCoords (int worldID, int posX, int posY, int posZ) + public boolean equalCoords(int worldID, int posX, int posY, int posZ) { return this.dim == worldID && this.x == posX && this.y == posY && this.z == posZ; } @Override - public boolean equals (Object obj) + public boolean equals(Object obj) { if (obj == null) + { return false; + } - if (getClass() == obj.getClass()) + if (this.getClass() == obj.getClass()) { DimensionCoordTuple coord = (DimensionCoordTuple) obj; - return equalCoords(coord.dim, coord.x, coord.y, coord.z); + return this.equalCoords(coord.dim, coord.x, coord.y, coord.z); } return false; } @Override - public int hashCode () + public int hashCode() { final int prime = 37; int result = 1; - result = prime * result + dim; - result = prime * result + x; - result = prime * result + y; - result = prime * result + z; + result = prime * result + this.dim; + result = prime * result + this.x; + result = prime * result + this.y; + result = prime * result + this.z; return result; } - public String toString () + @Override + public String toString() { - return "Dim: " + dim + ", X: " + x + ", Y: " + y + ", Z: " + z; + return "Dim: " + this.dim + ", X: " + this.x + ", Y: " + this.y + ", Z: " + this.z; } } diff --git a/src/mantle/world/DirectionUtils.java b/src/mantle/world/DirectionUtils.java index 3d1fbd4..5b4aa20 100644 --- a/src/mantle/world/DirectionUtils.java +++ b/src/mantle/world/DirectionUtils.java @@ -16,12 +16,12 @@ public class DirectionUtils // No instantiation } - public static boolean isRightAngles (EnumFacing a, EnumFacing b) + public static boolean isRightAngles(EnumFacing a, EnumFacing b) { return a != b && a != b.getOpposite(); } - public static boolean isHorizontal (EnumFacing a) + public static boolean isHorizontal(EnumFacing a) { return a == EnumFacing.EAST || a == EnumFacing.NORTH || a == EnumFacing.SOUTH || a == EnumFacing.WEST; }