-
Posts
2638 -
Joined
-
Last visited
-
Days Won
4
Everything posted by Ernio
-
Durability is stored inside ItemStack of given Item instance (there is only one Item). That data is stack's itemDamage and can be accessed from reference. Stack you can get from player.inventory#something (you should find right method). Accessing it can be done when you are crafting or inside any method/event that has Player/ ItemStack reference. Tell me - when do you want your faster-degradation debuff applied? On item crafting or in ench table or maybe by some itdk.. spell?
-
First of all - you can'r use global fields in Item class. There is only one instance of item. Note: onCreated is only called when you craft item with workbench. (You are probably pulling it from Creative Tab, thats why it doesn't have NBT) Everytime you try to do anything with NBT you should access that data directly (inside method, with local fields). That's pretty much all about NBT.
-
Well... playerUUID.dat is literally buffered NBT tag. Format is very similar to .zip (that's not relevant, just saying that it's similar). Anyway, dig into vanilla data loader class (i would start from EntityPlayer) and use it's methods to read NBTTag from .dat, then simply get tag you want and edit it. Useful: - Tags can be printed using Syso. - Editing it can be done probably anywhere in code (command?) - Note that you shouldn't edit .dat that is used by player (bam, corrupted or desynchro).
-
Question - what kind of files and what sizes/quantity you want to send? I for one am using ingame downloader, player events get cancelled for short time after you log in on server (0 interaction) and in VERY short time everything is downloaded/sychronized using packets. Obviously I am using CheckSums (hashes). Steps: Since PlayerLoggedInEvent is launched ONLY on Server i had to 1st send packet from server to client that is literally "start synchronization" msg. 1. Cancel player events. 2. Server -> Client - open GUI on client that shows progress. 3. Client -> Server - get all cached files and generate hashes, put all into NBTTagList and send. 4. Server comapres hashes (note server-side hashes are pre-generated on startup) 5. Server sends series of packets: Lacking files and clear-cache packet containing hashes that are not on server (client removes them from cache). Note: This will work for literally everything you try to upload to client (server too lel), BUT you will need to use some packet-structure for bigger files. Player event cancellation makes sure he won't die/anything during synchro. P.S - this system is only good for smallr files, more like game data (sending skills, classes, races maybe, some special data like quests (lore, NPC talks) that you don't want to send everytime player is doing it). For bigger ones I'd suggest custom connection thread - in this caste it's just java stuff (ask google). Edit: Yes you can put binary file into packet (rather packetS) you will just need to read more about it (it's java, i suggest StackOverflow site) Oh and i got confused by "Transfer files to client" and "transfer binary files from client to server." (Described 1st one)
-
Debate here would be "Do I need that 9th slot?". Anyway you can obviously add new armourSlot using those classes: IEntityExtendedProperties - store data for player and write/read to/from NBT on player load/exit. IInventory - create inventory for player. Container - make server-side handler for inventory Gui - client side display class for your inventory Events: EntityConstructing (something alike idr) - to init new IEEP. Packets: To send from server to all clients the slot and ItemStack in given custom inventory. There are now 2 similar threads on forums on this topic, have look at: http://www.minecraftforge.net/forum/index.php/topic,26619.msg135680.html#msg135680 Or as you suggested use that 9th slot. The code is obviously shorter: -You don't need apckets to send custom data. -You don't need IEEP to store custom slots. -You don't need Gui/Container to display ANYTHING. So howTo: Use PlayerTickEvent on SERVER side and check player.inventory#indexOfSlot, you will be checking 1st of all for null ItemStack, then for instance, like if(stack instanceof MyCustomRing), then if it's true you can do whatever you want (e.g get some props from item and add them to player (like speed boost)), if it's false you can get the stack and move it to 1st empty OTHER slot or drop ot on ground (if there are non free). To do other stuff like Hurting (like armour) you can use as suggested before LivingHurtEvent.
-
Simply create custom block. I don't remember exact method name but you should fin something like "onBlockClicked" or something inside Block class. (I am not on my PC now). Then you'll need to check if side is server (world.isRemote stuff) and run code that: 1. Either add new item to player.inventory. 2. Spawn new EntityItem in world with x,y,z of block. Thats the outline of the "idea", provide some basic code for more help.
-
[1.7.10]How to I get entityPlayer of my own character?
Ernio replied to TheiTay's topic in Modder Support
If that is all you came up with then you'll need to learn how to setup forge mod. (Hint: You cant store fields like player globally) As to question: If you want Client-SIDE Mod that will make player WALK to x,y,z location he is looking at key-clicked you will need to use vanilla pathfiniding and Client-SIDE entity.motionX/Y/Z. Note that when using Client entity motions you need to stay in bounds of normal walk speed (otherwise server-side will warp you back to maximal possible location of you movement). If you want to TELEPORT on Client-SIDE - it's not possible, everything is handled by server. If you want to actually inform server of your actions and make server move your player then follow Romejanic hint and also use pathfinding but server side instead, to actually move player you will also use entity.motionX/Y/Z but you will ahve to execute it on both sides to keep everything smooth (otherwise the client will receive update-position packets from server and it MIGHT look like you are lagging). If you want to just teleport from Server-SIDE, also - send packet and simply set entity position/rotation on server. As to direct question: simplest way to trigger "movePlayerWhereHePointsTo" during the game? If you would use some custom item to trigger it you wouldn't have to use packets. So that is so-called "simple". -
http://d3dsacqprgcsqh.cloudfront.net/photo/aoZmAww_460sa_v1.gif[/img] That ain't how you make Packets in MC. Again, look up the link I provided: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-x-1-8-customizing-packet-handling-with It has literally EVERYTHING - look it up, it's not smart for me to just rewrite whole tutorial. Note from tutorial author: "Also, for those of you venturing into 1.8, the network code has not changed so you can use the exact same code*! Pretty awesome, no?" For sake of everything: /** * @author Ernio */ //OVERALL COMMENT: IMessage is responsible for creating message on sender side - in this case on SERVER //IMessageHandler is the one who handler messago on receiver, in this case it's AbstractClientMessageHandler - this class is a abstraction made to ensure handler is CLIENT side (implements IMessageHandler and checks client stuff) public class PacketSynchronizeInventory implements IMessage // This packet travels from Server to Client and should be invoked by Inventory on slot change. { private int playerId; // the id you will use later on client private int slot; //index of slot in you custom inv private ItemStack stack = null; //stack to send public PacketSynchronizeInventory() {} //Empty constructor is NEEDED (required by implementation of interface) public PacketSynchronizeInventory(EntityPlayer player, int slot) //Actual constructor of packet { // Init of packet data this.playerId = player.getEntityId(); this.slot = slot; this.stack = ExPlayer.get(player).getCustomInventory().getStackInSlot(slot); // Note: this all happens on server side inside you inventory class } @Override public void toBytes(ByteBuf buffer) //encoding { buffer.writeInt(this.playerId); buffer.writeByte(this.slot); PacketBuffer pb = new PacketBuffer(buffer); try { pb.writeItemStackToBuffer(this.stack); //vanilla tool for encoding } catch (IOException e) { } } @Override public void fromBytes(ByteBuf buffer) //decoding { this.playerId = buffer.readInt(); this.slot = buffer.readByte(); PacketBuffer pb = new PacketBuffer(buffer); try { this.stack = pb.readItemStackFromBuffer(); } catch (IOException e) { } } //Statci handler (receiver class) working on CLIENT public static class PacketSynchronizeInventoryHandler extends AbstractClientMessageHandler<PacketSynchronizeInventory> { @Override public IMessage handleClientMessage(EntityPlayer player, PacketSynchronizeInventory message, MessageContext ctx) { //message contains all sent data *World world = Main.proxy.getClientWorld(); *if (world == null) return null; *Entity p = world.getEntityByID(message.playerId); *if (p != null && p instanceof EntityPlayer) //Those 4 lines with * are total bullshit, I used that before I jumped on abstract layer and forgot to remove it, now I can simply use player from method's 1st parameter, jut noticed that lol { ExPlayer.get((EntityPlayer) p).getCustomInventory().stackList[message.slot] = message.stack; //pretty obvious } return null; //You can return client answer to this packet } } } Registering" registerMessage(PacketSynchronizeInventoryHandler.class, PacketSynchronizeInventory.class, Side.CLIENT); // handler, sender, handling-side - from SERVER to CLIENT so handling side in CLIENT obviously. Invoking packet: Inside you IInventory you have to call this syncing on: setInventorySlotContents decrStackSize dropItems Whenever slot has changed. How to send: //This is what is invoked by 3 methods above. PacketDispatcher.sendToAll(new PacketSynchronizeInventory(player.get(), slot)); Remember to make sure it's only called server side. Pretty much everything. Also - Cheers to coolAlias! P.S - I only glympsed on your code, I assumed your GuiHandler is working properly and both Container and Gui are not crashing (you gave no error log)
-
His tutorials are probably best you'll find. I alredy pointed out: "Note: This is pretty Intermidiate/Advanced stuff and will take some time to make, so make sure you know what you can/want." Write something, post your code and error, we won't write whole mod for you. I wrote you everything you should learn to make this, now go and read some vanilla/forge code, it is not "making of block" and will need you to UNDERSTAND the code, not blindly follow method names and guessing. (use Syso and check caller methods to see how it's being processed). If you'll need more accurate help then post error/code with more not-so-general question. P.S: His tutorials are updated to 1.8/1.7.10 and if you spend at least few hours you could easily make it work following steps and then experimenting.
-
I don't see how giving us Main mod file is gonna help. Anyway - did you even have inventory made? Howto: Use IEntityExtendedProperties to store additional slots to player data. Use IInventory to make inv. Use IGuiHandler to open inv server/client-side. Use Packets to make updates: - When using IGuiHandler you open a container on server side and gui on client, hence you will need to send custom slot update packet to all players everytime something is edited in container. (on item move inside container (slots), do: sendToAll(new UpdatePacket(player, slotIndex)). public UpdatePacket(EntityPlayer player, int slotIndex) { this.playerId = player.getEntityId(); this.slot = slot; this.stack = ExPlayer.get(player).getCustomInv().getStackInSlot(slot); } This will be send to all clients, and all clients will update client-side ExtendedPlayer data for given playerId. To see how to make such packets you will need this: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-2-customizing-packet-handling-with This link also contains pretty much everything you need to dig into IEEP and containers. Useful tools: this.stack = pb.readItemStackFromBuffer(); pb.writeItemStackToBuffer(this.stack); In handler: Use this to get player from snt id. Entity p = world.getEntityByID(message.playerId); Remember casting and null checks. Note: This is pretty Intermidiate/Advanced stuff and will take some time to make, so make sure you know what you can/want.
-
[1.7.10] My custom Web Block crashes with getPlayerRelativeBlockHardness
Ernio replied to SteveKunG's topic in Modder Support
In #getPlayerRelativeBlockHardness() ItemStack stack = player.inventory.getCurrentItem(); if (stack != null && (stack.getItem() instanceof ItemSword || stack.getItem() == Items.shears)) { return 0.1F; } return ForgeHooks.blockStrength(this, player, world, x, y, z); ***stack != null*** Also shears are not extending Sword so: stack.getItem() == Items.shears && stack.getItem() instanceof ItemSword Which you wrote will always be false. -
Idk if that's proper way, but you can simply add dependency (check if loaded) and do Block.getBlockFromName(String). Other way is obviously adding mod to your workspace libs.
-
General note: You SHOULDN'T allow client to edit server values, that is very unsafe if you ask me. CustomItem theCustomItem - you don't need to send it. Basically (following my previous post) you wan't to send new damageValue, then in handler you will need to: ctx.getServerHandler().playerEntity.inventory //ctx is MsgContext Then get your item and edit it on server side. After editing, given ItemStack will auto-update to all since ItemStacks are auto updated. Note that you can only edit meta and NBT (you probably know that). Remember to properly register packet (Side.SERVER) - everything is included in tut i linked
-
Some logical help here: SharedMonsterAttributes - BASIC value of attribute shared between ALL entities using this class. AttributeModifier - a modifier saved in map that is actually assigned to entity, there you can edint this basic attribute and that's what you should use for you damage editing. write/readNBT() methods - here you will need to save/load entitie's NBT data to make it be custom. Static - after you read what it is, I will just add - in MC you should almost NEVER use static fields (unless they are actually static), so basically never in Item, Block, Entity, some other.
-
It will never work. KeyBindings are client side. You will need to send packet to server if you want to apply any kind of changes. How To: On KeyBinding send packet, get sender from context, get his inventory, get itemstack, check nulls, get item, update item. Good tutorial on packets: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-x-1-8-customizing-packet-handling-with
-
[1.7.10] My custom Web Block crashes with getPlayerRelativeBlockHardness
Ernio replied to SteveKunG's topic in Modder Support
Is it NPE? My guess is not checking for null itemStack You need to check if itemStack is not null before you cast it to any kind of item. ItemStack current = inv.getCurrentItem(); if (current != null && current.getItem() instanceof SomeItem) -
99% sure that mod is outdated. It will not work on 1.7.10, check latest version it might work on (I found 1.6 and MAYBE 1.7.2, haven't looked deeper). Also - this is wrong forum.
-
Writing good GUI tools is always time-consuming so I am asking you guys - anyone seen open-source mod that has this and/or maybe has it on his own and would care to share? Maybe it's somewhere in vanilla and I missed it? (I can't think of anything that uses it) "Code that on your own." is not necessary, I am just asking here before I "waste" few hours.
-
Wiki tutorial shows basic "what should I do to..." http://www.minecraftforge.net/wiki/Tutorials/Configuration_files You won't find much of those tuts because every config is different. Everything is included in Configuration.class with very good documentation. After hour or two of testing you should be able to make any structure you want. Also - update to 1.7.10+
-
Setting up mod is "that straightforward". Mods are being loaded by FML - That happens during game initialization. You can't just get something that doesn't exist yet. In this case Blocks.cobblestone is null because it hasn't been initialized yet. Anyway: http://www.minecraftforge.net/forum/index.php?topic=14048.0#post_update_forge Follow steps, you will get generic mod, then do whetever you want. API is not a program itself, it's an API that need something to run on (MC, thet need to be setup).
-
[SOLVED][1.7.10] On block placed method is executed twice?
Ernio replied to DonKresenko's topic in Modder Support
Could you post updated code (or update 1st post), there is just no way this spawns twice if you did as suggested. -
Uhm... DL uses shitload of ASM to make that "satisfactorily" well-done... Aaaand it's still VERY fps consuming. Without ASM it will be even more resource-eating. You can either spawn invisible block under player and remove it each tick or few or... http://www.minecraftforge.net/forum/index.php/topic,26351.0.html #readLastPost Thread is literally 2 days old (what a coincidence)
-
In LivingHurtEvent check if source was other entity, get that entity and compare pitch/yaw of entity hurt (remember casting, instanceof) with position of attacker. I'm just adding something more.
-
If you don't understand it yet, you need more java knowledge, you probably won't get any "done" code here. Here's good tutorial on this stuff: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-forge-1-6-4-1-8-eventhandler-and
-
net.minecraft.client.settings.GameSettings public KeyBinding keyBindUseItem; public KeyBinding keyBindDrop; public KeyBinding keyBindAttack; public KeyBinding keyBindPickBlock; public KeyBinding keyBindSprint;