Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[UNSOLVED]Strange things happen with my energysystem[1.8]


ItsAMysteriousYT
 Share

Recommended Posts

  • Replies 99
  • Created
  • Last Reply

Top Posters In This Topic

This is my packet - am i doing it the correct way?

package itsamysterious.mods.reallifemod.core.packets;

import java.nio.ByteBuffer;

import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

public class ElectricDataPackage implements IMessage{
float voltage;

public ElectricDataPackage() {
}

public ElectricDataPackage(float voltage){
	this.voltage=voltage;
}

@Override
public void fromBytes(ByteBuf buf) {
	voltage = buf.readFloat();
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeFloat(voltage);
}


}

 

Now i don't know what excactly to do in the packethandler. I tried passing the value through a static variable in my custom overlayclass, but it didn't work.

 

Thats what i tried:

package itsamysterious.mods.reallifemod.core.packets;

import java.awt.Color;

import itsamysterious.mods.reallifemod.core.gui.lifesystem.RLMOverlay;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class VoltagePackethandler implements IMessageHandler<ElectricDataPackage, ElectricDataPackage>{

@Override
public ElectricDataPackage onMessage(ElectricDataPackage message, MessageContext ctx) {
	RLMOverlay.voltage=message.voltage;
	return message;
}

}

Link to comment
Share on other sites

Okay - the energysystem is working pretty well now, just two thing - first:

The blocks do not immediatly update their lighting value(e.g. lanterns)

 

Second:

The rotation still does not work in onBlockPlacedBy:

My code is

@Override
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    	super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
    	 TileEntity tileentity = worldIn.getTileEntity(pos);
         if (tileentity instanceof TileEntity_Electric){
        	 TileEntity_Electric tile = (TileEntity_Electric)tileentity;
        	 tile.rotation = MathHelper.floor_double((double)(placer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
             System.out.println("Succesfully rotated "+tile.getClass().getName());
         }
    }

 

Perhaps it is necessary to say that im extending my own CustomBlock class and not the default BlockClass for the electrisity blocks?

Link to comment
Share on other sites

A well okay - now. I found a way doing it with a clientOnly method and render it on the tileentity - see:

@SideOnly(Side.CLIENT)
public float clientVoltage;

        //Update method
       if(worldObj.isRemote)
       {
	this.clientVoltage=getVoltage();
       }

SO, that thing is fixed now - thanks :)

 

Don't use @SideOnly.. It is not for those cases.

Just use packet with the position to sync information.

(Keep in mind that clientside tileentity and serverside tileentity is different instance)

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

It works, but the point is you don't need a new variable to hold the information.  Just use the same variable you already had.  You're not going to break anything.

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.

Link to comment
Share on other sites

*Facepalm*

 

You get the data out of the packet the same way it got in.  Its not fucking magic.

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.

Link to comment
Share on other sites

  • 2 weeks later...

Okay, there still are some tiny bugs that i wanna fix but i don't know how:

1. When i connect two blocks e.g a powersource with a lantern, the lanternblock itself gets updatet(becomes a lightvalue), but not the blocks around it. Even if i make markBlockForUpdtate on it.

2. The voltage in a block itself does not get updated immediatly sometimes(At least it does not show up when i draw a string with that voltage)

 

PS: For number two, i use @SideOnly(Side.CLIENT) variables which i set in a (worldObj.isRemote) check.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share




×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.