Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jolteffect.justsolars.tileentity;
- import com.jolteffect.justsolars.block.BlockSolarPanel;
- import com.jolteffect.justsolars.init.ModBlocks;
- import com.jolteffect.justsolars.utility.EnumSolarTier;
- import com.jolteffect.justsolars.utility.LogHelper;
- import net.darkhax.tesla.api.implementation.BaseTeslaContainer;
- import net.darkhax.tesla.api.implementation.InfiniteTeslaProducer;
- import net.darkhax.tesla.capability.TeslaCapabilities;
- import net.darkhax.tesla.lib.TeslaUtils;
- import net.minecraft.block.properties.PropertyEnum;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.ITickable;
- import net.minecraft.world.biome.BiomeDesert;
- import net.minecraftforge.common.capabilities.Capability;
- public class TileEntitySolarPanel extends TileEntity implements ITickable {
- public BaseTeslaContainer container;
- public boolean seesSun = false;
- public boolean active = false;
- public TileEntitySolarPanel() {
- // Initializes the container. Very straight forward.
- this.container = new BaseTeslaContainer();
- }
- @Override
- public void readFromNBT(NBTTagCompound compound) {
- super.readFromNBT(compound);
- // It is important for the power being stored to be persistent. The
- // BaseTeslaContainer
- // includes a method to make reading one from a compound tag very easy.
- // This method is
- // completely optional though, you can handle saving however you prefer.
- // You could even
- // choose not to, but then power won't be saved when you close the game.
- this.container = new BaseTeslaContainer(
- compound.getCompoundTag("TeslaContainer"));
- }
- @Override
- public NBTTagCompound writeToNBT(NBTTagCompound compound) {
- // It is important for the power being stored to be persistent. The
- // BaseTeslaContainer
- // includes a method to make writing one to a compound tag very easy.
- // This method is
- // completely optional though, you can handle saving however you prefer.
- // You could even
- // choose not to, but then power won't be saved when you close the game.
- compound.setTag("TeslaContainer", this.container.serializeNBT());
- return super.writeToNBT(compound);
- }
- @Override
- @SuppressWarnings("unchecked")
- public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
- // This method is where other things will try to access your
- // TileEntity's Tesla
- // capability. In the case of the analyzer, is a consumer, producer and
- // holder so we
- // can allow requests that are looking for any of those things. This
- // example also does
- // not care about which side is being accessed, however if you wanted to
- // restrict which
- // side can be used, for example only allow power input through the
- // back, that could be
- // done here.
- if (capability == TeslaCapabilities.CAPABILITY_PRODUCER)
- return (T) this.container;
- return super.getCapability(capability, facing);
- }
- @Override
- public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
- // This method replaces the instanceof checks that would be used in an
- // interface based
- // system. It can be used by other things to see if the TileEntity uses
- // a capability or
- // not. This example is a Consumer, Producer and Holder, so we return
- // true for all
- // three. This can also be used to restrict access on certain sides, for
- // example if you
- // only accept power input from the bottom of the block, you would only
- // return true for
- // Consumer if the facing parameter was down.
- if (capability == TeslaCapabilities.CAPABILITY_PRODUCER)
- return true;
- return super.hasCapability(capability, facing);
- }
- @Override
- public void update() {
- //EnumSolarTier solarTiers =
- LogHelper.logInfo("JUSTSOLARS --------------Get Value = " + this.worldObj.getBlockState(pos).getValue(BlockSolarPanel.TIER));
- LogHelper.logInfo("JUSTSOLARS --------------Get Value = " + this.worldObj.getBlockState(pos).getValue());
- if (!worldObj.isRemote) {
- if (worldObj.isDaytime()
- && ((!worldObj.isRaining() && !worldObj.isThundering()) || isDesert())
- && !worldObj.provider.getHasNoSky()
- && worldObj.canSeeSky(getPos().add(0, 4, 0))) {
- seesSun = true;
- } else {
- seesSun = false;
- }
- }
- if (seesSun) {
- active = true;
- //EnumSolarTier solarTier = this.worldObj.getBlockState(this.pos).getValue(BlockSolarPanel.TIER);
- //TeslaUtils.distributePowerToAllFaces(this.worldObj, this.pos, solarTiers.getPowerTransferLimit(), false);
- } else {
- active = false;
- }
- }
- public boolean isDesert() {
- return worldObj.provider.getBiomeForCoords(getPos()).getBiomeClass() == BiomeDesert.class;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement