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

[SOLVED][1.8.9]Custom TNT Entity is a white cube


Recommended Posts

I have searched the forums for this issue, and after looking at about 10 different threads, I have only found a single answer that (should have) helped me with this issue:

 

 

I suspect that your fuse counter (variable within your entity class) does only change within the serverside scope, which means the fuse won't be visible to the client and thus rendering your entity white all the time.

You need to sync the fuse with the client and the easiest way to do this is to use a DataWatcher.

Define a new DataWatcherObject (with this.dataWatcher.addObject(...)) within entityInit

on the server side (if worldObj.isRemote == false) set the object's value to the fuse variable in your onUpdate method after it gets updated with dataWatcher.updateObject(...)

on the client side (if worldObj.isRemote == true)  set the value of the fuse variable to the dataWatcherObject's value with getWatchableObjectInt(...)

 

If you don't understand what I mean, here have some pseudocode:

Entity Class
----------
entityInit():
    dataWatcher->addObject(id, Integer.valueOf(0))    | id must be unique! If you get a crash because an already given ID, try another one
                                                      | second param must be casted to the datatype you wanna put in there, here Integer (BTW, the cast is not pseudocode)

onUpdate(): (at the end within the method)
    if world is not remote:
        dataWatcher->updateObject(id, fuse)    | id must be the same as the above defined one
    else:
        fuse = dataWatcher->getWatchableObjectInt(id)    | id, same as above

http://www.minecraftforge.net/forum/index.php/topic,16627.msg84436.html#msg84436

 

 

After following these instructions, my entity is still a white cube. Here is my code:

 

 

Render class:

package the_fireplace.wars.client.render;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import the_fireplace.wars.entities.EntityPTNTPrimed;
import the_fireplace.wars.init.WarsBlocks;

/**
* @author The_Fireplace
*/
public class RenderPTNTPrimed extends Render {
    public RenderPTNTPrimed(RenderManager rm)
    {
        super(rm);
        this.shadowSize = 0.5F;
    }

    public void doRender(EntityPTNTPrimed entity, double x, double y, double z, float p_76986_8_, float partialTicks)
    {
        BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
        GL11.glPushMatrix();
        GL11.glTranslatef((float)x, (float)y, (float)z);
        float f2;

        if ((float)entity.fuse - partialTicks + 1.0F < 10.0F)
        {
            f2 = 1.0F - ((float)entity.fuse - partialTicks + 1.0F) / 10.0F;

            if (f2 < 0.0F)
            {
                f2 = 0.0F;
            }

            if (f2 > 1.0F)
            {
                f2 = 1.0F;
            }

            f2 *= f2;
            f2 *= f2;
            float f3 = 1.0F + f2 * 0.3F;
            GL11.glScalef(f3, f3, f3);
        }

        f2 = (1.0F - ((float)entity.fuse - partialTicks + 1.0F) / 100.0F) * 0.8F;
        this.bindEntityTexture(entity);
        blockRenderer.renderBlockBrightness(WarsBlocks.playerTNT.getDefaultState(), entity.getBrightness(partialTicks));

        if (entity.fuse / 5 % 2 == 0)
        {
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glDisable(GL11.GL_LIGHTING);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_ALPHA);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, f2);
            blockRenderer.renderBlockBrightness(WarsBlocks.playerTNT.getDefaultState(), 1.0F);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glEnable(GL11.GL_TEXTURE_2D);
        }

        GL11.glPopMatrix();
    }

    @Override
    protected ResourceLocation getEntityTexture(Entity entity)
    {
        return TextureMap.locationBlocksTexture;
    }

    @Override
    public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float partialTicks)
    {
        this.doRender((EntityPTNTPrimed) entity, x, y, z, p_76986_8_, partialTicks);
    }
}

Entity class:

package the_fireplace.wars.entities;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.world.World;

import java.util.List;

public class EntityPTNTPrimed extends Entity {
/** How long the fuse is */
public int fuse;

public EntityPTNTPrimed(World par1World) {
	super(par1World);
	fuse = 50;
	preventEntitySpawning = true;
	setSize(0.98F, 0.98F);
	posY = height / 2.0F;
}

public EntityPTNTPrimed(World par1World, double par2, double par4, double par6, EntityLivingBase placer) {
	this(par1World);
	setPosition(par2, par4, par6);
	float var8 = (float) (Math.random() * Math.PI * 2.0D);
	motionX = -((float) Math.sin(var8)) * 0.02F;
	motionY = 0.20000000298023224D;
	motionZ = -((float) Math.cos(var8)) * 0.02F;
	fuse = 50;
	prevPosX = par2;
	prevPosY = par4;
	prevPosZ = par6;
}

@Override
protected void entityInit() {
	this.dataWatcher.addObject(31, new Integer(fuse));
}

/**
 * returns if this entity triggers Block.onEntityWalking on the blocks they
 * walk on. used for spiders and wolves to prevent them from trampling crops
 */
@Override
protected boolean canTriggerWalking() {
	return false;
}

/**
 * Returns true if other Entities should be prevented from moving through
 * this Entity.
 */
@Override
public boolean canBeCollidedWith() {
	return !isDead;
}

/**
 * Called to update the entity's position/logic.
 */
@Override
public void onUpdate() {
	dataWatcher.updateObject(31, Integer.valueOf(fuse));
	fuse = dataWatcher.getWatchableObjectInt(31);
	prevPosX = posX;
	prevPosY = posY;
	prevPosZ = posZ;
	motionY -= 0.03999999910593033D;
	moveEntity(motionX, motionY, motionZ);
	motionX *= 0.9800000190734863D;
	motionY *= 0.9800000190734863D;
	motionZ *= 0.9800000190734863D;

	if (onGround) {
		motionX *= 0.699999988079071D;
		motionZ *= 0.699999988079071D;
		motionY *= -0.5D;
	}

	if (fuse-- <= 0) {
		worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, posX, posY, posZ, 1.0D, 0.0D, 0.0D);
		worldObj.playSoundEffect(posX, posY, posZ, "random.explode", 4.0F, (1.0F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.2F) * 0.7F);

		setDead();

		if (!worldObj.isRemote) {

			explode();

		}
	} else {
		worldObj.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, posX, posY + 0.5D, posZ, 0.0D, 0.0D, 0.0D);
	}
}

@SuppressWarnings("unchecked")
private void explode() {

	List<EntityLiving> nearbyEntities = worldObj.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.fromBounds(posX - 5, posY - 5, posZ - 5, posX + 5, posY + 5, posZ + 5));
	for (EntityLiving living : nearbyEntities) {
		living.attackEntityFrom(DamageSource.setExplosionSource(null), 10);
	}

}

/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
@Override
protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) {
	par1NBTTagCompound.setByte("Fuse", (byte) fuse);
}

/**
 * (abstract) Protected helper method to read subclass entity data from NBT.
 */
@Override
protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {
	fuse = par1NBTTagCompound.getByte("Fuse");
}
}

 

 

If any more code is needed, here is my source code.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to post
Share on other sites

RenderingRegistry#registerEntityRenderingHandler(Class<T>, IRenderFactory<? super T>)

must be called in preInit.

 

You should also use

ModelLoader.setCustomModelResourceLocation

or

ModelLoader.setCustomMeshDefinition

in preInit to register your item models instead of using

ItemModelMesher#register

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to post
Share on other sites
Guest
This topic is now closed to further replies.


  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I just uploaded my mod folder, but I already noticed that and removed it.
    • 1.7 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • ... Why did you install optifine on the server?
    • Hello! Wanted to make a server, and when i launched the server with all of the mods but unfortunatly it keeps crashing =(  Can someone tell me what to do in order to fix it? I would really appreciate any help 😃       Server log: Starting Gameserver now... [18:44:48] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.1.6, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [18:44:48] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 1.8.0_272 by Red Hat, Inc. [18:44:49] [main/INFO] [op.OptiFineTransformationService/]: OptiFineTransformationService.onLoad [18:44:49] [main/INFO] [op.OptiFineTransformationService/]: OptiFine ZIP file: /mnt/minecraftotherpacks/mods/OptiFine_1.16.5_HD_U_G7_MOD.jar [18:44:49] [main/INFO] [op.OptiFineTransformer/]: Target.PRE_CLASS is available [18:44:49] [main/INFO] [ne.mi.fm.lo.FixSSL/CORE]: Added Lets Encrypt root certificates as additional trust [18:44:49] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.2 Source=file:/mnt/minecraftotherpacks/libraries/org/spongepowered/mixin/0.8.2/mixin-0.8.2.jar Service=ModLauncher Env=SERVER [18:44:49] [main/INFO] [op.OptiFineTransformationService/]: OptiFineTransformationService.initialize [18:44:50] [main/INFO] [STDERR/]: [org.antlr.v4.runtime.ConsoleErrorListener:syntaxError:38]: line 1:0 token recognition error at: '~' [18:44:50] [main/INFO] [op.OptiFineTransformationService/]: OptiFineTransformationService.transformers [18:44:50] [main/INFO] [op.OptiFineTransformer/]: Targets: 308 [18:44:50] [main/INFO] [op.OptiFineTransformationService/]: additionalClassesLocator: [optifine., net.optifine.] [18:44:51] [main/INFO] [mixin/]: Successfully loaded Mixin Connector [com.qouteall.hiding_in_the_bushes.MyMixinConnector] [18:44:51] [main/INFO] [mixin/]: Successfully loaded Mixin Connector [tictim.paraglider.MixinConnector] [18:44:51] [main/INFO] [mixin/]: Successfully loaded Mixin Connector [midnight.core.MixinConnector] [18:44:51] [main/INFO] [Portal/]: Invoking Mixin Connector [18:44:51] [main/ERROR] [mixin/]: Mixin config imm_ptl_mixins.json does not specify "minVersion" property [18:44:51] [main/ERROR] [mixin/]: Mixin config imm_ptl_mixins_forge.json does not specify "minVersion" property [18:44:51] [main/ERROR] [mixin/]: Mixin config imm_ptl_peripheral_mixins.json does not specify "minVersion" property [18:44:51] [main/INFO] [cp.mo.mo.LaunchServiceHandler/MODLAUNCHER]: Launching target 'fmlserver' with arguments [--gameDir, ., nogui] [18:44:52] [main/WARN] [mixin/]: @Mixin target net/minecraft/world/server/ChunkManager$EntityTracker is public in imm_ptl_mixins.json:common.entity_sync.MixinEntityTracker and should be specified in value [18:44:52] [main/FATAL] [ne.mi.fm.lo.RuntimeDistCleaner/DISTXFORM]: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER Exception in thread "main" [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:39) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: Caused by: java.lang.reflect.InvocationTargetException [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at java.lang.reflect.Method.invoke(Method.java:498) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at net.minecraftforge.fml.loading.FMLServerLaunchProvider.lambda$launchService$0(FMLServerLaunchProvider.java:51) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [18:44:52] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: ... 7 more [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: Caused by: java.lang.ExceptionInInitializerError [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: at net.minecraft.crash.CrashReport.func_71504_g(CrashReport.java:101) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: at net.minecraft.crash.CrashReport.<init>(CrashReport.java:54) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: at net.minecraft.crash.CrashReport.func_230188_h_(CrashReport.java:425) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: at net.minecraft.server.Main.main(Main.java:91) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: ... 13 more [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:668]: Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:668]: at net.minecraftforge.fml.loading.RuntimeDistCleaner.processClassWithFlags(RuntimeDistCleaner.java:71) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:668]: at cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:85) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:668]: at cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:120) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:668]: at cpw.mods.modlauncher.TransformingClassLoader$DelegatedClassLoader.findClass(TransformingClassLoader.java:265) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:668]: at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:136) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:668]: at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:98) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:668]: at java.lang.ClassLoader.loadClass(ClassLoader.java:351) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:668]: at net.optifine.reflect.Reflector.<clinit>(Reflector.java:185) [18:44:52] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:668]: ... 17 more Gameserver exited without success - 1 Exiting now...     "[18:51:30] [main/FATAL] [ne.mi.fm.lo.RuntimeDistCleaner/DISTXFORM]: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER" I think this one might be the Error, but I dont know how to fix that
    • maybe it is time to buy a new/used one  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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