Jump to content

Recommended Posts

Posted

Hey guys, back again with another problem

So basically i created a Creative Energy Cell to test my blocks with, and made my gui check if my pulverizer has power to draw a certain section on the gui, now when i place my Energy Cell next to it, it gains power and draws the GUI, however, when i placed a generator from another mods (JAPTA) the pulverizer gained power, but didnt draw.

I have no idea whats the cause of this or if im implementing the energy methods wrong in my TE

 

GUI Code:

package abused_master.JATMA.gui.machine;

import abused_master.JATMA.Info;
import abused_master.JATMA.tileentities.container.machine.PulverizerContainer;
import abused_master.JATMA.tileentities.machine.TilePulverizer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

public class GuiPulverizer extends GuiContainer {

private static final ResourceLocation Pulverizer = new ResourceLocation(Info.MODID, "textures/gui/pulverizer_gui.png");
    public static final int WIDTH = 176;
    public static final int HEIGHT = 166;
    TilePulverizer pulverizer;

    public GuiPulverizer(TilePulverizer tileEntity, PulverizerContainer container, TileEntity te) {
        super(container);
        xSize = WIDTH;
        ySize = HEIGHT;
        pulverizer = (TilePulverizer) tileEntity;
    }
    
    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
        mc.getTextureManager().bindTexture(Pulverizer);
        drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
        
        if (pulverizer.powerStored > 0) {
            drawTexturedModalRect(guiLeft + 9, guiTop + 8, 177, 3, 14, 42);
            System.out.println("EnergyBar is being drawn!");
        }
    }
}

 

TilePulverizer:

public class TilePulverizer extends TileEnergyHandler implements ITickable {

public EnergyStorage storage = new EnergyStorage(50000);
        public boolean hasPower;
        public int powerStored;
    
@Override
public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	storage.readFromNBT(nbt);
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);
	return storage.writeToNBT(nbt);
}

@Override
public boolean canConnectEnergy(EnumFacing from) {

	return true;
}

@Override
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
	return storage.receiveEnergy(maxReceive, simulate);
}

@Override
public int getEnergyStored(EnumFacing from) {

	return storage.getEnergyStored();
}

@Override
public int getMaxEnergyStored(EnumFacing from) {

	return storage.getMaxEnergyStored();
}

@Override
public void update() {
	if (storage.getEnergyStored() > 0) {
		powerStored = storage.getEnergyStored();
	}
}
}

Posted

also Creative Energy Cell:

public class TileCreativeEnergyCell extends TileEntity implements IEnergyReceiver, IEnergyProvider, ITickable {

protected EnergyStorage storage = new EnergyStorage(1000000000);
    public static int SENDPERTICK = 6000;

@Override
public void readFromNBT(NBTTagCompound nbt) {

	super.readFromNBT(nbt);
	storage.readFromNBT(nbt);
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {

	super.writeToNBT(nbt);
	return storage.writeToNBT(nbt);
}

@Override
public boolean canConnectEnergy(EnumFacing from) {

	return true;
}

@Override
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {

	return storage.receiveEnergy(maxReceive, simulate);
}

@Override
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {

	return storage.extractEnergy(maxExtract = 1000000, simulate);
}
@Override
public int getEnergyStored(EnumFacing from) {

	return storage.getEnergyStored();
}

@Override
public int getMaxEnergyStored(EnumFacing from) {

	return storage.getMaxEnergyStored();
}

 public static boolean isEnergyTE(TileEntity te) {
        return te instanceof IEnergyHandler || (te != null && te.hasCapability(CapabilityEnergy.ENERGY, null));
    }

 public static int receiveEnergy(TileEntity tileEntity, EnumFacing from, int maxReceive) {
        if (tileEntity instanceof IEnergyReceiver) {
            return ((IEnergyReceiver) tileEntity).receiveEnergy(from, maxReceive, false);
        } else if (tileEntity != null && tileEntity.hasCapability(CapabilityEnergy.ENERGY, from)) {
            IEnergyStorage capability = tileEntity.getCapability(CapabilityEnergy.ENERGY, from);
            if (capability.canReceive()) {
                return capability.receiveEnergy(maxReceive, false);
            }
        }
        return 0;
    }

@Override
public void update() {
	storage.setEnergyStored(1000000000);

	int energyStored = getEnergyStored(EnumFacing.DOWN);

        for (EnumFacing facing : EnumFacing.values()) {
            BlockPos pos = getPos().offset(facing);
            TileEntity te = worldObj.getTileEntity(pos);
            if (isEnergyTE(te)) {
            EnumFacing opposite = facing.getOpposite();
                int rfToGive = SENDPERTICK <= energyStored ? SENDPERTICK : energyStored;
                int received;
                
                if (te instanceof IEnergyConnection) {
                    IEnergyConnection connection = (IEnergyConnection) te;
                    if (connection.canConnectEnergy(opposite)) {
                        received = receiveEnergy(te, opposite, rfToGive);
                    } else {
                        received = 0;
                    }
                } else {
                    received = receiveEnergy(te, opposite, rfToGive);
                }
                energyStored -= storage.extractEnergy(received, false);
                if (energyStored <= 0) {
                    break;
                }
            }
        }
	}
}

Posted

also Creative Energy Cell:

public class TileCreativeEnergyCell extends TileEntity implements IEnergyReceiver, IEnergyProvider, ITickable {

protected EnergyStorage storage = new EnergyStorage(1000000000);
    public static int SENDPERTICK = 6000;

@Override
public void readFromNBT(NBTTagCompound nbt) {

	super.readFromNBT(nbt);
	storage.readFromNBT(nbt);
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {

	super.writeToNBT(nbt);
	return storage.writeToNBT(nbt);
}

@Override
public boolean canConnectEnergy(EnumFacing from) {

	return true;
}

@Override
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {

	return storage.receiveEnergy(maxReceive, simulate);
}

@Override
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {

	return storage.extractEnergy(maxExtract = 1000000, simulate);
}
@Override
public int getEnergyStored(EnumFacing from) {

	return storage.getEnergyStored();
}

@Override
public int getMaxEnergyStored(EnumFacing from) {

	return storage.getMaxEnergyStored();
}

 public static boolean isEnergyTE(TileEntity te) {
        return te instanceof IEnergyHandler || (te != null && te.hasCapability(CapabilityEnergy.ENERGY, null));
    }

 public static int receiveEnergy(TileEntity tileEntity, EnumFacing from, int maxReceive) {
        if (tileEntity instanceof IEnergyReceiver) {
            return ((IEnergyReceiver) tileEntity).receiveEnergy(from, maxReceive, false);
        } else if (tileEntity != null && tileEntity.hasCapability(CapabilityEnergy.ENERGY, from)) {
            IEnergyStorage capability = tileEntity.getCapability(CapabilityEnergy.ENERGY, from);
            if (capability.canReceive()) {
                return capability.receiveEnergy(maxReceive, false);
            }
        }
        return 0;
    }

@Override
public void update() {
	storage.setEnergyStored(1000000000);

	int energyStored = getEnergyStored(EnumFacing.DOWN);

        for (EnumFacing facing : EnumFacing.values()) {
            BlockPos pos = getPos().offset(facing);
            TileEntity te = worldObj.getTileEntity(pos);
            if (isEnergyTE(te)) {
            EnumFacing opposite = facing.getOpposite();
                int rfToGive = SENDPERTICK <= energyStored ? SENDPERTICK : energyStored;
                int received;
                
                if (te instanceof IEnergyConnection) {
                    IEnergyConnection connection = (IEnergyConnection) te;
                    if (connection.canConnectEnergy(opposite)) {
                        received = receiveEnergy(te, opposite, rfToGive);
                    } else {
                        received = 0;
                    }
                } else {
                    received = receiveEnergy(te, opposite, rfToGive);
                }
                energyStored -= storage.extractEnergy(received, false);
                if (energyStored <= 0) {
                    break;
                }
            }
        }
	}
}

You need to sync your data using onDataPacket and getUpdatePacket in your TilePulverizer.

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.

Posted

I  have absolutely no idea if i did it right or not but was helped by TheCodedOne

@Nullable
    @Override
    public SPacketUpdateTileEntity getUpdatePacket() {
        NBTTagCompound data = new NBTTagCompound();
        writeToNBT(data);
        return new SPacketUpdateTileEntity(this.pos, 1, data);
    }
    
    @Override
    @SideOnly(Side.CLIENT)
    public void onDataPacket(NetworkManager networkManager, SPacketUpdateTileEntity s35PacketUpdateTileEntity) {
        readFromNBT(s35PacketUpdateTileEntity.getNbtCompound());
        worldObj.markBlockRangeForRenderUpdate(this.pos, this.pos);
        markForUpdate();
    }
    

    public void markForUpdate() {
        if (this.worldObj != null) {
            Block block = worldObj.getBlockState(this.pos).getBlock();
            this.worldObj.notifyBlockUpdate(this.pos, worldObj.getBlockState(this.pos), worldObj.getBlockState(this.pos), 3);
            int xCoord = this.pos.getX();
            int yCoord = this.pos.getY();
            int zCoord = this.pos.getZ();
        }
    }

Posted

I  have absolutely no idea if i did it right or not but was helped by TheCodedOne

@Nullable
    @Override
    public SPacketUpdateTileEntity getUpdatePacket() {
        NBTTagCompound data = new NBTTagCompound();
        writeToNBT(data);
        return new SPacketUpdateTileEntity(this.pos, 1, data);
    }
    
    @Override
    @SideOnly(Side.CLIENT)
    public void onDataPacket(NetworkManager networkManager, SPacketUpdateTileEntity s35PacketUpdateTileEntity) {
        readFromNBT(s35PacketUpdateTileEntity.getNbtCompound());
        worldObj.markBlockRangeForRenderUpdate(this.pos, this.pos);
        markForUpdate();
    }
    

    public void markForUpdate() {
        if (this.worldObj != null) {
            Block block = worldObj.getBlockState(this.pos).getBlock();
            this.worldObj.notifyBlockUpdate(this.pos, worldObj.getBlockState(this.pos), worldObj.getBlockState(this.pos), 3);
            int xCoord = this.pos.getX();
            int yCoord = this.pos.getY();
            int zCoord = this.pos.getZ();
        }
    }

Looks correct except for this

            int xCoord = this.pos.getX();
            int yCoord = this.pos.getY();
            int zCoord = this.pos.getZ();

They serve no purpose.

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.

Posted

I  have absolutely no idea if i did it right or not but was helped by TheCodedOne

@Nullable
    @Override
    public SPacketUpdateTileEntity getUpdatePacket() {
        NBTTagCompound data = new NBTTagCompound();
        writeToNBT(data);
        return new SPacketUpdateTileEntity(this.pos, 1, data);
    }
    
    @Override
    @SideOnly(Side.CLIENT)
    public void onDataPacket(NetworkManager networkManager, SPacketUpdateTileEntity s35PacketUpdateTileEntity) {
        readFromNBT(s35PacketUpdateTileEntity.getNbtCompound());
        worldObj.markBlockRangeForRenderUpdate(this.pos, this.pos);
        markForUpdate();
    }
    

    public void markForUpdate() {
        if (this.worldObj != null) {
            Block block = worldObj.getBlockState(this.pos).getBlock();
            this.worldObj.notifyBlockUpdate(this.pos, worldObj.getBlockState(this.pos), worldObj.getBlockState(this.pos), 3);
            int xCoord = this.pos.getX();
            int yCoord = this.pos.getY();
            int zCoord = this.pos.getZ();
        }
    }

Looks correct except for this

            int xCoord = this.pos.getX();
            int yCoord = this.pos.getY();
            int zCoord = this.pos.getZ();

They serve no purpose.

 

Removed, it still doesnt fix the problem though

Posted

I  have absolutely no idea if i did it right or not but was helped by TheCodedOne

@Nullable
    @Override
    public SPacketUpdateTileEntity getUpdatePacket() {
        NBTTagCompound data = new NBTTagCompound();
        writeToNBT(data);
        return new SPacketUpdateTileEntity(this.pos, 1, data);
    }
    
    @Override
    @SideOnly(Side.CLIENT)
    public void onDataPacket(NetworkManager networkManager, SPacketUpdateTileEntity s35PacketUpdateTileEntity) {
        readFromNBT(s35PacketUpdateTileEntity.getNbtCompound());
        worldObj.markBlockRangeForRenderUpdate(this.pos, this.pos);
        markForUpdate();
    }
    

    public void markForUpdate() {
        if (this.worldObj != null) {
            Block block = worldObj.getBlockState(this.pos).getBlock();
            this.worldObj.notifyBlockUpdate(this.pos, worldObj.getBlockState(this.pos), worldObj.getBlockState(this.pos), 3);
            int xCoord = this.pos.getX();
            int yCoord = this.pos.getY();
            int zCoord = this.pos.getZ();
        }
    }

Looks correct except for this

            int xCoord = this.pos.getX();
            int yCoord = this.pos.getY();
            int zCoord = this.pos.getZ();

They serve no purpose.

 

Removed, it still doesnt fix the problem though

When your data changes call markDirty();

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.

Posted

so would i do a check in say my update method to check when the power say gets greater than 0 then this.markDirty();?

Your receiveEnergy is where the energy gets changed.

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.

Posted

so would i do a check in say my update method to check when the power say gets greater than 0 then this.markDirty();?

Your receiveEnergy is where the energy gets changed.

 

I thought it might be and did try but that didnt change anything so i thought it must be another way of doing it

Posted

so would i do a check in say my update method to check when the power say gets greater than 0 then this.markDirty();?

Your receiveEnergy is where the energy gets changed.

 

I thought it might be and did try but that didnt change anything so i thought it must be another way of doing it

There are two other methods I forgot to say getUpdateTag, and handleUpdateTag. Those were recently brought to my attention.

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.

Posted

so would it be like this?

    @Override
    public NBTTagCompound getUpdateTag() {
    	return super.getUpdateTag();
    }
    
   @Override
public void handleUpdateTag(NBTTagCompound tag) {
super.handleUpdateTag(tag);
}

Posted

UpdateTag is more of a "first spawn" thing.  Also, if you only call super, there's no reason to override.  You actually need:

 

	@Override
@Nullable
public SPacketUpdateTileEntity getUpdatePacket() {
	return new SPacketUpdateTileEntity(this.pos, 3, this.getUpdateTag());
}

@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
	super.onDataPacket(net, pkt);
	handleUpdateTag(pkt.getNbtCompound());
}

 

These are the methods called to synchronize TEs.

 

See also: http://www.minecraftforge.net/forum/index.php?topic=43417.msg231329#msg231329

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

UpdateTag is more of a "first spawn" thing.  Also, if you only call super, there's no reason to override.  You actually need:

 

	@Override
@Nullable
public SPacketUpdateTileEntity getUpdatePacket() {
	return new SPacketUpdateTileEntity(this.pos, 3, this.getUpdateTag());
}

@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
	super.onDataPacket(net, pkt);
	handleUpdateTag(pkt.getNbtCompound());
}

 

These are the methods called to synchronize TEs.

 

See also: http://www.minecraftforge.net/forum/index.php?topic=43417.msg231329#msg231329

 

Ty so much, was able to fix my problem, didnt know that those methods are now needed to sync the data

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.

Announcements



×
×
  • Create New...

Important Information

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