Jump to content

Recommended Posts

Posted

Okay so I've been trying to make an item that lets to fly for a short period of time. I have all the logic correct and everything SHOULD work, but when  I set player.capabilities.allowFlying to true I can't fly (But I don't take fall damage)

 

Here is my code

 

Tickhandler

package rareores.Common;

import java.util.EnumSet;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ServerTickHandler implements ITickHandler {

int count = 0;
int delay = 0;
private void onPlayerTick(EntityPlayer player) {
	if(player.inventory.hasItem(Item.stick.itemID) && player.capabilities.isCreativeMode == false && this.count < 100 && this.delay == 0)
	{
	    player.capabilities.allowFlying = true;
	    if(player.capabilities.isFlying){
		this.count++;
	    }
	    if(this.count > 0 && !player.capabilities.isFlying){
	    	count = 100;
	    }
		System.out.println("We should be flying");
	}
	else
	{
		this.count = 0;
		this.delay++;

		if (this.delay >= 320)
		{
			this.delay = 0;
		}

		player.capabilities.allowFlying = false;
		System.out.println("We should NOT be flying");
	}
	System.out.println(this.count);
	System.out.println(this.delay);
}

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	 if (type.equals(EnumSet.of(TickType.PLAYER)))
	  {
	    onPlayerTick((EntityPlayer)tickData[0]);
	  }

}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {


}

@Override
public EnumSet<TickType> ticks()
{
	return EnumSet.of(TickType.PLAYER, TickType.SERVER);
}

@Override
public String getLabel() {

	return null;
}

}

 

commonproxy

package rareores.Common;

import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

public class CommonProxyRareores {

public void registerRenderers(){


}
public void onBowFOVZoomPherithium(EntityPlayer player, ItemStack stack){
	;

}
public void onBowFOVZoomCrystinium(EntityPlayer player, ItemStack stack){
	;

}
public void onBowFOVZoomTophinite(EntityPlayer player, ItemStack stack){
	;

}
public void onBowFOVZoomMagrolith(EntityPlayer player, ItemStack stack){
	;

}
public void onBowFOVZoomNecronite(EntityPlayer player, ItemStack stack){
	;

}
public void onBowFOVZoomGold(EntityPlayer player, ItemStack stack){
	;

}
public void onBowFOVZoomIron(EntityPlayer player, ItemStack stack){
	;

}
public void onBowFOVZoomDiamond(EntityPlayer player, ItemStack stack){
	;

}
public void onBowFOVZoomTrillint(EntityPlayer player, ItemStack stack){
	;

}
public void onBowFOVZoomNether(EntityPlayer player, ItemStack stack){
	;

}
public void resetSavedFOV() {
	  ;
	 }
public void registerClientTickHandler()
 {
  
 }
public void registerServerTickHandler()
 {
  TickRegistry.registerTickHandler(new ServerTickHandler(), Side.SERVER);
 }
public void bowRender()
{
	;
}

}

clientproxy

 
package mod_Rareores;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.MinecraftForgeClient;
import rareores.Common.CommonProxyRareores;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;

public class ClientProxyRareores extends CommonProxyRareores {

@Override
public void registerRenderers(){

RenderingRegistry.registerEntityRenderingHandler(EntityInvisibleArrow.class, new RenderInvisibleArrow());
MinecraftForgeClient.registerItemRenderer(mod_rareores.ItemPherithiumBow.itemID, new RenderBow());
MinecraftForgeClient.registerItemRenderer(mod_rareores.ItemCrystiniumBow.itemID, new RenderBow());
MinecraftForgeClient.registerItemRenderer(mod_rareores.ItemTophiniteBow.itemID, new RenderBow());
MinecraftForgeClient.registerItemRenderer(mod_rareores.ItemMagrolithBow.itemID, new RenderBow());
MinecraftForgeClient.registerItemRenderer(mod_rareores.ItemNecroniteBow.itemID, new RenderBow());
MinecraftForgeClient.registerItemRenderer(mod_rareores.ItemNetherBow.itemID, new RenderBow());
MinecraftForgeClient.registerItemRenderer(mod_rareores.ItemTrillintBow.itemID, new RenderBow());
MinecraftForgeClient.registerItemRenderer(mod_rareores.ItemDiamondBow.itemID, new RenderBow());
MinecraftForgeClient.registerItemRenderer(mod_rareores.ItemIronBow.itemID, new RenderBow());
MinecraftForgeClient.registerItemRenderer(mod_rareores.ItemGoldBow.itemID, new RenderBow());


}
public float fovModifierHand = 0F;

@Override
public void onBowFOVZoomPherithium(EntityPlayer player,ItemStack stack) {
    float f = 1.0F;

    if (player.capabilities.isFlying)
    {
        f *= 1.1F;
    }
    
    float speedOnGround = 0.1F;

    f *= (player.landMovementFactor * player.getSpeedModifier() / speedOnGround + 1.0F) / 2.0F;
    
int i = player.getItemInUseDuration();
    float f1 = (float)i / 16.0F;

    if (f1 > 1.0F)
    {
        f1 = 1.0F;
    }
    else
    {
        f1 *= f1;
    }

    f *= 1.0F - f1 * 0.2F;
    
    fovModifierHand = fovModifierHand > 0.001F ? fovModifierHand : (Float)ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");
    fovModifierHand += (f - fovModifierHand) * 0.5F;

    if (fovModifierHand > 1.5F)
    {
        fovModifierHand = 1.5F;
    }

    if (fovModifierHand < 0.1F)
    {
        fovModifierHand = 0.1F;
    }
    
ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");
}
@Override
public void onBowFOVZoomCrystinium(EntityPlayer player, ItemStack stack){
float f = 1.0F;

    if (player.capabilities.isFlying)
    {
        f *= 1.1F;
    }
    
    float speedOnGround = 0.1F;

    f *= (player.landMovementFactor * player.getSpeedModifier() / speedOnGround + 1.0F) / 2.0F;
    
int i = player.getItemInUseDuration();
    float f1 = (float)i / 15.0F;

    if (f1 > 1.0F)
    {
        f1 = 1.0F;
    }
    else
    {
        f1 *= f1;
    }

    f *= 1.0F - f1 * 0.2F;
    
    fovModifierHand = fovModifierHand > 0.001F ? fovModifierHand : (Float)ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");
    fovModifierHand += (f - fovModifierHand) * 0.5F;

    if (fovModifierHand > 1.5F)
    {
        fovModifierHand = 1.5F;
    }

    if (fovModifierHand < 0.1F)
    {
        fovModifierHand = 0.1F;
    }
    
ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");
}
@Override
public void onBowFOVZoomTophinite(EntityPlayer player, ItemStack stack){
float f = 1.0F;

    if (player.capabilities.isFlying)
    {
        f *= 1.1F;
    }
    
    float speedOnGround = 0.1F;

    f *= (player.landMovementFactor * player.getSpeedModifier() / speedOnGround + 1.0F) / 2.0F;
    
int i = player.getItemInUseDuration();
    float f1 = (float)i / 33.0F;

    if (f1 > 1.0F)
    {
        f1 = 1.0F;
    }
    else
    {
        f1 *= f1;
    }

    f *= 1.0F - f1 * 0.4F;
    
    fovModifierHand = fovModifierHand > 0.001F ? fovModifierHand : (Float)ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");
    fovModifierHand += (f - fovModifierHand) * 0.5F;

    if (fovModifierHand > 1.5F)
    {
        fovModifierHand = 1.5F;
    }

    if (fovModifierHand < 0.1F)
    {
        fovModifierHand = 0.1F;
    }
    
ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");
}
@Override
public void onBowFOVZoomMagrolith(EntityPlayer player, ItemStack stack){
float f = 1.0F;

    if (player.capabilities.isFlying)
    {
        f *= 1.1F;
    }
    
    float speedOnGround = 0.1F;

    f *= (player.landMovementFactor * player.getSpeedModifier() / speedOnGround + 1.0F) / 2.0F;
    
int i = player.getItemInUseDuration();
    float f1 = (float)i / 36.0F;

    if (f1 > 1.0F)
    {
        f1 = 1.0F;
    }
    else
    {
        f1 *= f1;
    }

    f *= 1.0F - f1 * 0.3F;
    
    fovModifierHand = fovModifierHand > 0.001F ? fovModifierHand : (Float)ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");
    fovModifierHand += (f - fovModifierHand) * 0.5F;

    if (fovModifierHand > 1.5F)
    {
        fovModifierHand = 1.5F;
    }

    if (fovModifierHand < 0.1F)
    {
        fovModifierHand = 0.1F;
    }
    
ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");

}
@Override
public void onBowFOVZoomNecronite(EntityPlayer player, ItemStack stack){
float f = 1.0F;

    if (player.capabilities.isFlying)
    {
        f *= 1.1F;
    }
    
    float speedOnGround = 0.1F;

    f *= (player.landMovementFactor * player.getSpeedModifier() / speedOnGround + 1.0F) / 2.0F;
    
int i = player.getItemInUseDuration();
    float f1 = (float)i / 14.0F;

    if (f1 > 1.0F)
    {
        f1 = 1.0F;
    }
    else
    {
        f1 *= f1;
    }

    f *= 1.0F - f1 * 0.2F;
    
    fovModifierHand = fovModifierHand > 0.001F ? fovModifierHand : (Float)ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");
    fovModifierHand += (f - fovModifierHand) * 0.5F;

    if (fovModifierHand > 1.5F)
    {
        fovModifierHand = 1.5F;
    }

    if (fovModifierHand < 0.1F)
    {
        fovModifierHand = 0.1F;
    }
    
ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");
}
@Override
public void onBowFOVZoomGold(EntityPlayer player, ItemStack stack){
float f = 1.0F;

    if (player.capabilities.isFlying)
    {
        f *= 1.1F;
    }
    
    float speedOnGround = 0.1F;

    f *= (player.landMovementFactor * player.getSpeedModifier() / speedOnGround + 1.0F) / 2.0F;
    
int i = player.getItemInUseDuration();
    float f1 = (float)i / 10.0F;

    if (f1 > 1.0F)
    {
        f1 = 1.0F;
    }
    else
    {
        f1 *= f1;
    }

    f *= 1.0F - f1 * 0.1F;
    
    fovModifierHand = fovModifierHand > 0.001F ? fovModifierHand : (Float)ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");
    fovModifierHand += (f - fovModifierHand) * 0.5F;

    if (fovModifierHand > 1.5F)
    {
        fovModifierHand = 1.5F;
    }

    if (fovModifierHand < 0.1F)
    {
        fovModifierHand = 0.1F;
    }
    
ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");

}
@Override
public void onBowFOVZoomIron(EntityPlayer player, ItemStack stack){
float f = 1.0F;

    if (player.capabilities.isFlying)
    {
        f *= 1.1F;
    }
    
    float speedOnGround = 0.1F;

    f *= (player.landMovementFactor * player.getSpeedModifier() / speedOnGround + 1.0F) / 2.0F;
    
int i = player.getItemInUseDuration();
    float f1 = (float)i / 19.0F;

    if (f1 > 1.0F)
    {
        f1 = 1.0F;
    }
    else
    {
        f1 *= f1;
    }

    f *= 1.0F - f1 * 0.16F;
    
    fovModifierHand = fovModifierHand > 0.001F ? fovModifierHand : (Float)ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");
    fovModifierHand += (f - fovModifierHand) * 0.5F;

    if (fovModifierHand > 1.5F)
    {
        fovModifierHand = 1.5F;
    }

    if (fovModifierHand < 0.1F)
    {
        fovModifierHand = 0.1F;
    }
    
ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");

}
@Override
public void onBowFOVZoomDiamond(EntityPlayer player, ItemStack stack){
float f = 1.0F;

    if (player.capabilities.isFlying)
    {
        f *= 1.1F;
    }
    
    float speedOnGround = 0.1F;

    f *= (player.landMovementFactor * player.getSpeedModifier() / speedOnGround + 1.0F) / 2.0F;
    
int i = player.getItemInUseDuration();
    float f1 = (float)i / 18.0F;

    if (f1 > 1.0F)
    {
        f1 = 1.0F;
    }
    else
    {
        f1 *= f1;
    }

    f *= 1.0F - f1 * 0.175F;
    
    fovModifierHand = fovModifierHand > 0.001F ? fovModifierHand : (Float)ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");
    fovModifierHand += (f - fovModifierHand) * 0.5F;

    if (fovModifierHand > 1.5F)
    {
        fovModifierHand = 1.5F;
    }

    if (fovModifierHand < 0.1F)
    {
        fovModifierHand = 0.1F;
    }
    
ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");

}
@Override
public void onBowFOVZoomTrillint(EntityPlayer player, ItemStack stack){
float f = 1.0F;

    if (player.capabilities.isFlying)
    {
        f *= 1.1F;
    }
    
    float speedOnGround = 0.1F;

    f *= (player.landMovementFactor * player.getSpeedModifier() / speedOnGround + 1.0F) / 2.0F;
    
int i = player.getItemInUseDuration();
    float f1 = (float)i / 19.0F;

    if (f1 > 1.0F)
    {
        f1 = 1.0F;
    }
    else
    {
        f1 *= f1;
    }

    f *= 1.0F - f1 * 0.15F;
    
    fovModifierHand = fovModifierHand > 0.001F ? fovModifierHand : (Float)ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");
    fovModifierHand += (f - fovModifierHand) * 0.5F;

    if (fovModifierHand > 1.5F)
    {
        fovModifierHand = 1.5F;
    }

    if (fovModifierHand < 0.1F)
    {
        fovModifierHand = 0.1F;
    }
    
ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");

}
@Override
public void onBowFOVZoomNether(EntityPlayer player, ItemStack stack){
float f = 1.0F;

    if (player.capabilities.isFlying)
    {
        f *= 1.1F;
    }
    
    float speedOnGround = 0.1F;

    f *= (player.landMovementFactor * player.getSpeedModifier() / speedOnGround + 1.0F) / 2.0F;
    
int i = player.getItemInUseDuration();
    float f1 = (float)i / 26.0F;

    if (f1 > 1.0F)
    {
        f1 = 1.0F;
    }
    else
    {
        f1 *= f1;
    }

    f *= 1.0F - f1 * 0.6F;
    
    fovModifierHand = fovModifierHand > 0.001F ? fovModifierHand : (Float)ObfuscationReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, "fovModifierHand", "field_78507_R");
    fovModifierHand += (f - fovModifierHand) * 0.5F;

    if (fovModifierHand > 1.5F)
    {
        fovModifierHand = 1.5F;
    }

    if (fovModifierHand < 0.1F)
    {
        fovModifierHand = 0.1F;
    }
    
ObfuscationReflectionHelper.setPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, fovModifierHand, "fovModifierHand", "field_78507_R");

}
@Override
public void resetSavedFOV() {
this.fovModifierHand = 0F;
}
@Override
public void registerClientTickHandler()
{
TickRegistry.registerTickHandler(new ClientTickHandlerFOV(), Side.CLIENT);

}



}

 

Thanks ahead of time :)

 

~Noah

This is the creator of the Rareores mod! Be sure to check it out at

Posted

Never mind, this post is REALLY old, I just needed to register it on the client and fixed a logic issue, use a forge event to prevent / reduce fall damage.

This is the creator of the Rareores mod! Be sure to check it out at

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.