Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.jonak.upower.generics
- import me.jonak.upower.block.tileentities.TilePowerBank
- import me.jonak.upower.core.UPower
- import me.jonak.upower.material.MaterialMachine
- import net.minecraft.block.properties.PropertyInteger
- import net.minecraft.block.state.{BlockStateContainer, IBlockState}
- import net.minecraft.block.{Block, ITileEntityProvider}
- import net.minecraft.item.Item
- import net.minecraft.tileentity.TileEntity
- import net.minecraft.util.math.BlockPos
- import net.minecraft.world.{IBlockAccess, World}
- /**
- * Created by jonak on 5/10/2016.
- */
- object BlockGenericPowerBank
- {
- var CHARGE_PERCENT: PropertyInteger = PropertyInteger.create("charge_percent", 0, 10)
- }
- abstract class BlockGenericPowerBank(maxEnergy: Int, maxOutput: Int, name: String = "powerbank_generic")
- extends Block(new MaterialMachine) with ITileEntityProvider
- {
- import BlockGenericPowerBank._
- private final val blockName = name
- protected val item: Item
- def getName: String = blockName
- def getItem: Item = item
- def registerRecipe(): Unit // Registers the block's recipe.
- override def createNewTileEntity(worldIn: World, meta: Int): TileEntity =
- {
- println("Placed Tile: " + (if(worldIn.isRemote) "SERVER" else "CLIENT"))
- new TilePowerBank(0, maxEnergy, maxOutput)
- }
- override def createBlockState: BlockStateContainer = new BlockStateContainer(this, CHARGE_PERCENT)
- override def getActualState(state: IBlockState, worldIn: IBlockAccess, pos: BlockPos): IBlockState =
- {
- val tileHere = worldIn.getTileEntity(pos).asInstanceOf[TilePowerBank]
- val currentPower = tileHere.getPowerContained
- val maxPower = tileHere.getMaxPower
- val percentTen = TilePowerBank.getPercentTen(maxPower, currentPower)
- setLightLevel(percentTen.toInt / 10)
- println("State updated: " + currentPower + "/" + maxPower + "/" + percentTen)
- return state.withProperty(CHARGE_PERCENT, percentTen)
- }
- override def getMetaFromState(state: IBlockState): Int = state.getValue[Integer](CHARGE_PERCENT)
- override def getStateFromMeta(meta: Int): IBlockState = getDefaultState.withProperty(CHARGE_PERCENT, Integer.valueOf(meta))
- setUnlocalizedName(name) // Sets the unlocalized name based on initialization parameters.
- setRegistryName(name) // Sets the registry name based on the initialization parameters.
- setCreativeTab(UPower.uPowerCreativeTab) // Sets the tab to the mod's creative tab.
- setDefaultState(getBlockState.getBaseState.withProperty(CHARGE_PERCENT, Integer.valueOf(0))) // Sets the default state to 0% charge.
- }
Add Comment
Please, Sign In to add comment