Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello there \o/

So I took a try at making a custom arrow.

Everything works fine, except one little detail: it shakes like there's no tomorrow.

After some research, I saw a few people having similar issues but they never got an answer.

 

Here's mah code :

 

(the entity)

package be.bluexin.rwbym.weaponry;

import be.bluexin.rwbym.RWBYModels;
import be.bluexin.rwbym.weaponry.dto.AmmoCapDTO;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.entity.EntityLivingBase;
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.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

/**
* Part of rwbym by Bluexin.
*
* @author Bluexin
*/
@MethodsReturnNonnullByDefault
public class RWBYAmmoEntity extends EntityArrow { // FIXME: for some reason these are shaking like a superpowered vibrator
    private static final DataParameter<String> RS = EntityDataManager.createKey(RWBYAmmoEntity.class, DataSerializers.STRING);

    private ResourceLocation rs = new ResourceLocation("minecraft", "textures/entity/projectiles/spectral_arrow.png");
    private RWBYAmmoItem itemRef;

    public RWBYAmmoEntity(World world) {
        super(world);
        this.dataManager.set(RS, this.rs.toString());
    }

    public RWBYAmmoEntity(World worldIn, double x, double y, double z, AmmoCapDTO capabilities, RWBYAmmoItem from) {
        super(worldIn, x, y, z);
        this.rs = new ResourceLocation(RWBYModels.MODID, capabilities.getTexture());
        this.dataManager.set(RS, this.rs.toString());
        this.setDamage(capabilities.getBaseDamage());
        this.setNoGravity(!capabilities.obeysGravity());
        this.itemRef = from;

    } // TODO: add to dispenser registries (see usage of this constructor in other impl of EntityArrow

    public RWBYAmmoEntity(World worldIn, EntityLivingBase shooter, AmmoCapDTO capabilities, RWBYAmmoItem from) {
        this(worldIn, shooter.posX, shooter.posY + (double) shooter.getEyeHeight() - 0.10000000149011612D, shooter.posZ, capabilities, from);
        this.shootingEntity = shooter;

        if (shooter instanceof EntityPlayer && capabilities.canPickup()) this.pickupStatus = PickupStatus.ALLOWED;
    }

    protected void entityInit() {
        super.entityInit();
        this.dataManager.register(RS, "");
    }

    @Override
    protected ItemStack getArrowStack() {
        return new ItemStack(itemRef);
    }

    public ResourceLocation getRs() {
        return new ResourceLocation(this.dataManager.get(RS));
    }

    public void writeEntityToNBT(NBTTagCompound compound) {
        super.writeEntityToNBT(compound);

        compound.setString("itemRef", this.itemRef == null ? "" : this.itemRef.getRegistryName().toString());
        compound.setString("texture", this.rs.toString());
    }

    public void readEntityFromNBT(NBTTagCompound compound) {
        super.readEntityFromNBT(compound);

        if (compound.hasKey("itemRef"))
            this.itemRef = (RWBYAmmoItem) Item.getByNameOrId(compound.getString("itemRef"));
        if (compound.hasKey("texture")) {
            String s = compound.getString("texture");
            this.rs = s.length() > 0 ? new ResourceLocation(s) : null;
            if (this.rs != null) this.dataManager.set(RS, this.rs.toString());
        }
    }

}

 

(the render)

package be.bluexin.rwbym.weaponry;

import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.client.renderer.entity.RenderArrow;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.util.ResourceLocation;

import javax.annotation.ParametersAreNonnullByDefault;

/**
* Part of rwbym by Bluexin.
*
* @author Bluexin
*/
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class RWBYAmmoRender extends RenderArrow<RWBYAmmoEntity> {

    public RWBYAmmoRender(RenderManager renderManagerIn) {
        super(renderManagerIn);
    }

    @Override
    protected ResourceLocation getEntityTexture(RWBYAmmoEntity entity) {
        return entity.getRs();
    }
}

 

I made these by looking at how the vanilla ones (tipped and spectral) were made, but I must have overlooked something.

Any clues?

 

Also, how I register the render (jic)

RenderingRegistry.registerEntityRenderingHandler(RWBYAmmoEntity.class, RWBYAmmoRender::new);

In my client proxy, called on preinit (FMLPreInitializationEvent)

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.