Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Mar 18, 2016
1 parent ddea705 commit 9fa56c7
Show file tree
Hide file tree
Showing 23 changed files with 300 additions and 335 deletions.
2 changes: 1 addition & 1 deletion src/main/java/slimeknights/mantle/Mantle.java
Expand Up @@ -16,7 +16,7 @@
*
* @author Sunstrike <sun@sunstrike.io>
*/
@Mod(modid = Mantle.modId, name = Mantle.modName, version = Mantle.modVersion, dependencies = "required-after:Forge@[11.15,)", acceptedMinecraftVersions="[1.8.8,1.8.9]")
@Mod(modid = Mantle.modId, name = Mantle.modName, version = Mantle.modVersion, dependencies = "required-after:Forge@[11.15,)", acceptedMinecraftVersions = "[1.8.8,1.8.9]")
public class Mantle {

public static final String modId = "mantle";
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/slimeknights/mantle/block/BlockInventory.java
Expand Up @@ -10,9 +10,9 @@
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;

import slimeknights.mantle.tileentity.TileInventory;
Expand Down Expand Up @@ -86,8 +86,7 @@ public int damageDropped(IBlockState state) {
// BlockContainer sets this to invisible
// we need model for standard forge rendering
@Override
public EnumBlockRenderType getRenderType(IBlockState state)
{
public EnumBlockRenderType getRenderType(IBlockState state) {
return EnumBlockRenderType.MODEL;
}
}
4 changes: 3 additions & 1 deletion src/main/java/slimeknights/mantle/block/EnumBlock.java
Expand Up @@ -15,6 +15,7 @@
import java.util.List;

public class EnumBlock<E extends Enum<E> & EnumBlock.IEnumMeta & IStringSerializable> extends Block {

public final PropertyEnum<E> prop;
private final E[] values;

Expand All @@ -28,7 +29,7 @@ public EnumBlock(Material material, PropertyEnum<E> prop, Class<E> clazz) {

@SuppressWarnings("unchecked")
private static Material preInit(Material material, PropertyEnum<?> property) {
tmp=property;
tmp = property;
return material;
}

Expand Down Expand Up @@ -72,6 +73,7 @@ protected E fromMeta(int meta) {
}

public interface IEnumMeta {

int getMeta();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/slimeknights/mantle/client/ModelHelper.java
Expand Up @@ -73,7 +73,8 @@ public static BakedQuad colorQuad(int color, BakedQuad quad) {
data[i * 7 + 3] = c;
}

return new BakedQuad(data, quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.shouldApplyDiffuseLighting(), quad.getFormat());
return new BakedQuad(data, quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad
.shouldApplyDiffuseLighting(), quad.getFormat());
}

public static Map<String, String> loadTexturesFromJson(ResourceLocation location) throws IOException {
Expand All @@ -100,8 +101,7 @@ public static ResourceLocation getModelLocation(ResourceLocation location) {
return new ResourceLocation(location.getResourceDomain(), "models/" + location.getResourcePath() + ".json");
}

private static TRSRTransformation get(float tx, float ty, float tz, float ax, float ay, float az, float s)
{
private static TRSRTransformation get(float tx, float ty, float tz, float ax, float ay, float az, float s) {
return TRSRTransformation.blockCenterToCorner(new TRSRTransformation(
new Vector3f(tx / 16, ty / 16, tz / 16),
TRSRTransformation.quatFromXYZDegrees(new Vector3f(ax, ay, az)),
Expand All @@ -128,7 +128,7 @@ ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND, get(1.13f, 3.2f, 1.1
}
{
BLOCK_THIRD_PERSON_RIGHT = get(0, 2.5f, 0, 75, 45, 0, 0.375f);
BLOCK_THIRD_PERSON_LEFT = get(0, 0, 0, 0, 255, 0, 0.4f);
BLOCK_THIRD_PERSON_LEFT = get(0, 0, 0, 0, 255, 0, 0.4f);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/slimeknights/mantle/client/gui/GuiModule.java
Expand Up @@ -6,9 +6,8 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.awt.Rectangle;
import java.awt.*;
import java.io.IOException;
import java.util.List;

// a sub-gui. Mostly the same as a separate GuiContainer, but doesn't do the calls that affect the game as if this were the only gui
@SideOnly(Side.CLIENT)
Expand Down
Expand Up @@ -58,7 +58,7 @@ protected void addModule(GuiModule module) {

public List<Rectangle> getModuleAreas() {
List<Rectangle> areas = new ArrayList<Rectangle>(modules.size());
for (GuiModule module : modules) {
for(GuiModule module : modules) {
areas.add(module.getArea());
}
return areas;
Expand Down Expand Up @@ -98,7 +98,7 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
drawContainerName();
drawPlayerInventoryName();

for(GuiModule module : modules) {
// set correct state for the module
GlStateManager.pushMatrix();
Expand Down
@@ -1,8 +1,6 @@
package slimeknights.mantle.client.model;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
Expand All @@ -21,7 +19,6 @@
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
import net.minecraftforge.client.model.pipeline.VertexTransformer;

import java.util.EnumMap;
import java.util.List;

import javax.vecmath.Matrix3f;
Expand Down Expand Up @@ -161,7 +158,7 @@ else if(usage == VertexFormatElement.EnumUsage.NORMAL && data.length >= 3) {
}

public UnpackedBakedQuad build() {
return ((UnpackedBakedQuad.Builder)parent).build();
return ((UnpackedBakedQuad.Builder) parent).build();
}
}
}
13 changes: 8 additions & 5 deletions src/main/java/slimeknights/mantle/item/ItemBlockMeta.java
Expand Up @@ -8,8 +8,8 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemColored;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameData;
Expand All @@ -32,15 +32,17 @@ public ItemBlockMeta(Block block) {

@Override
public String getUnlocalizedName(ItemStack stack) {
if(mappingProperty == null) return super.getUnlocalizedName(stack);
if(mappingProperty == null) {
return super.getUnlocalizedName(stack);
}

IBlockState state = block.getStateFromMeta(stack.getMetadata());
String name = state.getValue(mappingProperty).toString().toLowerCase(Locale.US);
return super.getUnlocalizedName(stack) + "." + name;
}

public static void setMappingProperty(Block block, IProperty<?> property) {
((ItemBlockMeta)Item.getItemFromBlock(block)).mappingProperty = property;
((ItemBlockMeta) Item.getItemFromBlock(block)).mappingProperty = property;
}

@Override
Expand All @@ -62,11 +64,12 @@ public void registerItemModels() {
final ResourceLocation loc = GameData.getBlockRegistry().getNameForObject(block);


for(Comparable o : (Collection<Comparable>)mappingProperty.getAllowedValues()) {
for(Comparable o : (Collection<Comparable>) mappingProperty.getAllowedValues()) {
int meta = block.getMetaFromState(block.getDefaultState().withProperty(mappingProperty, o));
String name = mappingProperty.getName(o);

ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(loc, mappingProperty.getName() + "=" + name));
ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(loc, mappingProperty
.getName() + "=" + name));
}
}
}
17 changes: 9 additions & 8 deletions src/main/java/slimeknights/mantle/item/ItemEdible.java
Expand Up @@ -37,11 +37,12 @@ public ItemEdible() {

/**
* Add a new food type!
* @param meta Metadata to use, has to be free
* @param food How much food it restores on eating
* @param saturation Saturation multiplier on the food
* @param name Unlocalized postfix
* @param effects PotionEffects that will be applied on eating. The PotionEffect passed will be directly applied
*
* @param meta Metadata to use, has to be free
* @param food How much food it restores on eating
* @param saturation Saturation multiplier on the food
* @param name Unlocalized postfix
* @param effects PotionEffects that will be applied on eating. The PotionEffect passed will be directly applied
* @return Itemstack containing the registered item
*/
public ItemStack addFood(int meta, int food, float saturation, String name, PotionEffect... effects) {
Expand All @@ -67,10 +68,10 @@ public int getHealAmount(ItemStack stack) {

@Override
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
if (!worldIn.isRemote)
{
if(!worldIn.isRemote) {
for(PotionEffect potion : potionEffects.get(stack.getMetadata())) {
player.addPotionEffect(new PotionEffect(potion.getPotion(), potion.getDuration(), potion.getAmplifier(), potion.getIsAmbient(), potion.doesShowParticles()));
player.addPotionEffect(new PotionEffect(potion.getPotion(), potion.getDuration(), potion.getAmplifier(), potion
.getIsAmbient(), potion.doesShowParticles()));
}
}
}
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/slimeknights/mantle/item/ItemMetaDynamic.java
Expand Up @@ -41,20 +41,24 @@ public ItemMetaDynamic() {

/**
* Add a valid metadata.
* @param meta The metadata value
* @param name The name used for registering the itemmodel as well as the unlocalized name of the meta. The unlocalized name will be lowercased and stripped of whitespaces.
*
* @param meta The metadata value
* @param name The name used for registering the itemmodel as well as the unlocalized name of the meta. The unlocalized name will be lowercased and stripped of whitespaces.
* @return An itemstack representing the Item-Meta combination.
*/
public ItemStack addMeta(int meta, String name) {
if(meta > MAX) {
throw new IllegalArgumentException(String.format("Metadata for %s too high, highest supported value is %d. Meta was %d", name, MAX, meta));
throw new IllegalArgumentException(String
.format("Metadata for %s too high, highest supported value is %d. Meta was %d", name, MAX, meta));
}
else if(isValid(meta)) {
throw new IllegalArgumentException(String.format("Metadata for %s is already taken. Meta %d is %s", name, meta, names.get(meta)));
throw new IllegalArgumentException(String
.format("Metadata for %s is already taken. Meta %d is %s", name, meta, names
.get(meta)));
}

while(meta >= availabilityMask.length) {
availabilityMask = Arrays.copyOf(availabilityMask, availabilityMask.length*2);
availabilityMask = Arrays.copyOf(availabilityMask, availabilityMask.length * 2);
}
setValid(meta);
names.put(meta, name);
Expand All @@ -64,10 +68,12 @@ else if(isValid(meta)) {
@Override
public String getUnlocalizedName(ItemStack stack) {
int meta = stack.getMetadata(); // should call getMetadata below
if(isValid(meta))
if(isValid(meta)) {
return super.getUnlocalizedName(stack) + "." + LocUtils.makeLocString(names.get(meta));
else
}
else {
return super.getUnlocalizedName(stack);
}
}

@Override
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/slimeknights/mantle/multiblock/IMasterLogic.java
Expand Up @@ -2,11 +2,12 @@

import net.minecraft.util.math.BlockPos;

public interface IMasterLogic
{
/** Called when servants change their state
*
* @param pos servant position
*/
void notifyChange(IServantLogic servant, BlockPos pos);
public interface IMasterLogic {

/**
* Called when servants change their state
*
* @param pos servant position
*/
void notifyChange(IServantLogic servant, BlockPos pos);
}
8 changes: 4 additions & 4 deletions src/main/java/slimeknights/mantle/multiblock/IMasterNode.java
@@ -1,8 +1,8 @@
package slimeknights.mantle.multiblock;

public interface IMasterNode extends IMasterLogic, IServantLogic
{
boolean isCurrentlyMaster();
public interface IMasterNode extends IMasterLogic, IServantLogic {

boolean isEquivalentMaster(IMasterLogic master);
boolean isCurrentlyMaster();

boolean isEquivalentMaster(IMasterLogic master);
}
68 changes: 33 additions & 35 deletions src/main/java/slimeknights/mantle/multiblock/IServantLogic.java
Expand Up @@ -3,39 +3,37 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public interface IServantLogic
{
BlockPos getMasterPosition();

/** The block should already have a valid master */
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
*/

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 pos position of master
* @return Is this block tied to this master?
*/

boolean verifyMaster(IMasterLogic master, World world, BlockPos pos);

/** Exactly what it says on the tin
*
* @param master
* @param world
* @param pos position of master
*/

void invalidateMaster(IMasterLogic master, World world, BlockPos pos);
public interface IServantLogic {

BlockPos getMasterPosition();

/** The block should already have a valid master */
void notifyMasterOfChange();

/**
* Checks if this block can be tied to this master
*
* @param world the world of master
* @param pos position of master
* @return whether the servant can be tied to this master
*/

boolean setPotentialMaster(IMasterLogic master, World world, BlockPos pos);

/**
* Used to set and verify that this is the block's master
*
* @param pos position of master
* @return Is this block tied to this master?
*/

boolean verifyMaster(IMasterLogic master, World world, BlockPos pos);

/**
* Exactly what it says on the tin
*
* @param pos position of master
*/

void invalidateMaster(IMasterLogic master, World world, BlockPos pos);
}

0 comments on commit 9fa56c7

Please sign in to comment.