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

I am making a few guns in my mod and I want to know if it is possible to make them fire at a slower or faster fire rate. I also want to make a rpg that push's the player back a block when they shoot. I only currently have the rpg code.

 


public class RpgClass extends Item
{
   public RpgClass()
   {
     super();
   setMaxStackSize(1).setFull3D();
   }
   @Override
   public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,EntityPlayer par3EntityPlayer) {
   ItemStack armourPiece0 = par3EntityPlayer.inventory.armorInventory[2];
  	   if (armourPiece0 != null && armourPiece0.getItem() == Mineturnedmain.DeathStrokeChestplate&&
  			   par3EntityPlayer.inventory.consumeInventoryItem(Mineturnedmain.RpgAmmo)||par3EntityPlayer.capabilities.isCreativeMode)
    		   
       {
           par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
           if (!par2World.isRemote)
           {
               par2World.spawnEntityInWorld(new EntityRpg(par2World, par3EntityPlayer));
           }
       }
           return par1ItemStack;
       }
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister reg){
	this.itemIcon = reg.registerIcon("morecraftingmod:rpg");
   } }

  • Author

world.spawnEntityInWorld(...)

 

You will also need to make sure that the entity is only spawned on the server.

 

Umm did u even read the post? The rpg works fine.

You will need to add NBT to your ItemStack. After shooting, get NBT and set some "cooldown" to e.g 100 (5 sec). Then you can decrement it in onUpdate().

"Called each tick as long the item is on a player inventory."

if (cooldown <= 0) can shoot, else can't.

Something close to basics: http://www.minecraftforge.net/wiki/Creating_NBT_for_items

 

As to pushback - onItemRightClick(...) has EntityPlayer argument (user) you can simply use math to get his "back side" and move him by 1.0D. Note: do it on both server and client. To see similar stuff - search for knockback around entity damaging - ready-to-use code for finding push-back side.

1.7.10 is no longer supported by forge, you are on your own.

You are much better off creating a tick handler and then sending packets than using nbt. Nbt saves to a file so it takes longer, but using a variable in your ram causes much less lag.

It's an item, only thing you can store in item is ItemStack's NBT (and meta ofc). Also - your idea of "saving NBT" is wrong. Something that I got confused too earlier - NBTs are java Maps, also note that either way ItemStack is sent from server to client, sending more packets is another weight for your connection. Also - you can't send pcket and expect shit to happen, you need to store packet-gotten info somewhere, so you would need IEEP.

Also - if you are storing cooldown in item its per-item cooldown, not a global one. Idk what's the idea here but i think it's more realistic to have 3 RPGs that have separate cooldown.

 

Next fact - ItemStack's NBT is NOT saved to HDD everytime you change it, it's either saved by world-saver or current-inventory-it-is-in saver. For players it happen fairly often (on SP everyime you pause game, on MP every "some" ticks or when you disconnect).

 

Next - TickHandler will cost more than smply saving stuff to ItemStack's NBT. And btw - using IEEP+packets to store global cooldowns will also save data (unless you don't want it to).

1.7.10 is no longer supported by forge, you are on your own.

I suggest:

1) On the client side, detect when the player is holding down the fire button.  You can do this by overriding Item.onEntitySwing (return true to stop further vanilla processing).

2) Send a packet to the server to start firing the gun.

3) On the server, you have a tick handler which is called 20 times per second.

4) When the "start firing" packet arrives at the server, fire a bullet every x ticks, where x depends on your desired firing rate.  Push the player backwards too.

5) When the client side detects that the player isn't holding down the fire button any more, send a "stop firing" packet to the server.

 

You'll probably need to tweak the logic a bit to get it how you want, but the basic idea should work.

 

-TGG

What would happen when client will not send "stop firing" packet? For exaple, player starts firing and he is kicked from server / minecraft or computer is crashing.

 

I think sending packets with specific rate when player holds item&button is better. How vanilla does.

 

What would happen when client will not send "stop firing" packet? For exaple, player starts firing and he is kicked from server / minecraft or computer is crashing.

for sure you would need to add some extra "error" detection to the basic idea.

 

I think sending packets with specific rate when player holds item&button is better. How vanilla does.

Probably the best is a hybrid.  Four times per second the client sends a packet.  Each packet says "fire a burst for 250s" or similar.

 

A bit of experimentation on a laggy server will show the best strategy from the player's point of view..

 

-TGG

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.