Jump to content

Where to learn about power system


Terrails

Recommended Posts

If someone knows the answer how I can print my energy storage that would be helpful. But another question how do I fix this visual bug, if I put an ender IO conduit under my solar panel, the conduit doesn't connect to it but the power is still getting extracted from the solar. I know I have a lot of question but I'm new to Energy Systems. Is that problem on Ender IO's side or is it on my side?

050ea5bb9abadf78003f2a782ba90a52.png

Link to comment
Share on other sites

It is probably because of a difference in functionality. EnderIO expects you to do nothing with the energy, and let the conduits handle the extracting and receiving of energy like most mods do. You are continuously outputting to the TileEntity underneath, even when EnderIO's conduit has a disabled connection to the top.

Edited by larsgerrits

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

2 hours ago, larsgerrits said:

It is probably because of a difference in functionality. EnderIO expects you to do nothing with the energy, and let the conduits handle the extracting and receiving of energy like most mods do. You are continuously outputting to the TileEntity underneath, even when EnderIO's conduit has a disabled connection to the top.

That is actually wrong information, not your fault though I fell for it myself. Ender IO and most other 'RF' mods(there are exceptions) expect you to push the energy out yourself.

2 hours ago, Terrails said:

What can I do with it than? Just make the bottom side provide energy somehow?

You need to expose your BaseEnergyContainer as a Capability for the connection to take place. And in the case of sending the message when it is right clicked (not sure if this has been solved already) you can create a getter method for your container field.

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I have a problem, do I need to extend my BaseEnergyContainer with TileEntity and add getCapability and hasCapability like this. It still doesn't work. Thanks for the getter method I totally forgot about that!

Spoiler

        @Override
        public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
            if (capability == CapabilityEnergy.ENERGY)
                return (T) this;

            return super.getCapability(capability, facing);
        }

        @Override
        public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
            if (capability == CapabilityEnergy.ENERGY)
                return true;

            return super.hasCapability(capability, facing);
        }

 

 

Link to comment
Share on other sites

  • Like 1

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

So I just made the Battery input power on all sides except the bottom which is used for output. The problem now is how do I store my power when I break the block, so when I place the block again it has the same amount of power. I know I do it in breakBlock method but how do I store it, and if anyone knows how can I change the input/output sides with specified item, I'll take a look into mods like Ender IO to see how they do it for now.

This is what I have done so far.

Block:

Spoiler

package terrails.minedustry.common.machine.battery;

import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import terrails.minedustry.Constants;

import javax.annotation.Nullable;
import java.util.Random;

public class BlockBasicBattery extends Block implements ITileEntityProvider {

    public static final PropertyDirection FACING = BlockHorizontal.FACING;
    String name = "basic_battery";

    public BlockBasicBattery() {
        super(Material.ROCK);
        setUnlocalizedName(name);
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
        this.isBlockContainer = true;
        this.setHardness(1.5f);
        this.setResistance(10f);
        this.setLightOpacity(0);
        setRegistryName(name);
        GameRegistry.register(this);
        GameRegistry.register(new ItemBlock(this), getRegistryName());
        GameRegistry.registerTileEntity(TileEntityBasicBattery.class, Constants.MODID + "_" + name);
    }

    private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state){
        if (!worldIn.isRemote){
            IBlockState iblockstate = worldIn.getBlockState(pos.north());
            IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
            IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
            IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
            EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

            if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock()){
                enumfacing = EnumFacing.SOUTH;
            }
            else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock()){
                enumfacing = EnumFacing.NORTH;
            }
            else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock()){
                enumfacing = EnumFacing.EAST;
            }
            else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock()){
                enumfacing = EnumFacing.WEST;
            }

            worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
        }
    }

    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand,
                                    @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        TileEntityBasicBattery te = (TileEntityBasicBattery) worldIn.getTileEntity(pos);
        if(playerIn.getActiveHand() == hand.MAIN_HAND || playerIn.getActiveHand() == hand.OFF_HAND)
            playerIn.sendStatusMessage(new TextComponentString(te.storedEnergy + "/" + te.maxEnergy));
        return true;

    }

    @SideOnly(Side.CLIENT)
    public void initModel() {
        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
    }

    public TileEntity createNewTileEntity(World worldIn, int meta){
        return new TileEntityBasicBattery();
    }

    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }

    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack){
        worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);

        if (stack.hasDisplayName()){
            TileEntity tileentity = worldIn.getTileEntity(pos);
            }
        }

    public EnumBlockRenderType getRenderType(IBlockState state){
        return EnumBlockRenderType.MODEL;
    }


    public IBlockState getStateFromMeta(int meta){
        EnumFacing enumfacing = EnumFacing.getFront(meta);

        if (enumfacing.getAxis() == EnumFacing.Axis.Y){
            enumfacing = EnumFacing.NORTH;
        }
        return this.getDefaultState().withProperty(FACING, enumfacing);
    }

    public int getMetaFromState(IBlockState state){
        return ((EnumFacing)state.getValue(FACING)).getIndex();
    }

    public IBlockState withRotation(IBlockState state, Rotation rot){
        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    }

    public IBlockState withMirror(IBlockState state, Mirror mirrorIn){
        return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    }

    protected BlockStateContainer createBlockState(){
        return new BlockStateContainer(this, new IProperty[] {FACING});
    }
}

 

TE:

Spoiler

package terrails.minedustry.common.machine.battery;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import terrails.minedustry.common.machine.BaseEnergyContainer;

public class TileEntityBasicBattery extends BaseEnergyContainer implements ITickable {

    int input = 2500;
    int output = 2500;
    int maxEnergy = 1000000;
    int storedEnergy;

    public TileEntityBasicBattery() {
        setMaxEnergyStored(maxEnergy);
        setMaxInput(input);
        setMaxOutput(output);
    }

    @Override
    public void update() {
        if (this.hasWorld() && !this.world.isRemote && getEnergyStored() != getMaxEnergyStored()) {
            this.canReceive();
            this.storedEnergy = this.getEnergyStored();

            final TileEntity tileEntity = this.getWorld().getTileEntity(this.getPos().offset(EnumFacing.DOWN));

            if (tileEntity != null && !tileEntity.isInvalid()) {
                if (tileEntity.hasCapability(CapabilityEnergy.ENERGY, EnumFacing.UP)) {
                    IEnergyStorage consumer = tileEntity.getCapability(CapabilityEnergy.ENERGY, EnumFacing.UP);

                    if (consumer != null)
                        this.extractEnergy(consumer.receiveEnergy(output, false), false);
                }
            }
        }
    }
}

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.