-
Posts
16559 -
Joined
-
Last visited
-
Days Won
156
Everything posted by Draco18s
-
Yes. (I don't have the details behind how you would want to configure it, etc., so I cannot be more helpful).
-
Snip tool, actually, but it amounts to the same thing. (I love the Windows Vista/7 snip tool. *Drool*)
-
Ok, this is fairly easy then. public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { int level = 20; //pretend the player has 20 levels to spend par1ItemStack = EnchantmentHelper.addRandomEnchantment(new Random(), par1ItemStack, level); } In theory that should work. There may be some helpers that need to be called to get your custom item recognized as valid [tool|bow|armor], I'm not sure. My items are going about it slightly differently (as I'm using one item class that results in items with varying effects, so "is it a tool?" is dependent on NBT data) so I'm actually enchanting a vanilla pickaxe/sword/armor (as appropriate) and then copying the relevant NBT data over to my item: Item item = Item.pickaxeWood; //pick a random amount of experience to use. Higher amounts are rarer. Minimum 5. int level = 4; do { ++level; } while(level < 30 && instance.rand.nextInt( != 0); //if it has the deal-damage effect, treat it as a sword if(effectsOnItem.contains(2) && instance.rand.nextBoolean()) { //get item's material switch(artifact.stackTagCompound.getInteger("material")) { case 0: item = Item.swordWood; break; case 1: item = Item.swordStone; break; case 2: item = Item.swordIron; break; case 3: item = Item.swordGold; break; case 4: item = Item.swordDiamond; break; } } //else treat it as a tool (imperfect, but acceptable; armor not coded yet) else { switch(artifact.stackTagCompound.getInteger("material")) { case 0: item = Item.pickaxeWood; break; case 1: item = Item.pickaxeStone; break; case 2: item = Item.pickaxeIron; break; case 3: item = Item.pickaxeGold; break; case 4: item = Item.pickaxeDiamond; break; } } //enchant the sword/pickaxe ItemStack stack = new ItemStack(item); stack = EnchantmentHelper.addRandomEnchantment(instance.rand, stack, level); //copy the enchantment from the temporary item to the real item artifact.stackTagCompound.setTag("ench", stack.stackTagCompound.getTag("ench").copy());/code] It's very easy if you are looking for a very specific enchantment, as ItemStack has this function: public void addEnchantment(Enchantment par1Enchantment, int par2){...} Easy peasy!
-
-
Sounds like you're deleting the card on the server and not sending the change to the client or vice versa.
-
[solved] changing leaf texture based on graphics level
Draco18s replied to Kakarotvg's topic in Modder Support
I looked into this once. I don't recall if I ever found a solution. I'll dig up my old code and see if it worked, and if so, I'll post it. -
You don't need to add and delete icons at "any time." You're either going to register icons at startup or you're not.
-
Getting EntityPlayer parameter outside of the method itself
Draco18s replied to Flenix's topic in Modder Support
You mean this? public class PacketHandlerServer implements IPacketHandler{ @Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) -
Sure you can. Question is: Do you want to add a specific enchantment manually or do you want to apply a random enchantment that is appropriate, or do you want to apply any random enchantment? (I happen to be in the middle of working on this myself!)
-
Getting EntityPlayer parameter outside of the method itself
Draco18s replied to Flenix's topic in Modder Support
String str = "" + myInt; -
Getting EntityPlayer parameter outside of the method itself
Draco18s replied to Flenix's topic in Modder Support
Not sure, try it and find out! Experimentation is why I like modding so much. ^..~ The first chunk needs to go everywhere you need to send a packet. You might be able to get away with creating a utils class/function that could handle it, so you'd just be passing the required info to the utils class/function. It'd be a little less flexible, though, as you wouldn't be able to handle complex information (i.e. if one button sends two ints and a float, the second button sends four ints and a string, the third button passes three floats, etc.). -
Getting EntityPlayer parameter outside of the method itself
Draco18s replied to Flenix's topic in Modder Support
The first chunk would go in your GUI class. The place where the action is being performed. In my case, it was in the item class's onRightClick / itemInteractionForEntity / hitEntity function(s). Wherever it is that you need to go "world needs to change here" but you don't have the server's world (or access to any world, even! Packets can be fired off from anywhere in the program's operation, and when handled by the server's packet handler, you will have access to the player that the packet came from as well as the world). Yeah, I stripped it out as its not important what function it's from. I pulled it from: public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { But the only reason I use the par3EntityPlayer is because I am operating on that entity. But now that I've changed it to not send the health total (just a "1" so that on the packet handler side I get what the server believes is the player's health and adds 1, to avoid race conditions) I could strip that out, even. How do you mean? -
Looks just about the same as what I do.
-
Getting EntityPlayer parameter outside of the method itself
Draco18s replied to Flenix's topic in Modder Support
Packets are really easy when it comes down to it. On the client sided function, you add this: ByteArrayOutputStream bt = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bt); try { //we will first need to know what action we're performing when the packet is read. //A switch statement on the first integer will let us do that out.writeInt(1); //Then the data relevant to the action being performed. In my case, I'm increasing the player's //health by 1, so I'm sending the value I want to set it to. //(Probably should calculate this server side....) out.writeFloat(par3EntityPlayer.getHealth()+1); //Then we construct a packet. The string parameter here is the "channel" we're using. Usually mod_id Packet250CustomPayload packet = new Packet250CustomPayload("Artifacts", bt.toByteArray()); //What player to send it to, not used here, but in server->client communication you'd need it Player player = (Player)par3EntityPlayer; //And send it off! PacketDispatcher.sendPacketToServer(packet); par1ItemStack.damageItem(1, par3EntityPlayer); } catch (IOException ex) { System.out.println("couldnt send packet!"); } Before we can do anything with that though, we need to set up our mod to be a NetworkMod. @NetworkMod(clientSideRequired = true, serverSideRequired = false, clientPacketHandlerSpec = @SidedPacketHandler(channels = {"Artifacts"}, packetHandler = PacketHandlerClient.class), serverPacketHandlerSpec = @SidedPacketHandler(channels = {"Artifacts"}, packetHandler = PacketHandlerServer.class)) Here you can see the channel being declared (there's a character limit, I think it's 16) and that we're setting up two classes to handle packets, one client-side, one server-side. You can use the same class for both, but it's not good practice in the long term. Finally, the packet handler class public class PacketHandlerServer implements IPacketHandler{ @Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { //again we need to check for the proper channel if (packet.channel.equals("Artifacts")) { handleRandom(packet, player); } } private void handleRandom(Packet250CustomPayload packet, Player player) { EntityPlayer p = (EntityPlayer) player; World world = p.worldObj; DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet.data)); //System.out.println("Packet get"); try { //here's that first integer again. int effectID = dis.readInt(); switch(effectID) { case 1: //and then the data we sent p.setHealth(dis.readFloat()); break; } } catch (IOException e) { System.out.println("Failed to read packet"); } finally { } } } -
I don't think that annotation means what you think it means. --Inigo Montoya (Hint: That particular annotation only has an effect inside your IDE to trigger additional error checking; leaving it off has no effect once the program is compiled)
-
Huh. I'm not having that problem. Though I did have a weird problem where the item onRightClick method would only be partially functional; as if it was running client-side only (that is, it was running on the server side as well, but that changes to entities wouldn't stick,* as if they'd been done client side). *My one test before I moved over to a packet based system dealt with healing the player with that function. I didn't try other effects, like lightning and so on, simply went "fine, this isn't working as expected" and shoved everything into packets.
-
Yeah, you're going to have to register them anyway. Here's what I did: public void registerIcons(IconRegister iconReg) { //can't loop this as there are different amounts of each set itemIcon = iconReg.registerIcon("artifacts:artifact1"); icons.put("artifact1",itemIcon); icons.put("amulet1",iconReg.registerIcon("artifacts:amulet1")); icons.put("amulet2",iconReg.registerIcon("artifacts:amulet2")); icons.put("amulet3",iconReg.registerIcon("artifacts:amulet3")); icons.put("amulet4",iconReg.registerIcon("artifacts:amulet4")); icons.put("dagger1",iconReg.registerIcon("artifacts:dagger1")); icons.put("dagger2",iconReg.registerIcon("artifacts:dagger2")); icons.put("dagger3",iconReg.registerIcon("artifacts:dagger3")); icons.put("dagger4",iconReg.registerIcon("artifacts:dagger4")); icons.put("figurine1",iconReg.registerIcon("artifacts:figurine1")); icons.put("figurine2",iconReg.registerIcon("artifacts:figurine2")); icons.put("ring1",iconReg.registerIcon("artifacts:ring1")); icons.put("ring2",iconReg.registerIcon("artifacts:ring2")); icons.put("ring3",iconReg.registerIcon("artifacts:ring3")); icons.put("ring4",iconReg.registerIcon("artifacts:ring4")); icons.put("ring5",iconReg.registerIcon("artifacts:ring5")); icons.put("ring6",iconReg.registerIcon("artifacts:ring6")); icons.put("ring7",iconReg.registerIcon("artifacts:ring7")); icons.put("staff1",iconReg.registerIcon("artifacts:staff1")); icons.put("staff2",iconReg.registerIcon("artifacts:staff2")); icons.put("staff3",iconReg.registerIcon("artifacts:staff3")); icons.put("staff4",iconReg.registerIcon("artifacts:staff4")); icons.put("sword1",iconReg.registerIcon("artifacts:sword1")); icons.put("sword2",iconReg.registerIcon("artifacts:sword2")); icons.put("sword3",iconReg.registerIcon("artifacts:sword3")); icons.put("trinket1",iconReg.registerIcon("artifacts:trinket1")); icons.put("trinket2",iconReg.registerIcon("artifacts:trinket2")); icons.put("trinket3",iconReg.registerIcon("artifacts:trinket3")); icons.put("trinket4",iconReg.registerIcon("artifacts:trinket4")); icons.put("trinket5",iconReg.registerIcon("artifacts:trinket5")); icons.put("trinket6",iconReg.registerIcon("artifacts:trinket6")); icons.put("trinket7",iconReg.registerIcon("artifacts:trinket7")); icons.put("wand1",iconReg.registerIcon("artifacts:wand1")); icons.put("wand2",iconReg.registerIcon("artifacts:wand2")); icons.put("wand3",iconReg.registerIcon("artifacts:wand3")); icons.put("wand4",iconReg.registerIcon("artifacts:wand4")); icons.put("wand5",iconReg.registerIcon("artifacts:wand5")); icons.put("boots1",iconReg.registerIcon("artifacts:boots1")); icons.put("chestplate1",iconReg.registerIcon("artifacts:chestplate1")); icons.put("helm1",iconReg.registerIcon("artifacts:helm1")); icons.put("leggings1",iconReg.registerIcon("artifacts:leggings1")); } public Icon getIcon(ItemStack stack, int pass) { Icon i = itemIcon; if(pass == 0) { if(stack.stackTagCompound == null) { return itemIcon; } i = (Icon) icons.get(stack.stackTagCompound.getString("icon").toLowerCase()); if(i == null) { i = itemIcon; } } return i; }
-
1) Use world.isRemote to determine if the entity is client side, if it is, do nothing. 2) If it is not client side, every time it updates, send any changed data to the client using Packet250CustomPayload 3) Add a packet handler on your client side to handle these packets and update the entity on the client end
-
I, myself, have only managed so far as to not completely fuck things up doing a minor thing, largely through the use of existing code, lots of Javadoc, and some blind luck.
-
That is a mite bit trickier, but doable. Your options: 1) Reflections (tricky, as Reflections is not a simple thing) 2) Base class edits (I would hazard you would not like this) 3) Creating custom items and then forcing them into the items array where the vanilla items reside (not entirely kosher)
-
[1.6.2]Changing a Specific Block's (x,y,z) Texture
Draco18s replied to Vemahk20's topic in Modder Support
I didn't forget it, i was just hoping that there would be a way around it without using a tile entity, which there appears not to... Thanks anyway Look for my reply in that thread. The one that starts "Ohsitdude, you don't need custom renderers or TileEntities for this." -
There are other ways of handling this. Namely, doing something like this in the item's class @Override public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) { if (par2Block != Block.oreCoal && par2Block != Block.oreIron && par2Block != Block.oreEmerald && par2Block != Block.oreGold && par2Block != Block.oreDiamond && par2Block != Block.oreNetherQuartz && par2Block != Block.oreLapis && par2Block != Block.oreRedstone && par2Block != Block.oreRedstoneGlowing) { return 0; } else { return 15; } } If the strength vs. the block returns 0 (or less) then no progress is ever made towards breaking it (punching with no/inappropriate tool is roughly 0.25). The 15 could be modified by material the item is made out of, etc. etc. This was just a quick implementation for a mod I'm making where it is not yet important what value is being returned, only that it is sufficiently large.
-
That's kinda why I made the suggestion. http://forums.dumpshock.com/style_emoticons/default/sarcastic.gif[/img] It's completely bonkers for a protected method ("I'm sorry, this function does something absolutely critical to the functioning of the program that you can't change it") only calls a non-protected ("change this at your whim") method.