Jump to content

[SOLVED]TileEntity implementing IUpdatePlayerListBox only working clientside


Brickfix

Recommended Posts

I have created a block that shall serve as a kind of totem pole that keeps bad monsters away. It basically works flawlessly, killing all skeletons around it as it is supposed to be and so on. But there is one weird thing happening every time I end minecraft and open the world again after relaunching minecraft:

Basically nothing happens. The tileentity also summons lightning, and for a time I had a weird semilightning appearing everytime I reloaded the world. I got rid of it checking if the world was remote, as summoning entities and so forth are only working it the world is not remote. So, as I said, when reloading the world after closing minecraft and relaunching it, the tile entity stops to work. Or at least whatever it does, it does not seem to have an effect anymore. I tested it in a various amount of ways, printing out a lot of different things in the console. Additionally please note that when placing the block, it all works, and when quitting the world to the title and than opening it again it works as well without a problem. It only does not work when restarting the game itself.

 

Here is my code of the Block class

package com.brickfix.totemmod.blocks;

import java.util.Random;

import com.brickfix.totemmod.TotemBlockLogic;
import com.brickfix.totemmod.lib.Constants;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.command.ICommandSender;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityCommandBlock;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class TotemBlockTest extends BlockContainer
{
public static final String name = "totem_block";
public boolean isCharged;

public TotemBlockTest() 
{
	super(Material.rock);


	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setHardness(5.0F);
	//this.setTickRandomly(true);

	GameRegistry.registerBlock(this, name);
	setUnlocalizedName(Constants.MODID + "_" + name);

}

public String getName()
{
	return this.name;
}

public int getRenderType()
    {
        return 3;
    }

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) 
{
	return new TileEntityTotemBlock();
}

}

 

Here is the TileEntity

package com.brickfix.totemmod.blocks;

import java.util.Random;

import net.minecraft.command.CommandBase;
import net.minecraft.command.NumberInvalidException;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.item.EntityFireworkRocket;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.brickfix.totemmod.TotemBlockLogic;
import com.brickfix.totemmod.TotemMod;
import com.sun.org.apache.xalan.internal.xsltc.util.IntegerArray;

public class TileEntityTotemBlock extends TileEntity implements IUpdatePlayerListBox
{
public int cooldown;
public boolean isCharged;

private final TotemBlockLogic totemLogic = new TotemBlockLogic()
{
	@Override
	public String getCommand()
	{
		return "/kill @e[type=Skeleton,r=5]";
	}

	@Override
	public BlockPos getPosition() 
	{
		return TileEntityTotemBlock.this.pos;
	}

	@Override
	public Vec3 getPositionVector() 
	{
		return new Vec3((double)TileEntityTotemBlock.this.pos.getX() + 0.5D, (double)TileEntityTotemBlock.this.pos.getY() + 0.5D, (double)TileEntityTotemBlock.this.pos.getZ() + 0.5D);
	}

	@Override
	public World getEntityWorld() 
	{
		return TileEntityTotemBlock.this.worldObj;
	}

};

public int getCooldown()
{
	return 100;
}

public TotemBlockLogic getTotemLogic()
{
	return this.totemLogic;
}

public void writeToNBT(NBTTagCompound compound)
{
	super.writeToNBT(compound);
	compound.setInteger("Cooldown", this.cooldown);
	compound.setBoolean("Charged", this.isCharged);

}
public void readFromNBT(NBTTagCompound compound)
{
	super.readFromNBT(compound);
	this.cooldown = compound.getInteger("Cooldown");
	this.isCharged = compound.getBoolean("Charged");
}

static
{
	addMapping(TileEntityTotemBlock.class, "TotemBlock");
}


public void update()
{
	if (this.worldObj.isRemote) return;

	this.isCharged = isCharged();

	if (this.cooldown==0)
	{
		int i=0;

		if (this.isCharged)
		{
			i = totemLogic.trigger(this.worldObj);
		}
		if (i!=0)
		{
			this.cooldown = this.getCooldown();
			Item rm = Items.fireworks;

			NBTTagCompound tag0 = new NBTTagCompound();
			NBTTagList explosions = new NBTTagList();
			NBTTagCompound tag1 = new NBTTagCompound();
			NBTTagCompound tag2 = new NBTTagCompound();

			int[] array = new int[1];
			array[0] = 65536*230;

			tag2.setIntArray("Colors", array);
			tag2.setBoolean("Flicker", true);

			explosions.appendTag(tag2);

			tag1.setTag("Explosions", explosions);
			tag1.setByte("Flight", (byte) 0);

			tag0.setTag("Fireworks", tag1);


			ItemStack modifier = new ItemStack(rm);

			modifier.setTagCompound(tag0);

			Entity effect = new EntityFireworkRocket(this.worldObj, pos.getX()+0.5D, pos.getY()+0.5D, pos.getZ()+0.5D, modifier);

			this.worldObj.spawnEntityInWorld(effect);
		}	
	}
	else if (this.cooldown > 0)
	{
		this.cooldown--;
	}

}

public boolean isCharged()
{
	boolean flag = this.isCharged;
	boolean flag2 = false;
	BlockPos pos = this.pos;
	if ((this.worldObj.getBlockState(pos.up()) == Blocks.obsidian.getDefaultState()) && (this.worldObj.getBlockState(pos.down()) == Blocks.obsidian.getDefaultState()))
	{
		flag2 = true;
	}

	if (flag==false && flag2==true)
	{
		this.lightningStrikes(worldObj, pos);
	}

	return flag2;
}

protected void lightningStrikes(World world, BlockPos pos)
{

	double dx = (double)pos.getX();
	double dy = (double)pos.getY();
	double dz = (double)pos.getZ();

	String sx = String.valueOf(pos.getX());
	String sy = String.valueOf(pos.getY());
	String sz = String.valueOf(pos.getZ());

	try 
	{
		dx = CommandBase.func_175761_b(dx, sx, true);
		dy = CommandBase.func_175761_b(dy, sy, false);
		dz = CommandBase.func_175761_b(dz, sz, true);
	} 
	catch (NumberInvalidException e) 
	{
		e.printStackTrace();
		return;
	}
        
        
        world.addWeatherEffect(new EntityLightningBolt(world, dx, dy, dz));
}

}

 

And here is my TotemLogic class

package com.brickfix.totemmod;

import net.minecraft.command.ICommandSender;
import net.minecraft.command.CommandResultStats.Type;
import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.BlockPos;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;

public abstract class TotemBlockLogic implements ICommandSender
{

public int trigger(World worldIn) 
{
	MinecraftServer minecraftserver = MinecraftServer.getServer();
	int i = 0;

        if (minecraftserver != null && minecraftserver.func_175578_N())
        {

        	try
        	{
        		i = minecraftserver.getCommandManager().executeCommand(this, getCommand());
        		//System.out.println(getCommand());
        		return i;
        	}
        	catch(Throwable t)
        	{
        		System.out.println("could not execute command");
        		return 0;
        	}
        }
	return i;

}

public abstract String getCommand();

@Override
public void addChatMessage(IChatComponent message) 
{
	//We do not want to see a chat message
}

@Override
public String getName() 
{
	// TODO Auto-generated method stub
	return "totem";
}

@Override
public Entity getCommandSenderEntity() 
{
	// This is no entity and not important
	return null;
}

@Override
public boolean sendCommandFeedback() 
{
	//We do not need this
	return false;
}

@Override
public void setCommandStat(Type type, int amount) 
{
	// We do not need this		
}

@Override
public IChatComponent getDisplayName() 
{
	return null;
}

@Override
public boolean canUseCommand(int permLevel, String commandName) 
{
	return true;
}



}

 

It would be awesome if you could help me out with this :)

Link to comment
Share on other sites

Hi

 

Without looking at your code too hard, my first guess is that it's because you haven't implemented onDataPacket() and getDescriptionPacket().  If you're doing everything server-side, I would have thought it's not necessary, but I'm not 100% sure.

 

See here for an explanation

http://greyminecraftcoder.blogspot.com.au/2015/01/tileentity.html

 

Otherwise - are you sure that server side update stops getting called?  Show an example of the test code and the console output that leads you to that conclusion?

 

-TGG

 

 

 

Link to comment
Share on other sites

So it seems that I have not implemented the onDataPacket() and getDescriptionPacket() methods, I added these in and the problem persists.

I am really sure that it runs the update() only client side, I added

 

if (this.worldObj.isRemot)
{
    System.out.println("Updated ClientSide");
    return;
}
else
{
    System.out.println("Updated ServerSide");
    //Here comes the rest of my code
}

 

Turns out that when I place the block, both messages pop up in the console. Closing and reloading the world still keeps both messages showing up. Ending the minecraft game and restarting it only leads to the display of the "Updated ClientSide" message.

 

I copied over the onDataPacket() and getDescriptionPacket() methods into my code, and the problem is still there. Maybe I set them up incorrectly?

@Override
public Packet getDescriptionPacket() 
{
	NBTTagCompound nbtTagCompound = new NBTTagCompound();
	writeToNBT(nbtTagCompound);
	int metadata = getBlockMetadata();
	return new S35PacketUpdateTileEntity(this.pos, metadata, nbtTagCompound);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) 
{
	readFromNBT(pkt.getNbtCompound());
}

 

I have basically read through everything in you blog, it is explaining really good and already helped me out several times.

Thanks for taking the time :)

Link to comment
Share on other sites

Ok so here are all my classes:

 

Main mod class:

http://pastebin.com/CUzCNWF0

 

Common Proxy:

http://pastebin.com/ncaUgkpx

 

The Block class:

http://pastebin.com/Q2EFxbX5

 

The TileEntity:

http://pastebin.com/cgGQXdxT

 

And the Logic class:

http://pastebin.com/bmW1yBnW

 

I left out the client proxy as it is doing nothing ATM as well as my constants class as it is pretty obvious what it is doing.

 

Thanks again for taking the time and looking over my problem :)

 

Link to comment
Share on other sites

Its like my classes are bewitched or something. I even compiled it all and tested it with my actual minecraft game and the problems still occured exactly as described above.

I will update my forge version, maybe this is causing it ...

 

EDIT:

I recompiled forge and suddenly all problems have disappeared. Thanks a lot anyway, I have learned a lot of other things about tile entities during the process :D

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
  • Topics

×
×
  • Create New...

Important Information

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