Jump to content

Recommended Posts

Posted

so basically I made a throwable entity that explodes on impact, the problem is, the blocks register on the client side(I think) but not on the server side(I think), basically I am wondering how I should register the entity in the game, because, after re-logging the explosion cease to exist, how should I fix this?

 

EntityClass

package com.OlympiansMod.entity;

import net.minecraft.entity.EntityList;

import com.OlympiansMod.Main.MainRegistry;

import cpw.mods.fml.common.registry.EntityRegistry;

public class MEntity {
public static void MainRegistry(){

}
public static void registerEntity(){
	createEntity(EntityGreekFire.class, "GreekFire", 0x008521, 0x00FF0800);
}
public static void createEntity(Class entityClass, String entityName, int solidColour, int spotColour){
	int randomId = EntityRegistry.findGlobalUniqueEntityId();


	EntityRegistry.registerGlobalEntityID(entityClass, entityName, randomId);
	EntityRegistry.registerModEntity(entityClass, entityName, randomId, MainRegistry.modInstance, 80, 1, true);
	createEgg(randomId, solidColour, spotColour);
}
private static void createEgg(int randomId, int solidColour, int spotColour){
	EntityList.entityEggs.put(Integer.valueOf(randomId), new EntityList.EntityEggInfo(randomId, solidColour, spotColour));

}
}

 

EntityGreekFireClass

package com.OlympiansMod.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class EntityGreekFire extends EntityThrowable{

public EntityGreekFire(World p_i1776_1_) {
	super(p_i1776_1_);
}
public EntityGreekFire(World world, EntityLivingBase entity){
	super(world, entity);
}
@Override
protected void onImpact(MovingObjectPosition p_70184_1_) {
	for(int i = 0; i < 10; i++){
		this.worldObj.spawnParticle("largesmoke", this.posX, this.posY, this.posZ, 0f, 0f, 0f);
		this.worldObj.playSound(this.posX, this.posY, this.posZ, "random.explode", 10.0f, 1.0f, inGround);
	}

	if(this.worldObj.isRemote){
		this.setDead();
		if(this.worldObj.isRemote){
			this.worldObj.createExplosion((Entity) null, this.posX, this.posY, this.posZ, 10f, true);
		}
	}

}

}

 

GreekFire Item extends

package com.OlympiansMod.Item;

import com.OlympiansMod.entity.EntityGreekFire;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class GreekFire extends Item{
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player){
	if(!player.capabilities.isCreativeMode){
		--itemstack.stackSize;
	}
	world.playSoundAtEntity(player, "random.fizz", 0.7f, 0.8f);

	if(world.isRemote){
		world.spawnEntityInWorld(new  EntityGreekFire(world, player));
	}
	return itemstack;
}

}

 

MainRegistery

 

package com.OlympiansMod.Main;

import com.OlympiansMod.Block.ModBlocks;
import com.OlympiansMod.Item.ModItems;
import com.OlympiansMod.creativetabs.MCreativeTabs;
import com.OlympiansMod.entity.MEntity;
import com.OlympiansMod.lib.Refstrings;
import com.OlympiansMod.world.MWorld;

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.registry.GameRegistry;

@Mod(modid = Refstrings.MODID , name = Refstrings.NAME , version = Refstrings.VERSION)
public class MainRegistry {

@SidedProxy(clientSide = Refstrings.CLIENTSIDE , serverSide = Refstrings.SERVERSIDE)
public static ServerProxy proxy;

@Instance
public static MainRegistry modInstance;

@EventHandler
public static void PreLoad(FMLPreInitializationEvent PreEvent) {
	MCreativeTabs.initialiseTabs();
	ModBlocks.MainRegistry();
	MEntity.MainRegistry();
	ModItems.MainRegistry();
	MWorld.MainRegistry();
        CraftingManager.mainRegistry();
        proxy.registerRenderInfo();

}
@EventHandler
public static void Load(FMLInitializationEvent event) {

}
@EventHandler
public static void PostLoad(FMLPostInitializationEvent PostEvent) {

}

}

 

Client and ServerSide Proxys

 

package com.OlympiansMod.Main;

import net.minecraft.client.renderer.entity.RenderSnowball;

import com.OlympiansMod.Item.ModItems;
import com.OlympiansMod.entity.EntityGreekFire;

import cpw.mods.fml.client.registry.RenderingRegistry;

public class ClientProxy extends ServerProxy{
public void registerRenderInfo(){
	RenderingRegistry.registerEntityRenderingHandler(EntityGreekFire.class, new RenderSnowball(ModItems.GreekFire));

}
public int addArmor(String armor){
	return RenderingRegistry.addNewArmourRendererPrefix(armor);

}

}

package com.OlympiansMod.Main;

import net.minecraft.client.renderer.entity.RenderSnowball;

import com.OlympiansMod.Item.ModItems;
import com.OlympiansMod.entity.EntityGreekFire;

import cpw.mods.fml.client.registry.RenderingRegistry;

public class ServerProxy {
public void registerRenderInfo() {
	RenderingRegistry.registerEntityRenderingHandler(EntityGreekFire.class, new RenderSnowball(ModItems.GreekFire));

}
public int addArmor(String armor){
	return 0;

}

}

 

Thank you all for your time. -BoonieQuafterCrAfTeR

 

Im serious don't look at it!!

Posted

1. You don't register the entity both as a mod entity and as a global entity, just use registerModEntity

2. Don't use static entity IDs, use a Configuration to allow the user to change it

3. You have redundant checks for this.worldObj.isRemote, you only need one

3. isRemote is true on the client and false on the server, you want to be creating the explosion on the server not the client

 

if (!this.worldObj.isRemote) {
this.setDead();
this.worldObj.createExplosion((Entity) null, this.posX, this.posY, this.posZ, 10f, true);
}

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Posted

heres the new code, its still not registering. what did I do wrong.

 

package com.OlympiansMod.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class EntityGreekFire extends EntityThrowable{

public EntityGreekFire(World p_i1776_1_) {
	super(p_i1776_1_);
}
public EntityGreekFire(World world, EntityLivingBase entity){
	super(world, entity);
}
@Override
protected void onImpact(MovingObjectPosition p_70184_1_) {
	for(int i = 0; i < 10; i++){
		this.worldObj.spawnParticle("largesmoke", this.posX, this.posY, this.posZ, 0f, 0f, 0f);
		this.worldObj.playSound(this.posX, this.posY, this.posZ, "random.explode", 10.0f, 1.0f, inGround);
	}

	if(this.worldObj.isRemote){
		this.setDead();
		this.worldObj.createExplosion((Entity) null, this.posX, this.posY, this.posZ, 10f, true);
		}
	}

}


 

MEntity Class

package com.OlympiansMod.entity;

import net.minecraft.entity.EntityList;

import com.OlympiansMod.Main.MainRegistry;

import cpw.mods.fml.common.registry.EntityRegistry;

public class MEntity {
public static void MainRegistry(){

}
public static void registerEntity(){
	createEntity(EntityGreekFire.class, "GreekFire", 0x008521, 0x00FF0800);
}
public static void createEntity(Class entityClass, String entityName, int solidColour, int spotColour){
	int randomId = EntityRegistry.findGlobalUniqueEntityId();

	EntityRegistry.registerModEntity(entityClass, entityName, randomId, MainRegistry.modInstance, 80, 1, true);
	createEgg(randomId, solidColour, spotColour);
}
private static void createEgg(int randomId, int solidColour, int spotColour){
	EntityList.entityEggs.put(Integer.valueOf(randomId), new EntityList.EntityEggInfo(randomId, solidColour, spotColour));

}
}

 

Im serious don't look at it!!

Posted

how do I fix my code so that I create the explosion on the server?

Dont use
EntityRegistry.findGlobalUniqueEntityId();

, the entity IDs are al yours, so you can start at 0 and increment for each entity.

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/

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.