Code style fixes
This commit is contained in:
@@ -1,40 +1,30 @@
|
||||
package refinedstorage.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Enchantments;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.item.ItemBlockBase;
|
||||
import refinedstorage.item.ItemBlockController;
|
||||
import refinedstorage.tile.TileController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockController extends BlockBase {
|
||||
public static final PropertyEnum TYPE = PropertyEnum.create("type", EnumControllerType.class);
|
||||
@@ -99,7 +89,7 @@ public class BlockController extends BlockBase {
|
||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
||||
((TileController) world.getTileEntity(pos)).onDestroyed();
|
||||
|
||||
super.breakBlock(world,pos,state);
|
||||
super.breakBlock(world, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,13 +113,12 @@ public class BlockController extends BlockBase {
|
||||
super.onBlockPlacedBy(world, pos, state, player, itemStack);
|
||||
|
||||
NBTTagCompound tag = itemStack.getTagCompound();
|
||||
if(tag != null)
|
||||
{
|
||||
|
||||
if (tag != null) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileController)
|
||||
{
|
||||
TileController controller = (TileController)tile;
|
||||
controller.readNBT(tag);
|
||||
|
||||
if (tile instanceof TileController) {
|
||||
((TileController) tile).readItemOrBlockNBT(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,7 +130,7 @@ public class BlockController extends BlockBase {
|
||||
ItemStack stack = new ItemStack(RefinedStorageBlocks.CONTROLLER, 1, RefinedStorageBlocks.CONTROLLER.getMetaFromState(state));
|
||||
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
((TileController) world.getTileEntity(pos)).writeNBT(tag);
|
||||
((TileController) world.getTileEntity(pos)).writeItemOrBlockNBT(tag);
|
||||
stack.setTagCompound(tag);
|
||||
|
||||
drops.add(stack);
|
||||
@@ -164,6 +153,4 @@ public class BlockController extends BlockBase {
|
||||
public Item createItemForBlock() {
|
||||
return new ItemBlockController();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
28
src/main/java/refinedstorage/item/ItemBlockController.java
Normal file → Executable file
28
src/main/java/refinedstorage/item/ItemBlockController.java
Normal file → Executable file
@@ -1,19 +1,16 @@
|
||||
package refinedstorage.item;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.block.EnumControllerType;
|
||||
import refinedstorage.block.EnumStorageType;
|
||||
import refinedstorage.tile.TileController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by zyberwax on 05.04.2016.
|
||||
*/
|
||||
public class ItemBlockController extends ItemBlockBase {
|
||||
public ItemBlockController() {
|
||||
super(RefinedStorageBlocks.CONTROLLER, true);
|
||||
@@ -24,22 +21,15 @@ public class ItemBlockController extends ItemBlockBase {
|
||||
EnumControllerType type = stack.getMetadata() == EnumControllerType.CREATIVE.getId() ? EnumControllerType.CREATIVE : EnumControllerType.NORMAL;
|
||||
|
||||
int energyStored = 0;
|
||||
int capacity = TileController.ENERGY_CAPACITY;
|
||||
int percent = 0;
|
||||
int capacity = TileController.ENERGY_CAPACITY;
|
||||
|
||||
if(type == EnumControllerType.CREATIVE) {
|
||||
if (type == EnumControllerType.CREATIVE) {
|
||||
energyStored = capacity;
|
||||
percent = 100;
|
||||
} else if (stack.getTagCompound() != null && stack.getTagCompound().hasKey(TileController.NBT_ENERGY)) {
|
||||
energyStored = stack.getTagCompound().getInteger(TileController.NBT_ENERGY);
|
||||
}
|
||||
else if (stack.getTagCompound() != null && stack.getTagCompound().hasKey(TileController.NBT_ENERGY)) {
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
|
||||
energyStored = tag.getInteger(TileController.NBT_ENERGY);
|
||||
percent = (int)((float)energyStored / (capacity) * 100);
|
||||
}
|
||||
//TODO: Format numbers ?
|
||||
list.add("RF: " + energyStored + "/" + capacity + " (" + percent + "%)");
|
||||
|
||||
list.add(I18n.format("misc.refinedstorage:energy_stored", energyStored, capacity));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,8 +41,12 @@ public class ItemBlockController extends ItemBlockBase {
|
||||
|
||||
public static ItemStack initNBT(ItemStack stack) {
|
||||
EnumControllerType type = stack.getMetadata() == EnumControllerType.CREATIVE.getId() ? EnumControllerType.CREATIVE : EnumControllerType.NORMAL;
|
||||
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
if(tag == null) tag = new NBTTagCompound();
|
||||
|
||||
if (tag == null) {
|
||||
tag = new NBTTagCompound();
|
||||
}
|
||||
|
||||
tag.setInteger(TileController.NBT_ENERGY, type == EnumControllerType.CREATIVE ? TileController.ENERGY_CAPACITY : 0);
|
||||
|
||||
|
||||
@@ -365,10 +365,11 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
readNBT(nbt);
|
||||
|
||||
readItemOrBlockNBT(nbt);
|
||||
}
|
||||
|
||||
public void readNBT(NBTTagCompound nbt) {
|
||||
public void readItemOrBlockNBT(NBTTagCompound nbt) {
|
||||
energy.readFromNBT(nbt);
|
||||
|
||||
if (nbt.hasKey(RedstoneMode.NBT)) {
|
||||
@@ -379,10 +380,11 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
writeNBT(nbt);
|
||||
|
||||
writeItemOrBlockNBT(nbt);
|
||||
}
|
||||
|
||||
public void writeNBT(NBTTagCompound nbt) {
|
||||
public void writeItemOrBlockNBT(NBTTagCompound nbt) {
|
||||
energy.writeToNBT(nbt);
|
||||
nbt.setInteger(RedstoneMode.NBT, redstoneMode.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user