Jump to content

Recommended Posts

Posted

Not tried this in 1.5.x yet, but in 1.4.7 you could call "player.capabilities.allowFlying = true;" in the on armor update method for the armor, this does have the draw back of not being deactivated when it is removed, so alternatively you can create a player tick handler as follows:

import java.util.EnumSet;

import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class PlayerTickHandler implements ITickHandler
{

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
	playerTick((EntityPlayer) tickData[0]);

}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
	// TODO Auto-generated method stub

}

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

@Override
public String getLabel()
{
	return "My Tick Handler";
}



private void playerTick(EntityPlayer player)
{
	//think 0 is helmet, haven't got the setup to try this yet
	player.capabilities.allowFlying = 
			(player.inventory.armorInventory[0] == myHelmet || player.capabilities.isCreativeMode);
}

}

 

then reference this in your common proxy as

import mtech.code.handler.tick.PlayerTickHandler;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;


public class CommonProxy
{
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.SERVER);
}
}

 

and in the client proxy as

import mtech.code.handler.tick.PlayerTickHandler;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;


public class ClientProxy
{
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.CLIENT);
}
}

 

finally in your main mod file (the one with all the annotations (@)) call

proxy.registerHandlers();

 

hope i helped

Posted
  On 4/25/2013 at 6:49 PM, Yagoki said:

Not tried this in 1.5.x yet, but in 1.4.7 you could call "player.capabilities.allowFlying = true;" in the on armor update method for the armor, this does have the draw back of not being deactivated when it is removed, so alternatively you can create a player tick handler as follows:

import java.util.EnumSet;

import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class PlayerTickHandler implements ITickHandler
{

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
	playerTick((EntityPlayer) tickData[0]);

}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
	// TODO Auto-generated method stub

}

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

@Override
public String getLabel()
{
	return "My Tick Handler";
}



private void playerTick(EntityPlayer player)
{
	//think 0 is helmet, haven't got the setup to try this yet
	player.capabilities.allowFlying = 
			(player.inventory.armorInventory[0] == myHelmet || player.capabilities.isCreativeMode);
}

}

 

then reference this in your common proxy as

import mtech.code.handler.tick.PlayerTickHandler;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;


public class CommonProxy
{
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.SERVER);
}
}

 

and in the client proxy as

import mtech.code.handler.tick.PlayerTickHandler;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;


public class ClientProxy
{
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.CLIENT);
}
}

 

finally in your main mod file (the one with all the annotations (@)) call

proxy.registerHandlers();

 

hope i helped

I tried it and it wont work

Posted

How so? can i see your relevant code (Main mod file, proxies...)

 

[EDIT] have you tried editing the number in the item[] for the armor inventory, i wasn't definite that 0 was correct for the helmet, so that could be the problem

Posted

finally got to a point where i could do some testing on this. I got it to work pretty much first time so nut sure what you're doing wrong, Here's my code: (just make sure you understand what it's doing, far too many people just copy and paste without thinking about it)

 

Main file

@Mod(modid="TestMod", name="TestMod", version = "0.0.0")
@NetworkMod(serverSideRequired=false, clientSideRequired=true)
public class TestMod
{
@Instance("Testmod")
public static TestMod instance;

@SidedProxy(clientSide="mods.testmod.code.client.ClientProxy", serverSide="mods.testmod.code.common.CommonProxy")
public static CommonProxy proxy;

@PreInit
public static void preInit(FMLPreInitializationEvent evt)
{

}

public static Item modHat;

@Init
public static void init(FMLInitializationEvent evt)
{
	modHat = new ItemModArmor(9001, ItemModArmor.ModArmor, 0, 0)
	.setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("modHat");

	LanguageRegistry.addName(modHat, "Mod Hat");

	proxy.registerHandlers();
}

@PostInit
public static void postInit(FMLPostInitializationEvent evt)
{

}
}

 

ItemModArmor

public class ItemModArmor extends ItemArmor
{
public static final EnumArmorMaterial ModArmor = EnumHelper
		.addArmorMaterial("ModArmor", 9001, new int[]{1,2,3,4}, 42);


public ItemModArmor(int par1, EnumArmorMaterial par2EnumArmorMaterial, int par3, int par4)
{
	super(par1, par2EnumArmorMaterial, par3, par4);
}

}

 

PlayerTickHandler

public class PlayerTickHandler implements ITickHandler
{

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
	playerTick((EntityPlayer)tickData[0]);
}

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

}

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

@Override
public String getLabel()
{
	return "My_Tick_Handler";
}

private void playerTick(EntityPlayer player)
{
	if (player.inventory.armorInventory[3] != null)
	{
		if (player.inventory.armorInventory[3].getItem() instanceof ItemModArmor)
		{
			player.capabilities.allowFlying = true;

		} 
	}
	else if (!player.capabilities.isCreativeMode)
	{
		player.capabilities.allowFlying = false;
	}

	player.fallDistance = 0F; // does not seem to be working not worked out why yet.
}

}

 

Proxys

public class CommonProxy
{
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.SERVER);
}
}

 

public class ClientProxy extends CommonProxy
{
@Override
public void registerHandlers()
{
	TickRegistry.registerTickHandler(new PlayerTickHandler(), Side.CLIENT);
}

}

 

Think that's all of it, didn't bother with textures but the flying works.

if you figure out the fall damage tell me how

 

 

[EDIT]

upon further testing it seems that this method is not working 100% correctly, as it seems that there is some desynchronization between the client and server, meaning that when the player takes damage he will move back to where the server thinks they are. Not sure how to fix this atm but i'll get back to you

Posted

You know there is an easier way to do this right?

 

package O3Bubbles09.testmod.armor;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.IArmorTextureProvider;

public class ArmorFlyingArmor extends ItemArmor implements
        IArmorTextureProvider {

    public ArmorFlyingArmor(int par1, EnumArmorMaterial par2EnumArmorMaterial,
            int par3, int par4) {
        super(par1, par2EnumArmorMaterial, par3, par4);
    }

    public void onArmorTickUpdate(World world, EntityPlayer player,
            ItemStack itemStack) {
        
        if(!world.isRemote) {
            player.capabilities.allowFlying = true;
        }
        super.onArmorTickUpdate(world, player, itemStack);
    }
    
    public String getArmorTextureFile(ItemStack itemstack) {
        return null;
    }

}

Posted

I thought of that (see my first reply to this topic), but that doesn't remove the ability once the armor has been removed, so doesn't really have the desired effect.

 

Does work better than my method though, so if a workaround for this exists then use this. (but the if(!world.isRemote) is not required as both the client and server need to know the player can fly for it to work properly)

 

[EDIT]

a possible work around would exist if multiple pieces of armor were being worn, as you could check the armor inventory before enabling the flight, and then deactivate if a piece is missing, however i'm not sure how this would respond on death or some more peculiar case when all the pieces are removed simultaneously

Posted

A tick Handler, like you wanted to do it previously, would be the better solution. Did you try to register in the ClientProxy the TickHandler for both sides (client and server)? So having two registrations for it in the client proxy (since on the client, the CommonProxy stuff is not called, unless you add super.registerHandlers(), which should not be done).

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

on the tick handler I don't think the problem is with the client. The client shows the player flying fine until the server sends its "idea" of the player to the client when events such as damage happen occur, as these happen on the server. (at least that's how i understand it, i've not looked into it too far so i could be wrong). I will try what you said and probably ad some debug lines to see if i can figure out why it's acting weirdly.

 

[EDIT]

well that worked! Thanks, even though it wasn't my problem... haha.

if someone could explain to me why that was necessary that would be super.

Posted
  On 4/30/2013 at 6:05 PM, Yagoki said:

on the tick handler I don't think the problem is with the client. The client shows the player flying fine until the server sends its "idea" of the player to the client when events such as damage happen occur, as these happen on the server. (at least that's how i understand it, i've not looked into it too far so i could be wrong). I will try what you said and probably ad some debug lines to see if i can figure out why it's acting weirdly.

 

Yes, because, following your previous code, the ticks don't happen on the (internal) server-side. They need to happen on the client both, client-sided and server-sided. On a dedicated server, they only need to happen server-sided.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • it was flywheel, it's solved now and i am reporting it but i am going to figure what create addon was the cause or if was create itself  
    • I deleted delightful and all farmers delight addon (just in case) and still i have the error :'(, i need to check mod by mod?
    • I'm developing a Forge mod for Minecraft 1.16.5 to run on CatServer (version 1.16.5-1d8d6313, Forge 36.2.39). My mod needs to get the player's UUID from a ServerPlayerEntity object within a Forge ServerChatEvent handler. When I use serverPlayerEntity.getUUID(), my mod compiles fine, but I get a java.lang.NoSuchMethodError: net.minecraft.entity.player.ServerPlayerEntity.getUUID()Ljava/util/UUID; at runtime. I cannot use serverPlayerEntity.getUniqueID() as it causes a compile error (cannot find symbol). Is there a known issue with this on CatServer, or a recommended way for a Forge mod to reliably get a player's UUID from ServerPlayerEntity in this environment? My goal is to pass this UUID to the LuckPerms API (which is running as a Bukkit plugin and successfully connected via ServicesManager). erorr ChatMod: FMLServerStartedEvent received. Attempting to initialize LuckPerms connection... [22:45:20] [Server thread/INFO]: ⚙️ Початок ініціалізації LuckPerms API через Bukkit Services Manager... [22:45:20] [Server thread/INFO]: ✅ Bukkit ServicesManager успішно отримано. [22:45:20] [Server thread/INFO]: ✅ Реєстрацію сервісу LuckPerms знайдено. [22:45:20] [Server thread/INFO]: ✅ API LuckPerms успішно отримано від Bukkit plugin! [22:45:20] [Server thread/INFO]: Використовується реалізація: me.lucko.luckperms.common.api.LuckPermsApiProvider [22:45:20] [Server thread/INFO]: ✅ LuckPerms API схоже що успішно ініціалізовано через Bukkit Services Manager. [22:45:24] [User Authenticator #1/INFO]: UUID of player Hiklee is 92cd7721-2652-3867-896b-2ceba5b99306 [22:45:25] [Server thread/INFO]: Using new advancement loading for net.minecraft.advancements.PlayerAdvancements@24cb7a68 [22:45:26] [Server thread/INFO]: Hiklee[/127.0.0.1:41122] logged in with entity id 210 at (92.23203876864889, 95.6183020148442, 68.24087802017877) [22:45:28] [Async Chat Thread - #0/INFO]: ✅ Скасовано стандартне відправлення чату! [22:45:28] [Async Chat Thread - #0/ERROR]: Exception caught during firing event: net.minecraft.entity.player.ServerPlayerEntity.getUUID()Ljava/util/UUID; Index: 1 Listeners: 0: NORMAL 1: ASM: class com.example.chatmod.ChatEventHandler onPlayerChat(Lnet/minecraftforge/event/ServerChatEvent;)V java.lang.NoSuchMethodError: net.minecraft.entity.player.ServerPlayerEntity.getUUID()Ljava/util/UUID; at com.example.chatmod.ChatPacketHandler.getPlayerPrefix(ChatPacketHandler.java:46) at com.example.chatmod.ChatEventHandler.onPlayerChat(ChatEventHandler.java:32) at net.minecraftforge.eventbus.ASMEventHandler_1_ChatEventHandler_onPlayerChat_ServerChatEvent.invoke(.dynamic) at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) at net.minecraftforge.eventbus.EventBus.post(EventBus.java:303) at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) at net.minecraftforge.common.ForgeHooks.onServerChatEvent(ForgeHooks.java:493) at net.minecraft.network.play.ServerPlayNetHandler.chat(ServerPlayNetHandler.java:1717) at net.minecraft.network.play.ServerPlayNetHandler.func_244548_c(ServerPlayNetHandler.java:1666) at net.minecraft.network.play.ServerPlayNetHandler.func_147354_a(ServerPlayNetHandler.java:1605) at net.minecraft.network.play.client.CChatMessagePacket.lambda$handle$0(CChatMessagePacket.java:34) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:750
    • Thank you so much for your help, I'll try it as soon as I can. I have a genuine question because I'm not familiar with the matter: Can a recipe error cause something as serious as the AMD error?
    • When i try to launch my modpack, the instance crashes and this is sent to the logs: Time: 2025-05-27 23:07:18 Description: Rendering overlay Below is the full log: https://mclo.gs/jP5G2EH
  • Topics

×
×
  • Create New...

Important Information

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