Some more work on solar panels.
This commit is contained in:
parent
0aa8974035
commit
e0edff6891
9 changed files with 45 additions and 28 deletions
|
@ -27,6 +27,7 @@ package techreborn.blocks.generator.solarpanel;
|
|||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -58,31 +59,38 @@ public class BlockSolarPanel extends BaseTileBlock {
|
|||
public static final String[] panes = new String[] {
|
||||
"Basic", "Hybrid", "Advanced", "Ultimate", "Quantum"};
|
||||
public static final IProperty<EnumPanelType> TYPE = PropertyEnum.create("type", EnumPanelType.class);
|
||||
public static PropertyBool ACTIVE = PropertyBool.create("active");
|
||||
private static final List<String> paneList = Lists.newArrayList(panes);
|
||||
|
||||
public BlockSolarPanel() {
|
||||
super(Material.IRON);
|
||||
setCreativeTab(TechRebornCreativeTab.instance);
|
||||
this.setDefaultState(this.getBlockState().getBaseState().withProperty(TYPE, EnumPanelType.Basic));
|
||||
this.setDefaultState(this.getBlockState().getBaseState().withProperty(TYPE, EnumPanelType.Basic).withProperty(ACTIVE, false));
|
||||
setHardness(2.0F);
|
||||
this.setDefaultState(this.getStateFromMeta(0));
|
||||
for (int i = 0; i < panes.length; i++) {
|
||||
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i, "machines/generators").setInvVariant("type=" + panes[i]));
|
||||
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i, "machines/generators").setInvVariant("type=" + panes[i] + ",active=false"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(TYPE).ordinal();
|
||||
int active = state.getValue(ACTIVE) ? EnumPanelType.values().length : 0;
|
||||
return state.getValue(TYPE).ordinal() + active;
|
||||
}
|
||||
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, new IProperty[]{TYPE});
|
||||
return new BlockStateContainer(this, TYPE, ACTIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState().withProperty(TYPE, EnumPanelType.values()[meta]);
|
||||
boolean active = false;
|
||||
if(meta >= EnumPanelType.values().length){
|
||||
active = true;
|
||||
meta -= EnumPanelType.values().length;
|
||||
}
|
||||
return getDefaultState().withProperty(TYPE, EnumPanelType.values()[meta]).withProperty(ACTIVE, active);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,7 +3,8 @@ package techreborn.itemblocks;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import techreborn.blocks.generator.solarpanel.EnumPanelType;
|
||||
import techreborn.blocks.generator.solarpanel.BlockSolarPanel;
|
||||
import techreborn.init.ModBlocks;
|
||||
|
||||
public class ItemBlockSolarPanel extends ItemBlock {
|
||||
|
||||
|
@ -13,6 +14,6 @@ public class ItemBlockSolarPanel extends ItemBlock {
|
|||
}
|
||||
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
return super.getUnlocalizedName() + "." + EnumPanelType.values()[stack.getItemDamage()].getName();
|
||||
return super.getUnlocalizedName() + "." + ModBlocks.SOLAR_PANEL.getStateFromMeta(stack.getItemDamage()).getValue(BlockSolarPanel.TYPE).getName().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import reborncore.api.power.EnumPowerTier;
|
|||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import techreborn.Core;
|
||||
import techreborn.blocks.generator.solarpanel.BlockSolarPanel;
|
||||
import techreborn.blocks.generator.solarpanel.EnumPanelType;
|
||||
import techreborn.init.ModBlocks;
|
||||
|
||||
|
@ -42,6 +43,7 @@ import java.util.List;
|
|||
public class TileSolarPanel extends TilePowerAcceptor implements IToolDrop {
|
||||
|
||||
boolean canSeeSky = false;
|
||||
boolean lastSate = false;
|
||||
int powerToAdd;
|
||||
EnumPanelType panel;
|
||||
|
||||
|
@ -62,6 +64,12 @@ public class TileSolarPanel extends TilePowerAcceptor implements IToolDrop {
|
|||
}
|
||||
if (world.getTotalWorldTime() % 20 == 0) {
|
||||
canSeeSky = this.world.canBlockSeeSky(this.pos.up());
|
||||
if(lastSate != this.isSunOut()){
|
||||
this.world.setBlockState(this.getPos(),
|
||||
this.world.getBlockState(this.getPos()).withProperty(BlockSolarPanel.ACTIVE, this.isSunOut()));
|
||||
lastSate = isSunOut();
|
||||
}
|
||||
|
||||
}
|
||||
if (isSunOut()) {
|
||||
this.powerToAdd = panel.generationRateD;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue