Jump to content

Ernio

Forge Modder
  • Posts

    2638
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by Ernio

  1. getCurrentEquippedItem().getItem() == Mod.myItem CHeck if stack is not null before getting item.
  2. You can't hold fields inside Item itself. You need to store them into NBT of given ItemStack (there is one on onUpdate()). onUpdate() is called always when item is in player's inventory, do additional check if player is holding given item (the one that actually check for sprinting).
  3. You should NEVER use threads and stuff like sleep if you don't know what you are doing (you don't). Don't transfer energy once per loop, do it once per tick(or few ticks) or all at same time. More explanation: Minecraft runs on game loop - ticks, 20/sec. (Note: Not talking about rendering ticks - those are different (fps)) All update-like methods are called once per tick. If you want to transfer energy overtime you do it per tick.
  4. 1. Use scaled x/y In GuiScreen it's this.width this.height You can get it on your own: scaledresolution.getScaledHeight(); (ScaledResolution.class) 2. "overlay for the deeper gui page." What you mean? Post code.
  5. I never knew what is the best way to get entities, BUT I know this. Let's say your vector is arrow, you entity is some box. To know that arrow hit box you need to check if vector is "touching" box. You need to actually do that. Have a look at EntityThrowable#onUpdate() Vec3 vec3 = new Vec3(this.posX, this.posY, this.posZ); Vec3 vec31 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31); vec3 = new Vec3(this.posX, this.posY, this.posZ); vec31 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (movingobjectposition != null) { vec31 = new Vec3(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } if (!this.worldObj.isRemote) { Entity entity = null; List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D)); double d0 = 0.0D; EntityLivingBase entitylivingbase = this.getThrower(); for (int j = 0; j < list.size(); ++j) { Entity entity1 = (Entity)list.get(j); if (entity1.canBeCollidedWith() && (entity1 != entitylivingbase || this.ticksInAir >= 5)) { float f = 0.3F; AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand((double)f, (double)f, (double)f); MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31); if (movingobjectposition1 != null) { double d1 = vec3.distanceTo(movingobjectposition1.hitVec); if (d1 < d0 || d0 == 0.0D) { entity = entity1; d0 = d1; } } } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } } if (movingobjectposition != null) { if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.worldObj.getBlockState(movingobjectposition.getBlockPos()).getBlock() == Blocks.portal) { this.setInPortal(); } else { this.onImpact(movingobjectposition); } } Every tick there is check if EntityThrowable's bounding box touches any other box in 1.0D "lenght" (box size). That is the way to get the entity hit. Notice how it checks which entity was hit 1st and stuff. Pretty neat. And yes - unless you want to go with VERY complicated 3D math on your own, this is best way provided by vanilla (for me at least).
  6. Use rayTracing. Before 1.8 client look vector was on players eyes, server one was not. Since 1.8 both are from eyes, but vanilla method is for client only. Copy vanilla rayTracing method and use it on server. Note: Find here: Entity#rayTrace
  7. Yup, that explains it. This line was long enough for me to miss adding stack to inv. if (this.delayBeforeCanPickup <= 0 && (this.owner == null || lifespan - this.age <= 200 || this.owner.equals(entityIn.getName())) && (hook == 1 || i <= 0 || entityIn.inventory.addItemStackToInventory(itemstack))) *applauds*
  8. Okay, so invastagating led me to "how to", but I don't undestand why and where to look for answers: There are 2 events for picking up items, one fired before - Forge (cancellable) one after on actual pickup (FML). What I don't understand is why ItemStack in FML event is not "real" (it can't get full ItemStack data). Forge: @SubscribeEvent public void entityPickup(EntityItemPickupEvent event) { ItemStack stack = event.item.getEntityItem(); if(stack != null) { System.out.println("EntityItemPickupEvent: " + stack + " Size: " + stack.stackSize); } } FML: @SubscribeEvent public void itemPickup(ItemPickupEvent event) { ItemStack stack = event.pickedUp.getEntityItem(); if(stack != null) { System.out.println("ItemPickupEvent: " + stack + " Size: " + stack.stackSize); } } (NBT is too lost in FML) [16:17:44] [server thread/INFO] [sTDOUT]: [x.ForgeEvents:entityPickup:38]: EntityItemPickupEvent: 1xitem.stick@0 Size: 1 [16:17:44] [server thread/INFO] [sTDOUT]: [x.FMLEvents:itemPickup:33]: ItemPickupEvent: 0xitem.stick@0 Size: 0 [16:17:57] [server thread/INFO] [sTDOUT]: [x.ForgeEvents:entityPickup:38]: EntityItemPickupEvent: 59xitem.stick@0 Size: 59 [16:17:57] [server thread/INFO] [sTDOUT]: [x.FMLEvents:itemPickup:33]: ItemPickupEvent: 0xitem.stick@0 Size: 0 [16:18:07] [server thread/INFO] [sTDOUT]: [x.ForgeEvents:entityPickup:38]: EntityItemPickupEvent: 12xitem.stick@0 Size: 12 [16:18:07] [server thread/INFO] [sTDOUT]: [x.FMLEvents:itemPickup:33]: ItemPickupEvent: 0xitem.stick@0 Size: 0 I was trying to figure it out, but looking at how are they called leaves me with no explanation. Also, why is this passed: (EntityItem#onCollideWithPlayer) int hook = net.minecraftforge.event.ForgeEventFactory.onItemPickup(this, entityIn, itemstack); ...if the ForgeEventFactory#onItemPickup is not actually using that ItemStack? Asking because this is literally only difference between those two events. net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerItemPickupEvent(entityIn, this); Asking of pure curiosity.
  9. Just add some distance to x/y/z spawn position of your "bullet" in player "facing" vactor. Best would be placing second (in tick) bullet between two others (previous and next). Previous bullet (if exist) x/y/z Pos - (minus) x/y/z Pos of Next bullet will give you x/y/z distances between next/previous. Divide that by 2 and add to position (fixed) of middle bullet. EDIT Or above, both methods are "good", depending on situation - above (diesieben) might be better.
  10. I don't have exact answer, but two hints/ideas. You could look into multiverse or multiworld repo for help. You could track down vanilla unloading code. If I were you I would start from world unload event.
  11. Okay, you are missing the point of using Containers. If you want simple Gui, you should use GuiScreen and open it on client side ONLY. that means on server you will return null. If you want to have slots you use Container for server and GuiContainer for client. Using Container and GuiContainer and not having slots is totally pointless. EDIT In case of GuiScreen exchange of data happens via packets sent from button-clicks.
  12. With custom sword: public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) { if (attacker instanceof EntityPlayer) if (sprinting - post above) target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 1.0F); stack.damageItem(1, attacker); // this or super.hitEntity is NEEDED, otherwise sword will not lose durability. return true; } For vanilla LivingAttackEvent (strongly prefered) or LivingHurtEvent if you want to apply damage after hit. Disclaimer - I have no idea how #causePlayerDamage actually works, just noticed method in eclipse. There are several others if you want to know and also you can define your own (simply make new DamageSource).
  13. I am kinda lost, why are youu returning FCGuiContainer in both client and server? What's up with those namings anyway? In both server and client you are using FCGuidePage"X" which extends GuiContainer which is NOT Container and is actually only for client (it's GUI). As to you "explanation" - your code will probably crash at some point. Container is for SERVER GuiContainer is for CLIENT You can make gui that is only client-side - then you return gui for client and null for server. You can't really (pointless) do other way around.
  14. We're not here to code it for you. Read what forum description says. It's forum that will provide help woth forge (which I did), not Java directly. My best advice (many will agree) - learn Java (actually take some course). If you post what you've tried I could go from there and provide more explanations. What to look for (google) - How to spawn Entity in world. - How is lightning spawned (I'd look in vanilla code) Rest is REALLY SIMPLE - you just need to know minimum of Java.
  15. What? No... You don't need events for that. Events are to edit vanilla/other mod's behaviour. In your sword class override #hitEntity, get target's position, spawn new lightning entity in given position. Pretty much what above is said.
  16. http://minecraft.gamepedia.com/Frame_rate#Render_distance You do realize that is ridiculus range right? ~3200 blocks square terrain.
  17. Render.class is always the same. What is not same is the entity it renders. Arrow doesn't have a model, why would it. It's just one texture rendered twice (rotated) in X diagonal. Note: Start using Java Naming Convention - I am sure that most of modders on this forum don't really like your coding style. Your entity bullet has speed (motion or whatever) fields. Inside your Render class you can get those fields and check if they are == 0. If they are, it means that bullet has stopped (obviously), so you can start rendering the mark it left. Using rayTrace (client side), you can get the side of block your bullet hit. It's a big benefit here, that the minecraft is square world. When you have that side you can rotate your entity bullet to fit the side and render your square onto block, it will fit perfectly. As to model - yes, you can make your bullet and/or mark models. Load them using BaseModel and simply render them (look vanilla). And yes - you need to understand AT LEAST very basics of GL. Study vanilla code. If you'd want to render bullet like arrow (not 3d object, but 2 textures in X, as said before) you will need to learn tesselator. http://greyminecraftcoder.blogspot.com.au/2013/08/the-tessellator.html
  18. You can't retrieve anything from ItemStack that is stored inside picked up EntityItem. Only thing that is "actually" there is the Item (instance). I tried to learn how and why it is that way. First I though it was something with DataWatchers (which are there), but then, there is this forge code: public void onCollideWithPlayer(EntityPlayer entityIn) { if (!this.worldObj.isRemote) { if (this.delayBeforeCanPickup > 0) return; ItemStack itemstack = this.getEntityItem(); int i = itemstack.stackSize; int hook = net.minecraftforge.event.ForgeEventFactory.onItemPickup(this, entityIn, itemstack); Which as you can see directly uses stackSize. It either means that forge/vanilla is actually always getting stackSize=1 (which you get every damn time you'd try to get inside event itself) or that it is handled elsewhere (my guess it is). I wasn't curious enough to look deeper, I don't need it. And yes, I am taunting someone to explain. Link: (the "PROBLEM") http://www.minecraftforge.net/forum/index.php/topic,29752.msg154028.html#msg154028 EDIT Btw. I know that there are 2 events for picking up, even if one of them actually gives proper ItemStack (which I didn't check, but doubt it does), I still want to know why this one is giving output as it is.
  19. You are not checking if ItemStack is null. You are checking if Item is null which won't do anything, Item will never be null. Also - use else if - will save you a lot of other ifs.
  20. Were you updating workspace, like just now?
  21. @Override is just annotation, it doesn't do anything besides making sure you actually made override. (When you apply @Override and you make mistake, IDE will tell you that). As to problems - When you don't know what to do and think (I think) it shouldn't be like it, update to latest 1.7.10 (re-set up workspace, make test item, see if it's still called twice). It might be some mistake in code, for one I know - in 1.8 it's called once for each side. Note that it is still NOT the problem. Even if onCrafting is called twice the NBT still works (as you can see in prints). Is there still some problem?
  22. First of all you should read about http://minecraft.gamepedia.com/Spawn Unless you don't want your mobs to despawn ever you should consider Despawns. It'd be pointless to make links between entities. I'd rather go with WorldSaveData and hold big pool of everything your "army" collects there. WSD is saved into world (per world). Same as entities, in case of taleportig entity into other dimension it will start using other pool (from that world obviously). You should know that you can't (shouldn't) load entities in chunks that are not loaded. Loading chunks that are not needed for server to work will cause massive lags on big maps considering your entity will be present in many places (again - read about Spawning on wiki). To get entities in world you can simply get entityList (from world) and check instanceof, or hold your own (weak?) list in WorldSaveData that will be filled on entity spawn. Ye, as to rest - you need to code your AI that will actually use that data, nothing to tell you here since idk what you want.
  23. [03:41:05] [Client thread/INFO] [sTDOUT]: [x:onBlockDestroyed:57]: 1xitem.sword_fuck@0 [03:41:05] [Client thread/INFO] [sTDOUT]: [x:onBlockDestroyed:58]: {MiningSize:"3x3",} [03:41:06] [server thread/INFO] [sTDOUT]: [x:onBlockDestroyed:57]: 1xitem.sword_fuck@0 [03:41:06] [server thread/INFO] [sTDOUT]: [x:onBlockDestroyed:58]: {MiningSize:"3x3",} @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn) { System.out.println(stack); System.out.println(stack.getTagCompound()); return false; } Yes, I did. Your problem is in code, not NBT (most likely). I'll have a look. EDIT No, it's not possible, it is called only once on server, end of story. Click on that method, see callbacks -you MUST be doing something wrong :C EDIT 2 I am out for next ~8h, learn to debug your code, put Syso(nbt) EVERYWHERE. Don't do redirections like this: (what's the point, you are using it once). NBTTagCompound cmp = hammer.stackTagCompound; cmp.getString("MiningSize"); Other than that - I have no idea
  24. This gave me chuckle so I actually coded this shit on my own. public void onCreated(ItemStack stack, World world, EntityPlayer player) { if(!world.isRemote) { System.out.println("THE STACK: " + stack); NBTTagCompound cmp = stack.getTagCompound(); System.out.println("THE TAG: " + cmp); if(cmp == null) { System.out.println("NEW TAG"); cmp = new NBTTagCompound(); cmp.setString("MiningSize", "3x3"); stack.setTagCompound(cmp); } System.out.println(cmp); System.out.println(stack.getTagCompound()); } } Output: [03:08:47] [server thread/INFO] [sTDOUT]: [x:onCreated:30]: THE STACK: 1xitem.sword_fuck@0 [03:08:47] [server thread/INFO] [sTDOUT]: [x:onCreated:34]: THE TAG: null [03:08:47] [server thread/INFO] [sTDOUT]: [x:onCreated:38]: NEW TAG [03:08:47] [server thread/INFO] [sTDOUT]: [x:onCreated:46]: {MiningSize:"3x3",} [03:08:47] [server thread/INFO] [sTDOUT]: [x:onCreated:47]: {MiningSize:"3x3",} Those getters/setters are just wrappers from 1.8 update. public NBTTagCompound getTagCompound() { return this.stackTagCompound; } public void setTagCompound(NBTTagCompound nbt) { this.stackTagCompound = nbt; } EDIT I added print on stack's nbt just to show that it actually works.
  25. I don't really know next shit about 1.8 BlockStates (not yet in topic with my progress), but what I know is that block's meta is 4 bytes. 4 bytes is 16 variants (as it always was), please do tell - did BlockStates suddenly allowed users to have more variants? PS - yes, this might be offtopic (additional question). Well, seeing what I see in vanilla .json-s, you can actually have more than 16 variants, could someone post explanation how is it saved in world? I just don't get how they save so much data in so little space. EDIT (to post below) Ah, yes, obviously. Should have thought about it before asking
×
×
  • Create New...

Important Information

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