Im not too sure how to make packets, what I've made so far changes all of the tileentities
In the below attachments you can see that the pipes are treated as a whole not individually when being rendered - any help on this would be nice (not sure if this is related to the packets)
public boolean num1 = false;
public boolean num2 = false;
public boolean num3 = false;
public boolean num4 = false;
public boolean num5 = false;
public boolean num6 = false;
public void checkForNeighbors(World world, int x, int y, int z) {
if (world.getBlock(x - 1, y, z) == GunnCraftBlocks.Pipe){
num1 = true;
System.out.println("tested block left true");
}
if (world.getBlock(x + 1, y, z) == GunnCraftBlocks.Pipe){
num2 = true;
System.out.println("tested block right true");
}
if (world.getBlock(x, y, z - 1) == GunnCraftBlocks.Pipe){
num3 = true;
System.out.println("tested block front true");
}
if (world.getBlock(x, y, z + 1) == GunnCraftBlocks.Pipe){
num4 = true;
System.out.println("tested block back true");
}
if (world.getBlock(x, y + 1, z) == GunnCraftBlocks.Pipe){
num5 = true;
System.out.println("tested block top true");
}
if (world.getBlock(x, y - 1, z) == GunnCraftBlocks.Pipe){
num6 = true;
System.out.println("tested block bottom true");
}
}
public void shouldRenderMiddle(float f5){
middle.render(f5);
}
public void shouldRenderLeft(float f5){
if(num1 == true){
left.render(f5);
}
}
public void shouldRenderRight(float f5){
if(num2 == true){
right.render(f5);
}
}
public void shouldRenderFront(float f5){
if(num3 == true){
front.render(f5);
}
}
public void shouldRenderBack(float f5){
if(num4 == true){
back.render(f5);
}
}
public void shouldRenderTop(float f5){
if(num5 == true){
top.render(f5);
}
}
public void shouldRenderBottom(float f5){
if(num6 == true){
bottom.render(f5);
}
}
@Override
public Packet getDescriptionPacket(){
return null;
}
public void onDataPacket(){
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirty();
}
public boolean num1 = false;
public boolean num2 = false;
public boolean num3 = false;
public boolean num4 = false;
public boolean num5 = false;
public boolean num6 = false;
public void checkForNeighbors(World world, int x, int y, int z) {
if (world.getBlock(x - 1, y, z) == GunnCraftBlocks.Pipe){
num1 = true;
System.out.println("tested block left true");
}
if (world.getBlock(x + 1, y, z) == GunnCraftBlocks.Pipe){
num2 = true;
System.out.println("tested block right true");
}
if (world.getBlock(x, y, z - 1) == GunnCraftBlocks.Pipe){
num3 = true;
System.out.println("tested block front true");
}
if (world.getBlock(x, y, z + 1) == GunnCraftBlocks.Pipe){
num4 = true;
System.out.println("tested block back true");
}
if (world.getBlock(x, y + 1, z) == GunnCraftBlocks.Pipe){
num5 = true;
System.out.println("tested block top true");
}
if (world.getBlock(x, y - 1, z) == GunnCraftBlocks.Pipe){
num6 = true;
System.out.println("tested block bottom true");
}
}
}
If anyone could figure this out it would be greatly appreciated!
P.S. Rename the Handler.java to something like MessageSyncTile.java (because the handler is a subclass) and for TargetPoint you have only to import it from cpw.mods.fml.common.network.NetworkRegistry.TargetPoint
ops for the readInt() my bad i thinked they was number (because i wasn't looking at your code when realising the packet) because the var name num(ber)1 ecc
for the sync problem you have to call sync() when you finished to check neighbours:
public void checkForNeighbors() {
World world = this.worldObj;
int x = this.xCoord;
int y = this.yCoord;
int z = this.zCoord;
if (world.getBlock(x - 1, y, z) == GunnCraftBlocks.Pipe){
num1 = true;
System.out.println("tested block left true");
}
if (world.getBlock(x + 1, y, z) == GunnCraftBlocks.Pipe){
num2 = true;
System.out.println("tested block right true");
}
if (world.getBlock(x, y, z - 1) == GunnCraftBlocks.Pipe){
num3 = true;
System.out.println("tested block front true");
}
if (world.getBlock(x, y, z + 1) == GunnCraftBlocks.Pipe){
num4 = true;
System.out.println("tested block back true");
}
if (world.getBlock(x, y + 1, z) == GunnCraftBlocks.Pipe){
num5 = true;
System.out.println("tested block top true");
}
if (world.getBlock(x, y - 1, z) == GunnCraftBlocks.Pipe){
num6 = true;
System.out.println("tested block bottom true");
}
sync()
}
P.S.
I don't know where you call the check but i suggest you to do this in your block to update only when necessary (calling it every tick would lag the server cause to getBlock iteraction):
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block par5) {
if (!world.isRemote) {
TileEntityPipe tileEntity = (TileEntityPipe) world.getTileEntity(x, y, z);
if (tileEntity != null) {
tileEntity.checkForNeighbors();
}
}
}
P.S. I modified checkForNeighbors to take the tile world and coords because pass other coords wouldn't make any sense considering it saves the vars into an instance of tile
P.S. I modified checkForNeighbors to take the tile world and coords because pass other coords wouldn't make any sense considering it saves the vars into an instance of tile
except this ^ didn't know what coords or integers (still relatively new to modding)
however when I place a single pipe it renders as it should (rendering only this.model.shouldRenderMiddle(0.0625F)) but when I place the second it crashes
console -- Head -- Stacktrace:
at com.gunnthorian.block.TileEntityPipe.sync(TileEntityPipe.java:84)
at com.gunnthorian.block.TileEntityPipe.checkForNeighbors(TileEntityPipe.java:61)
at com.gunnthorian.block.Pipe.onNeighborBlockChange(Pipe.java:31)
you forgot the @EventHandler over init BUT you don't need it because you can use the Load function that is called on init because you put FMLInitializationEvent as argument.
and you don't have to put NetworkRegistry.INSTANCE.newSimpleChannel(((Mod) Main.class.getAnnotation(Mod.class)).modid()); but you have to put
MessagesHandler.registerPackets();
remove the init that you created and rename Load TO init.
you mustn't create a new tileentity because it will not be associated with a physical block and will not update values. one moment and I'll write the correction.
to explain to you simply the num1 variable doesn't exist in TileEntity but only in TileEntityPipe. the argument is a TileEntity then it don't show the num1 variable and to access to it you need to cast the TileEntity to TileEntityPipe if you don't really understand it I suggest you to look at this https://howtoprogramwithjava.com/java-cast/
Im not too sure how to make packets, what I've made so far changes all of the tileentities
In the below attachments you can see that the pipes are treated as a whole not individually when being rendered - any help on this would be nice (not sure if this is related to the packets)
code:
ModelPipe:
package com.gunnthorian.model;
import java.util.Random;
import com.gunnthorian.block.GunnCraftBlocks;
import com.gunnthorian.block.Pipe;
import com.gunnthorian.renderer.RenderPipe;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class ModelPipe extends ModelBase{
private static final TileEntity TileEntity = null;
private static final float F = 0;
//fields
ModelRenderer middle;
ModelRenderer left;
ModelRenderer right;
ModelRenderer front;
ModelRenderer back;
ModelRenderer top;
ModelRenderer bottom;
public ModelPipe()
{
textureWidth = 32;
textureHeight = 32;
middle = new ModelRenderer(this, 0, 0);
middle.addBox(0F, 0F, 0F, 6, 6, 6);
middle.setRotationPoint(-3F, 13F, -3F);
middle.setTextureSize(32, 32);
middle.mirror = true;
setRotation(middle, 0F, 0F, 0F);
left = new ModelRenderer(this, 0, 12);
left.addBox(0F, 0F, 0F, 5, 6, 6);
left.setRotationPoint(3F, 13F, -3F);
left.setTextureSize(32, 32);
left.mirror = true;
setRotation(left, 0F, 0F, 0F);
right = new ModelRenderer(this, 0, 12);
right.addBox(0F, 0F, 0F, 5, 6, 6);
right.setRotationPoint(-3F, 13F, 3F);
right.setTextureSize(32, 32);
right.mirror = true;
setRotation(right, 0F, -3.141593F, 0F);
front = new ModelRenderer(this, 0, 12);
front.addBox(0F, 0F, 0F, 5, 6, 6);
front.setRotationPoint(-3F, 13F, -3F);
front.setTextureSize(32, 32);
front.mirror = true;
setRotation(front, 0F, 1.570796F, 0F);
back = new ModelRenderer(this, 0, 12);
back.addBox(0F, 0F, 0F, 5, 6, 6);
back.setRotationPoint(3F, 13F, 3F);
back.setTextureSize(32, 32);
back.mirror = true;
setRotation(back, 0F, -1.570796F, 0F);
top = new ModelRenderer(this, 0, 12);
top.addBox(0F, 0F, 0F, 5, 6, 6);
top.setRotationPoint(-3F, 13F, -3F);
top.setTextureSize(32, 32);
top.mirror = true;
setRotation(top, 0F, 0F, -1.570796F);
bottom = new ModelRenderer(this, 0, 12);
bottom.addBox(0F, 0F, 0F, 5, 6, 6);
bottom.setRotationPoint(3F, 19F, -3F);
bottom.setTextureSize(32, 32);
bottom.mirror = true;
setRotation(bottom, 0F, 0F, 1.570796F);
}
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
{
super.render(entity, f, f1, f2, f3, f4, f5);
setRotationAngles(f, f1, f2, f3, f4, f5, entity);
middle.render(f5);
left.render(f5);
right.render(f5);
front.render(f5);
back.render(f5);
top.render(f5);
bottom.render(f5);
}
public boolean num1 = false;
public boolean num2 = false;
public boolean num3 = false;
public boolean num4 = false;
public boolean num5 = false;
public boolean num6 = false;
public void checkForNeighbors(World world, int x, int y, int z) {
if (world.getBlock(x - 1, y, z) == GunnCraftBlocks.Pipe){
num1 = true;
System.out.println("tested block left true");
}
if (world.getBlock(x + 1, y, z) == GunnCraftBlocks.Pipe){
num2 = true;
System.out.println("tested block right true");
}
if (world.getBlock(x, y, z - 1) == GunnCraftBlocks.Pipe){
num3 = true;
System.out.println("tested block front true");
}
if (world.getBlock(x, y, z + 1) == GunnCraftBlocks.Pipe){
num4 = true;
System.out.println("tested block back true");
}
if (world.getBlock(x, y + 1, z) == GunnCraftBlocks.Pipe){
num5 = true;
System.out.println("tested block top true");
}
if (world.getBlock(x, y - 1, z) == GunnCraftBlocks.Pipe){
num6 = true;
System.out.println("tested block bottom true");
}
}
public void shouldRenderMiddle(float f5){
middle.render(f5);
}
public void shouldRenderLeft(float f5){
if(num1 == true){
left.render(f5);
}
}
public void shouldRenderRight(float f5){
if(num2 == true){
right.render(f5);
}
}
public void shouldRenderFront(float f5){
if(num3 == true){
front.render(f5);
}
}
public void shouldRenderBack(float f5){
if(num4 == true){
back.render(f5);
}
}
public void shouldRenderTop(float f5){
if(num5 == true){
top.render(f5);
}
}
public void shouldRenderBottom(float f5){
if(num6 == true){
bottom.render(f5);
}
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
{
super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
}
}
/*//fields
ModelRenderer horrizShape1;
ModelRenderer horrizShape2;
ModelRenderer horrizShape3;
ModelRenderer horrizShape4;
ModelRenderer verticalShape1;
ModelRenderer verticalShape2;
ModelRenderer verticalShape3;
ModelRenderer verticalShape4;
ModelRenderer horriz2Shape1;
ModelRenderer horriz2Shape2;
ModelRenderer horriz2Shape3;
ModelRenderer horriz2Shape4;
public ModelPipe()
{
textureWidth = 16;
textureHeight = 16;
horrizShape1 = new ModelRenderer(this, 0, 0);
horrizShape1.addBox(0F, 0F, 0F, 16, 1, 1);
horrizShape1.setRotationPoint(-8F, 18F, 2F);
horrizShape1.setTextureSize(64, 32);
horrizShape1.mirror = true;
setRotation(horrizShape1, 0F, 0F, 0F);
horrizShape2 = new ModelRenderer(this, 0, 0);
horrizShape2.addBox(0F, 0F, 0F, 16, 1, 1);
horrizShape2.setRotationPoint(-8F, 18F, -3F);
horrizShape2.setTextureSize(64, 32);
horrizShape2.mirror = true;
setRotation(horrizShape2, 0F, 0F, 0F);
horrizShape3 = new ModelRenderer(this, 0, 0);
horrizShape3.addBox(0F, 0F, 0F, 16, 1, 1);
horrizShape3.setRotationPoint(-8F, 13F, 2F);
horrizShape3.setTextureSize(64, 32);
horrizShape3.mirror = true;
setRotation(horrizShape3, 0F, 0F, 0F);
horrizShape4 = new ModelRenderer(this, 0, 0);
horrizShape4.addBox(0F, 0F, 0F, 16, 1, 1);
horrizShape4.setRotationPoint(-8F, 13F, -3F);
horrizShape4.setTextureSize(64, 32);
horrizShape4.mirror = true;
setRotation(horrizShape4, 0F, 0F, 0F);
verticalShape1 = new ModelRenderer(this, 0, 0);
verticalShape1.addBox(0F, 0F, 0F, 1, 16, 1);
verticalShape1.setRotationPoint(-3F, 8F, 2F);
verticalShape1.setTextureSize(64, 32);
verticalShape1.mirror = true;
setRotation(verticalShape1, 0F, 0F, 0F);
verticalShape2 = new ModelRenderer(this, 0, 0);
verticalShape2.addBox(0F, 0F, 0F, 1, 16, 1);
verticalShape2.setRotationPoint(2F, 8F, 2F);
verticalShape2.setTextureSize(64, 32);
verticalShape2.mirror = true;
setRotation(verticalShape2, 0F, 0F, 0F);
verticalShape3 = new ModelRenderer(this, 0, 0);
verticalShape3.addBox(0F, 0F, 0F, 1, 16, 1);
verticalShape3.setRotationPoint(-3F, 8F, -3F);
verticalShape3.setTextureSize(64, 32);
verticalShape3.mirror = true;
setRotation(verticalShape3, 0F, 0F, 0F);
verticalShape4 = new ModelRenderer(this, 0, 0);
verticalShape4.addBox(0F, 0F, 0F, 1, 16, 1);
verticalShape4.setRotationPoint(2F, 8F, -3F);
verticalShape4.setTextureSize(64, 32);
verticalShape4.mirror = true;
setRotation(verticalShape1, 0F, 0F, 0F);
horriz2Shape1 = new ModelRenderer(this, 0, 0);
horriz2Shape1.addBox(0F, 0F, 0F, 1, 1, 16);
horriz2Shape1.setRotationPoint(-3F, 18F, -8F);
horriz2Shape1.setTextureSize(64, 32);
horriz2Shape1.mirror = true;
setRotation(horriz2Shape1, 0F, 0F, 0F);
horriz2Shape2 = new ModelRenderer(this, 0, 0);
horriz2Shape2.addBox(0F, 0F, 0F, 1, 1, 16);
horriz2Shape2.setRotationPoint(2F, 18F, -8F);
horriz2Shape2.setTextureSize(64, 32);
horriz2Shape2.mirror = true;
setRotation(horriz2Shape2, 0F, 0F, 0F);
horriz2Shape3 = new ModelRenderer(this, 0, 0);
horriz2Shape3.addBox(0F, 0F, 0F, 1, 1, 16);
horriz2Shape3.setRotationPoint(-3F, 13F, -8F);
horriz2Shape3.setTextureSize(64, 32);
horriz2Shape3.mirror = true;
setRotation(horriz2Shape3, 0F, 0F, 0F);
horriz2Shape4 = new ModelRenderer(this, 0, 0);
horriz2Shape4.addBox(0F, 0F, 0F, 1, 1, 16);
horriz2Shape4.setRotationPoint(2F, 13F, -8F);
horriz2Shape4.setTextureSize(64, 32);
horriz2Shape4.mirror = true;
setRotation(horriz2Shape4, 0F, 0F, 0F);
}
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
{
super.render(entity, f, f1, f2, f3, f4, f5);
setRotationAngles(f, f1, f2, f3, f4, f5, entity);
horrizShape1.render(f5);
horrizShape2.render(f5);
horrizShape3.render(f5);
horrizShape4.render(f5);
verticalShape1.render(f5);
verticalShape2.render(f5);
verticalShape3.render(f5);
verticalShape4.render(f5);
horriz2Shape1.render(f5);
horriz2Shape2.render(f5);
horriz2Shape3.render(f5);
horriz2Shape4.render(f5);
}
public boolean num1 = false;
public boolean num2 = false;
public boolean num3 = false;
* attempt to make a neighbor checking function
public void checkForNeighbors(World world, int x, int y, int z) {
if (world.getBlock(x - 1, y, z) == GunnCraftBlocks.Pipe){
num1 = true;
System.out.println("tested block num1 1 true");
}
if (world.getBlock(x + 1, y, z) == GunnCraftBlocks.Pipe){
num1 = true;
System.out.println("tested block num1 2 true");
}
if (world.getBlock(x, y - 1, z) == GunnCraftBlocks.Pipe){
num2 = true;
System.out.println("tested block num2 1 true");
}
if (world.getBlock(x, y + 1, z) == GunnCraftBlocks.Pipe){
num2 = true;
System.out.println("tested block num2 2 true");
}
if (world.getBlock(x, y, z - 1) == GunnCraftBlocks.Pipe){
num3 = true;
System.out.println("tested block num3 1 true");
}
if (world.getBlock(x, y, z + 1) == GunnCraftBlocks.Pipe){
num3 = true;
System.out.println("tested block num3 2 true");
}
}
public void shouldRenderModel1(float f5){
if(num1 == true){
horrizShape1.render(f5);
horrizShape2.render(f5);
horrizShape3.render(f5);
horrizShape4.render(f5);
}
}
public void shouldRenderModel2(float f5){
if(num2 == true){
verticalShape1.render(f5);
verticalShape2.render(f5);
verticalShape3.render(f5);
verticalShape4.render(f5);
}
}
public void shouldRenderModel3(float f5){
if(num3 == true){
horriz2Shape1.render(f5);
horriz2Shape2.render(f5);
horriz2Shape3.render(f5);
horriz2Shape4.render(f5);
}
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
{
super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
}
}*/
RenderPipe:
package com.gunnthorian.renderer;
import org.lwjgl.opengl.GL11;
import com.gunnthorian.block.Pipe;
import com.gunnthorian.lib.RefStrings;
import com.gunnthorian.model.ModelPipe;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
public class RenderPipe extends TileEntitySpecialRenderer{
ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/models/Pipe.png");
private ModelPipe model;
public RenderPipe(){
this.model = new ModelPipe();
}
publicvoid renderTileEntityAt(TileEntity entity, doublex, doubley, doublez, floatF) {
GL11.glPushMatrix();
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
GL11.glRotatef(180, 0F, 0F, 1F);
this.bindTexture(texture);
GL11.glPushMatrix();
this.model.checkForNeighbors(entity.getWorldObj(), entity.xCoord, entity.yCoord, entity.zCoord);
this.model.shouldRenderMiddle(0.0625F);
this.model.shouldRenderLeft(0.0625F);
this.model.shouldRenderRight(0.0625F);
this.model.shouldRenderFront(0.0625F);
this.model.shouldRenderBack(0.0625F);
this.model.shouldRenderTop(0.0625F);
this.model.shouldRenderBottom(0.0625F);
GL11.glPopMatrix();
GL11.glPopMatrix();
}
}
TileEntityPipe:
package com.gunnthorian.block;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
public class TileEntityPipe extends TileEntity {
@Override
public Packet getDescriptionPacket(){
returnnull;
}
publicvoid onDataPacket(){
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirty();
}
}
why are the boolean value outputs from TileEntityPipe all false when they are tested in ModelPipe?
ModelPipe:
package com.gunnthorian.model;
import java.util.Random;
import com.gunnthorian.block.GunnCraftBlocks;
import com.gunnthorian.block.Pipe;
import com.gunnthorian.block.TileEntityPipe;
import com.gunnthorian.renderer.RenderPipe;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class ModelPipe extends ModelBase{
private static final TileEntity TileEntity = null;
private static final float F = 0;
//fields
ModelRenderer middle;
ModelRenderer left;
ModelRenderer right;
ModelRenderer front;
ModelRenderer back;
ModelRenderer top;
ModelRenderer bottom;
public ModelPipe()
{
textureWidth = 32;
textureHeight = 32;
middle = new ModelRenderer(this, 0, 0);
middle.addBox(0F, 0F, 0F, 6, 6, 6);
middle.setRotationPoint(-3F, 13F, -3F);
middle.setTextureSize(32, 32);
middle.mirror = true;
setRotation(middle, 0F, 0F, 0F);
left = new ModelRenderer(this, 0, 12);
left.addBox(0F, 0F, 0F, 5, 6, 6);
left.setRotationPoint(3F, 13F, -3F);
left.setTextureSize(32, 32);
left.mirror = true;
setRotation(left, 0F, 0F, 0F);
right = new ModelRenderer(this, 0, 12);
right.addBox(0F, 0F, 0F, 5, 6, 6);
right.setRotationPoint(-3F, 13F, 3F);
right.setTextureSize(32, 32);
right.mirror = true;
setRotation(right, 0F, -3.141593F, 0F);
front = new ModelRenderer(this, 0, 12);
front.addBox(0F, 0F, 0F, 5, 6, 6);
front.setRotationPoint(-3F, 13F, -3F);
front.setTextureSize(32, 32);
front.mirror = true;
setRotation(front, 0F, 1.570796F, 0F);
back = new ModelRenderer(this, 0, 12);
back.addBox(0F, 0F, 0F, 5, 6, 6);
back.setRotationPoint(3F, 13F, 3F);
back.setTextureSize(32, 32);
back.mirror = true;
setRotation(back, 0F, -1.570796F, 0F);
top = new ModelRenderer(this, 0, 12);
top.addBox(0F, 0F, 0F, 5, 6, 6);
top.setRotationPoint(-3F, 13F, -3F);
top.setTextureSize(32, 32);
top.mirror = true;
setRotation(top, 0F, 0F, -1.570796F);
bottom = new ModelRenderer(this, 0, 12);
bottom.addBox(0F, 0F, 0F, 5, 6, 6);
bottom.setRotationPoint(3F, 19F, -3F);
bottom.setTextureSize(32, 32);
bottom.mirror = true;
setRotation(bottom, 0F, 0F, 1.570796F);
}
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
{
super.render(entity, f, f1, f2, f3, f4, f5);
setRotationAngles(f, f1, f2, f3, f4, f5, entity);
middle.render(f5);
left.render(f5);
right.render(f5);
front.render(f5);
back.render(f5);
top.render(f5);
bottom.render(f5);
}
TileEntityPipe tileentity = new TileEntityPipe();
boolean num1 = tileentity.num1;
boolean num2 = tileentity.num2;
boolean num3 = tileentity.num3;
boolean num4 = tileentity.num4;
boolean num5 = tileentity.num5;
boolean num6 = tileentity.num6;
public void shouldRenderMiddle(float f5){
middle.render(f5);
System.out.println(num1 + "," + num2 + "," + num3 + "," + num4 + "," + num5 + "," + num6);
}
public void shouldRenderLeft(float f5){
if(num1 == true){
left.render(f5);
}
}
public void shouldRenderRight(float f5){
if(num2 == true){
right.render(f5);
}
}
public void shouldRenderFront(float f5){
if(num3 == true){
front.render(f5);
}
}
public void shouldRenderBack(float f5){
if(num4 == true){
back.render(f5);
}
}
public void shouldRenderTop(float f5){
if(num5 == true){
top.render(f5);
}
}
public void shouldRenderBottom(float f5){
if(num6 == true){
bottom.render(f5);
}
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
{
super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
}
}
TileEntityPipe:
package com.gunnthorian.block;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class TileEntityPipe extends TileEntity {
@Override
public Packet getDescriptionPacket(){
return null;
}
public void onDataPacket(){
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirty();
}
public boolean num1 = false;
public boolean num2 = false;
public boolean num3 = false;
public boolean num4 = false;
public boolean num5 = false;
public boolean num6 = false;
public void checkForNeighbors(World world, int x, int y, int z) {
if (world.getBlock(x - 1, y, z) == GunnCraftBlocks.Pipe){
num1 = true;
System.out.println("tested block left true");
}
if (world.getBlock(x + 1, y, z) == GunnCraftBlocks.Pipe){
num2 = true;
System.out.println("tested block right true");
}
if (world.getBlock(x, y, z - 1) == GunnCraftBlocks.Pipe){
num3 = true;
System.out.println("tested block front true");
}
if (world.getBlock(x, y, z + 1) == GunnCraftBlocks.Pipe){
num4 = true;
System.out.println("tested block back true");
}
if (world.getBlock(x, y + 1, z) == GunnCraftBlocks.Pipe){
num5 = true;
System.out.println("tested block top true");
}
if (world.getBlock(x, y - 1, z) == GunnCraftBlocks.Pipe){
num6 = true;
System.out.println("tested block bottom true");
}
}
}
If anyone could figure this out it would be greatly appreciated!
You need to sync the server tile entity with the client, ths code may help you:
https://gist.github.com/andry08/1efedbb708310e4d5a5d (you have to create a message, this is going to be the handler)
https://gist.github.com/andry08/4ab90d2632b981d5d63e (you have to put this in your tile)
you have to change
to your custom messages handler and your custom packet
sorry for my bad english I'm Italian
I have the following errors in my code:
package com.gunnthorian.block;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class TileEntityPipe extends TileEntity {
@Override
public Packet getDescriptionPacket(){
returnnull;
}
publicvoid onDataPacket(){
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirty();
}
publicbooleannum1 = false;
publicbooleannum2 = false;
publicbooleannum3 = false;
publicbooleannum4 = false;
publicbooleannum5 = false;
publicbooleannum6 = false;
publicvoid checkForNeighbors(World world, intx, inty, intz) {
if (world.getBlock(x - 1, y, z) == GunnCraftBlocks.Pipe){
num1 = true;
System.out.println("tested block left true");
}
if (world.getBlock(x + 1, y, z) == GunnCraftBlocks.Pipe){
num2 = true;
System.out.println("tested block right true");
}
if (world.getBlock(x, y, z - 1) == GunnCraftBlocks.Pipe){
num3 = true;
System.out.println("tested block front true");
}
if (world.getBlock(x, y, z + 1) == GunnCraftBlocks.Pipe){
num4 = true;
System.out.println("tested block back true");
}
if (world.getBlock(x, y + 1, z) == GunnCraftBlocks.Pipe){
num5 = true;
System.out.println("tested block top true");
}
if (world.getBlock(x, y - 1, z) == GunnCraftBlocks.Pipe){
num6 = true;
System.out.println("tested block bottom true");
}
}
publicvoid sync() {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(bos);
try {
outputStream.writeInt(this.xCoord);
outputStream.writeInt(this.yCoord);
outputStream.writeInt(this.zCoord);
outputStream.writeBoolean(this.num1);
outputStream.writeBoolean(this.num2);
outputStream.writeBoolean(this.num3);
outputStream.writeBoolean(this.num4);
outputStream.writeBoolean(this.num5);
outputStream.writeBoolean(this.num6);
} catch (Exception ex) {
ex.printStackTrace();
}
if (this.worldObj != null && this.worldObj.provider != null) {
MessagesHandler.dispatcher.sendToAllAround(new MessageSyncTile(bos), new TargetPoint(this.worldObj.provider.dimensionId, this.xCoord, this.yCoord, this.zCoord, 8));
}
}
}
publicvoid recieveSync(booleanpar1, booleanpar2, booleanpar3, booleanpar4, booleanpar5, booleanpar6) {
this.num1 = par1;
this.num2 = par2;
this.num3 = par3;
this.num4 = par4;
this.num5 = par5;
this.num6 = par6;
}
}
package com.gunnthorian.handler;
import java.io.IOException;
import com.gunnthorian.block.TileEntityPipe;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
public static class Handler implements IMessageHandler<MessageSyncTile, IMessage> {
@Override
public IMessage onMessage(MessageSyncTile message, MessageContext ctx) {
if (!FMLCommonHandler.instance().getEffectiveSide().isClient())
returnnull;
try {
TileEntityPipe tep = (TileEntityPipe) FMLClientHandler.instance()
.getClientPlayerEntity().worldObj.getTileEntity(message.readbytes.readInt(),
message.readbytes.readInt(), message.readbytes.readInt());
if (tep != null) {
tep.recieveSync(message.readbytes.readInt(), message.readbytes.readInt(), message.readbytes.readInt(), message.readbytes.readInt(), message.readbytes.readInt(), message.readbytes.readInt());
}
} catch (IOException e) {
e.printStackTrace();
}
returnnull;
}
}
I'm having a hard time trying to figure out packets, thank you for the reply and coming up with the code for this!
--hopefully I edited it time before you read this, I had posted old code in one of the spoilers -- fixed now
as I wrote before you need to create a message, i posted to you only the handler.
I edited the handler.java and now it is the complete message https://gist.github.com/andry08/1efedbb708310e4d5a5d
And this is the MessagesHandler that miss https://gist.github.com/andry08/4408c68c532f531a398c
P.S. Rename the Handler.java to something like MessageSyncTile.java (because the handler is a subclass) and for TargetPoint you have only to import it from cpw.mods.fml.common.network.NetworkRegistry.TargetPoint
sorry for my bad english I'm Italian
no errors yay! I only had to change some
message.readbytes.readInt()
to:
message.readbytes.readBoolean()
but the pipes still don't render the booleans are still all false
ops for the readInt() my bad i thinked they was number (because i wasn't looking at your code when realising the packet) because the var name num(ber)1 ecc
for the sync problem you have to call sync() when you finished to check neighbours:
P.S.
I don't know where you call the check but i suggest you to do this in your block to update only when necessary (calling it every tick would lag the server cause to getBlock iteraction):
P.S. I modified checkForNeighbors to take the tile world and coords because pass other coords wouldn't make any sense considering it saves the vars into an instance of tile
sorry for my bad english I'm Italian
So I did all of this
except this ^ didn't know what coords or integers (still relatively new to modding)
however when I place a single pipe it renders as it should (rendering only this.model.shouldRenderMiddle(0.0625F)) but when I place the second it crashes
console -- Head -- Stacktrace:
what contain the line 84 of TileEntityPipe and can you upload the entire crash on pastebin and link it here?
sorry for my bad english I'm Italian
pastern url:
http://pastebin.com/bLLB7fEU
You have to initalize packet, put this in your main class init:
and also did you modify Main with your main class?
sorry for my bad english I'm Italian
I placed the
under my
Is the MainRegistry setup properly
package com.gunnthorian.Main;
import com.gunnthorian.block.GunnCraftBlocks;
import com.gunnthorian.creativetabs.GunnCraftCreativeTabs;
import com.gunnthorian.handler.MessagesHandler;
import com.gunnthorian.item.GunnCraftItems;
import com.gunnthorian.lib.RefStrings;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.client.main.Main;
@Mod(modid = RefStrings.MODID, name = RefStrings.NAME, version = RefStrings.VERSION)
public class MainRegistry {
@SidedProxy(clientSide = RefStrings.CLEINTSIDEPROXY, serverSide = RefStrings.SERVERSIDEPROXY)
public static ServerProxy proxy;
/*@Instance("gunncraft")
public static MainRegistry instance;*/
@Instance
public static MainRegistry instance = new MainRegistry();
@EventHandler
public static void PreLoad(FMLPreInitializationEvent PreEvent){
GunnCraftCreativeTabs.initialiseTabs();
GunnCraftBlocks.mainRegistry();
GunnCraftItems.mainRegistry();
CraftingManager.mainRegistry();
MessagesHandler.registerPackets();
proxy.registerRenderInfo();
}
public void init(FMLInitializationEvent e) {
NetworkRegistry.INSTANCE.newSimpleChannel(((Mod) Main.class.getAnnotation(Mod.class)).modid());
}
@EventHandler
public static void Load(FMLInitializationEvent Event){
LanguageRegistry.instance().addStringLocalization("itemGroup.tabGunnCraft", "en_US", "tabgunncraft");
}
@EventHandler
public static void PostLoad(FMLPostInitializationEvent PostEvent){
}
}
sorry for the late reply...
you forgot the @EventHandler over init BUT you don't need it because you can use the Load function that is called on init because you put FMLInitializationEvent as argument.
and you don't have to put NetworkRegistry.INSTANCE.newSimpleChannel(((Mod) Main.class.getAnnotation(Mod.class)).modid()); but you have to put
remove the init that you created and rename Load TO init.
finally it should look like this
after that you have to go in MessagesHandler and modify the line
to
you made a lot of mistakes, you need to follow some tutorials next time like this: http://www.minecraftforge.net/forum/index.php/topic,20135.0.html
sorry for my bad english I'm Italian
Okay, so now minecraft doesn't crash when the pipes update but the num1-6 values aren't there when the block gets rendered
try breaking and re-placing the pipes
sorry for my bad english I'm Italian
AHHH.... you made an epic mistake...
you mustn't create a new tileentity because it will not be associated with a physical block and will not update values. one moment and I'll write the correction.
sorry for my bad english I'm Italian
no its not rendering them properly, the ModelPipe class is never receiving the num1-6 values
----- oh my bad lol
ok i made some instructions: https://gist.github.com/andry08/9619269677de92e36d5a
then tell if it worked
sorry for my bad english I'm Italian
boolean num1;
boolean num2;
boolean num3;
boolean num4;
boolean num5;
boolean num6;
public void checkForNeighbors(TileEntity te) {
num1 = te.num1;
num2 = te.num2;
num3 = te.num3;
num4 = te.num4;
num5 = te.num5;
num6 = te.num6;
}
error: num1 cannot be resolved or is not a field
ops my bad.
modify the function like this:
to explain to you simply the num1 variable doesn't exist in TileEntity but only in TileEntityPipe. the argument is a TileEntity then it don't show the num1 variable and to access to it you need to cast the TileEntity to TileEntityPipe if you don't really understand it I suggest you to look at this https://howtoprogramwithjava.com/java-cast/
sorry for my bad english I'm Italian