Jump to content

[SOLVED] Throwable Entity drops twice randomly...


Bedrock_Miner
 Share

Recommended Posts

Hi Guys!

 

I've created some Shurikens in minecraft. Everything works well, except the following: I want the shurikens to drop as an Item if they hit the ground. The problem is: Sometimes not one but two Items are dropped. And sometimes an Item is dropped even if I hit an Entity, like a Creeper or something!

 

I found out that the method is called multiple times (I replaced the dropItem with an Output line). But how can this go on? The Entity is killed at the end of the method, so it musnt't be called again. I have no Idea why.  :(

Can you help me?

 

Register Class:

public static void registerEntities() {
	EntityRegistry.registerGlobalEntityID(EntityShuriken.class, "Shuriken", EntityRegistry.findGlobalUniqueEntityId());
	EntityRegistry.registerModEntity(EntityShuriken.class, "Shuriken", 0, MoreTools.instance, 128, 1, true);
	RenderingRegistry.registerEntityRenderingHandler(EntityShuriken.class, new RenderShuriken(MoreToolsItems.shurikenIron));
}

Entity Class:  (copied from entityy Snowball (and edited))

package Bedrockminer.MoreTools.Classes;

import Bedrockminer.MoreTools.Declarations.MoreToolsItems;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class EntityShuriken extends EntityThrowable
{

    public EntityShuriken(World par1World)
    {
        super(par1World);
    }

    public EntityShuriken(World par1World, EntityLiving par2EntityLiving)
    {
        super(par1World, par2EntityLiving);
    }

    public EntityShuriken(World par1World, double par2, double par4, double par6)
    {
        super(par1World, par2, par4, par6);
    }

    /**
     * Called when this EntityThrowable hits a block or entity.
     */
    protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
    {
    	if (par1MovingObjectPosition.entityHit != null)
    	{
    			byte b0 = 5;
        		par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), b0);
        		
    	} else {
    		this.dropItem(MoreToolsItems.shurikenIron.itemID, 1);
    	}
        
    	this.setDead();
    }
}

Item Class:

package Bedrockminer.MoreTools.Classes;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class MoreToolsShuriken extends Item {

private boolean shotalready;

public MoreToolsShuriken(int par1) {
	super(par1);
}

public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){

     EntityShuriken shuriken = new EntityShuriken(world, player);
     world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + 0.5F);
     	
     if (!world.isRemote)
     {
    	 world.spawnEntityInWorld(shuriken);
     }
     
     if (!player.capabilities.isCreativeMode){
    	 if (-- stack.stackSize == 0)
    		 return null;
     }
     return stack;
}
}


Render Class: (copied from Snowballs)

package Bedrockminer.MoreTools.Classes;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.EntityPotion;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPotion;
import net.minecraft.potion.PotionHelper;
import net.minecraft.util.Icon;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

@SideOnly(Side.CLIENT)
public class RenderShuriken extends Render
{
    private Item field_94151_a;
    private int field_94150_f;

    public RenderShuriken(Item par1, int par2)
    {
        this.field_94151_a = par1;
        this.field_94150_f = par2;
    }

    public RenderShuriken(Item par1)
    {
        this(par1, 0);
    }

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
     */
    public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    {
        Icon icon = this.field_94151_a.getIconFromDamage(this.field_94150_f);

        if (icon != null)
        {
            GL11.glPushMatrix();
            GL11.glTranslatef((float)par2, (float)par4, (float)par6);
            GL11.glEnable(GL12.GL_RESCALE_NORMAL);
            GL11.glScalef(0.5F, 0.5F, 0.5F);
            this.loadTexture("/gui/items.png");
            Tessellator tessellator = Tessellator.instance;

            if (icon == ItemPotion.func_94589_d("potion_splash"))
            {
                int i = PotionHelper.func_77915_a(((EntityPotion)par1Entity).getPotionDamage(), false);
                float f2 = (float)(i >> 16 & 255) / 255.0F;
                float f3 = (float)(i >> 8 & 255) / 255.0F;
                float f4 = (float)(i & 255) / 255.0F;
                GL11.glColor3f(f2, f3, f4);
                GL11.glPushMatrix();
                this.func_77026_a(tessellator, ItemPotion.func_94589_d("potion_contents"));
                GL11.glPopMatrix();
                GL11.glColor3f(1.0F, 1.0F, 1.0F);
            }

            this.func_77026_a(tessellator, icon);
            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
            GL11.glPopMatrix();
        }
    }

    private void func_77026_a(Tessellator par1Tessellator, Icon par2Icon)
    {
        float f = par2Icon.getMinU();
        float f1 = par2Icon.getMaxU();
        float f2 = par2Icon.getMinV();
        float f3 = par2Icon.getMaxV();
        float f4 = 1.0F;
        float f5 = 0.5F;
        float f6 = 0.25F;
        GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
        par1Tessellator.startDrawingQuads();
        par1Tessellator.setNormal(0.0F, 1.0F, 0.0F);
        par1Tessellator.addVertexWithUV((double)(0.0F - f5), (double)(0.0F - f6), 0.0D, (double)f, (double)f3);
        par1Tessellator.addVertexWithUV((double)(f4 - f5), (double)(0.0F - f6), 0.0D, (double)f1, (double)f3);
        par1Tessellator.addVertexWithUV((double)(f4 - f5), (double)(f4 - f6), 0.0D, (double)f1, (double)f2);
        par1Tessellator.addVertexWithUV((double)(0.0F - f5), (double)(f4 - f6), 0.0D, (double)f, (double)f2);
        par1Tessellator.draw();
    }
}

 

PS: If anybody tried it out with my code and it works, please tell me what exactly you did!

Link to comment
Share on other sites

Look at the arrow entity class.

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

Not sure if this will work 100%, but try and add:

if (!worldObj.isRemote) {

  //code

}

 

Yeah! That solved it (but I really don't know why ;D)

 

@Draco: I looked in EntityArrow, there its solved quite different (and does'n work either, I'm just too stupid.  ;D)

 

But thanks to both of you!

Link to comment
Share on other sites

If you want to know why that worked it's because, previously, you were spawning the entity on both the client and server side. The "!world.isRemote" makes sure that the code is only executed on the server, which then sends the update to the client. In summary the client was being told to show a new entity twice (once by your code on the client thread and once by the server) so it showed two new entities.

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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • yo.  i wanted to make a server with mods and now idk what to do. I think better weather is to blame but IDK. PLS HELP crash:  java.lang.NoSuchMethodError: 'void corgitaco.betterweather.api.weather.WeatherEvent.setClient(corgitaco.betterweather.api.client.WeatherEventClient)'     at corgitaco.betterweather.weather.BWWeatherEventContext.lambda$new$6(BWWeatherEventContext.java:108) ~[betterweather-1.2.jar%23207!/:1.0.0] {re:mixin,pl:runtimedistcleaner:A,re:classloading,pl:runtimedistcleaner:A}     at java.util.HashMap.forEach(HashMap.java:1421) ~[?:?] {re:mixin}     at corgitaco.betterweather.weather.BWWeatherEventContext.<init>(BWWeatherEventContext.java:107) ~[betterweather-1.2.jar%23207!/:1.0.0] {re:mixin,pl:runtimedistcleaner:A,re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.server.players.PlayerList.handler$zdd000$sendContext(PlayerList.java:950) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,re:classloading,pl:mixin:APP:betterweather.mixins.json:network.MixinPlayerList,pl:mixin:APP:enhancedcelestials.mixins.json:MixinPlayerList,pl:mixin:APP:assets/better_respawn/better_respawn.mixins.json:PlayerListMixin,pl:mixin:A}     at net.minecraft.server.players.PlayerList.m_11229_(PlayerList.java) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,re:classloading,pl:mixin:APP:betterweather.mixins.json:network.MixinPlayerList,pl:mixin:APP:enhancedcelestials.mixins.json:MixinPlayerList,pl:mixin:APP:assets/better_respawn/better_respawn.mixins.json:PlayerListMixin,pl:mixin:A}     at net.minecraft.server.players.PlayerList.m_11261_(PlayerList.java:200) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,re:classloading,pl:mixin:APP:betterweather.mixins.json:network.MixinPlayerList,pl:mixin:APP:enhancedcelestials.mixins.json:MixinPlayerList,pl:mixin:APP:assets/better_respawn/better_respawn.mixins.json:PlayerListMixin,pl:mixin:A}     at net.minecraft.server.network.ServerLoginPacketListenerImpl.m_143699_(ServerLoginPacketListenerImpl.java:156) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.server.network.ServerLoginPacketListenerImpl.m_10055_(ServerLoginPacketListenerImpl.java:143) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.server.network.ServerLoginPacketListenerImpl.m_9933_(ServerLoginPacketListenerImpl.java:75) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.network.Connection.m_129483_(Connection.java:248) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:classloading}     at net.minecraft.server.network.ServerConnectionListener.m_9721_(ServerConnectionListener.java:143) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5703_(MinecraftServer.java:880) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,pl:mixin:APP:citadel.mixins.json:MinecraftServerMixin,pl:mixin:APP:balm.mixins.json:MinecraftServerMixin,pl:mixin:A}     at net.minecraft.server.dedicated.DedicatedServer.m_5703_(DedicatedServer.java:292) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:806) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,pl:mixin:APP:citadel.mixins.json:MinecraftServerMixin,pl:mixin:APP:balm.mixins.json:MinecraftServerMixin,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:654) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,pl:mixin:APP:citadel.mixins.json:MinecraftServerMixin,pl:mixin:APP:balm.mixins.json:MinecraftServerMixin,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:244) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,pl:mixin:APP:citadel.mixins.json:MinecraftServerMixin,pl:mixin:APP:balm.mixins.json:MinecraftServerMixin,pl:mixin:A}     at java.lang.Thread.run(Thread.java:833) [?:?] {}
    • yo.  i wanted to make a server with mods and now idk what to do. I think better weather is to blame but IDK. PLS HELP crash:  java.lang.NoSuchMethodError: 'void corgitaco.betterweather.api.weather.WeatherEvent.setClient(corgitaco.betterweather.api.client.WeatherEventClient)'     at corgitaco.betterweather.weather.BWWeatherEventContext.lambda$new$6(BWWeatherEventContext.java:108) ~[betterweather-1.2.jar%23207!/:1.0.0] {re:mixin,pl:runtimedistcleaner:A,re:classloading,pl:runtimedistcleaner:A}     at java.util.HashMap.forEach(HashMap.java:1421) ~[?:?] {re:mixin}     at corgitaco.betterweather.weather.BWWeatherEventContext.<init>(BWWeatherEventContext.java:107) ~[betterweather-1.2.jar%23207!/:1.0.0] {re:mixin,pl:runtimedistcleaner:A,re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.server.players.PlayerList.handler$zdd000$sendContext(PlayerList.java:950) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,re:classloading,pl:mixin:APP:betterweather.mixins.json:network.MixinPlayerList,pl:mixin:APP:enhancedcelestials.mixins.json:MixinPlayerList,pl:mixin:APP:assets/better_respawn/better_respawn.mixins.json:PlayerListMixin,pl:mixin:A}     at net.minecraft.server.players.PlayerList.m_11229_(PlayerList.java) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,re:classloading,pl:mixin:APP:betterweather.mixins.json:network.MixinPlayerList,pl:mixin:APP:enhancedcelestials.mixins.json:MixinPlayerList,pl:mixin:APP:assets/better_respawn/better_respawn.mixins.json:PlayerListMixin,pl:mixin:A}     at net.minecraft.server.players.PlayerList.m_11261_(PlayerList.java:200) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,re:classloading,pl:mixin:APP:betterweather.mixins.json:network.MixinPlayerList,pl:mixin:APP:enhancedcelestials.mixins.json:MixinPlayerList,pl:mixin:APP:assets/better_respawn/better_respawn.mixins.json:PlayerListMixin,pl:mixin:A}     at net.minecraft.server.network.ServerLoginPacketListenerImpl.m_143699_(ServerLoginPacketListenerImpl.java:156) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.server.network.ServerLoginPacketListenerImpl.m_10055_(ServerLoginPacketListenerImpl.java:143) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.server.network.ServerLoginPacketListenerImpl.m_9933_(ServerLoginPacketListenerImpl.java:75) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.network.Connection.m_129483_(Connection.java:248) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:classloading}     at net.minecraft.server.network.ServerConnectionListener.m_9721_(ServerConnectionListener.java:143) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5703_(MinecraftServer.java:880) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,pl:mixin:APP:citadel.mixins.json:MinecraftServerMixin,pl:mixin:APP:balm.mixins.json:MinecraftServerMixin,pl:mixin:A}     at net.minecraft.server.dedicated.DedicatedServer.m_5703_(DedicatedServer.java:292) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:806) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,pl:mixin:APP:citadel.mixins.json:MinecraftServerMixin,pl:mixin:APP:balm.mixins.json:MinecraftServerMixin,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:654) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,pl:mixin:APP:citadel.mixins.json:MinecraftServerMixin,pl:mixin:APP:balm.mixins.json:MinecraftServerMixin,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:244) ~[server-1.19.2-20220805.130853-srg.jar%23291!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,pl:mixin:APP:citadel.mixins.json:MinecraftServerMixin,pl:mixin:APP:balm.mixins.json:MinecraftServerMixin,pl:mixin:A}     at java.lang.Thread.run(Thread.java:833) [?:?] {}
    • I've got no solution for this particular way. But may I suggest? You can create one singular item and store the entity's data using NBT or Capability. It will make things easier and cleaner.
    • REM Forge requires a configured set of both JVM and program arguments. REM Add custom JVM arguments to the user_jvm_args.txt REM Add custom program arguments {such as nogui} to this file in the next line before the %* or REM  pass them to this script directly "C:\Program Files\Java\jdk-17\bin\Java.exe" @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.18.2-40.1.80/win_args.txt -Xmx8G -Xms8G %* pause     so I used it.
    • I created an SOUL_JAR Item that has been registered for each mob like - mod:soul_jar_minecraft_cow etc.. but it all has different registry names, i have a model file name soul_jar.json and i want to know how to bind each of those items to this class (When mod iterates through all of vanilla mobs and registering items for them).   I didn't found any info about it because all of info is outdated, and forge docs is complicated asf (i wish there would be more examples) i also used AI but it showing me only outdated info, but theres some code where i registering my item and trying to bind it to model ->   public static void register(IEventBus eventBus){ ITEMS.register(eventBus); Set<ResourceLocation> entityKeyList = ForgeRegistries.ENTITY_TYPES.getKeys(); for (ResourceLocation k : entityKeyList) { EntityType<?> entityType = ForgeRegistries.ENTITY_TYPES.getValue(k); if (!entityType.getCategory().equals(MobCategory.MISC)) { RegistryObject<Item> SOUL_JAR = ITEMS.register("soul_jar" + '_' + k.toString().replace(':', '_').replace('.', '_'), () -> new JarItem(new Item.Properties().rarity(Rarity.RARE).tab(ModTabs.MAGICAL_OBSESSION_JARS), entityType)); if (Thread.currentThread().getThreadGroup() == SidedThreadGroups.CLIENT) { ItemModelShaper itemModelShaper = Minecraft.getInstance().getItemRenderer().getItemModelShaper(); itemModelShaper.register(SOUL_JAR.get().asItem(), new ModelResourceLocation("item.soul_jar", "inventory")); } } } } I also have more questions like how to iterate through all other mods mobs also, or render mob inside of a jar in inventory, but i will try to figure it out.
  • Topics

×
×
  • Create New...

Important Information

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