Jump to content

TheiTay

Members
  • Posts

    22
  • Joined

  • Last visited

Everything posted by TheiTay

  1. Hello, this is the code that I currently have - but the harvestBlock function is not what I'm looking for. I need a function that would show the crack animation and break the block after the time it should take to mine it... @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { //this condition is here in order to avoid this code running twice for each tick if (event.phase == TickEvent.Phase.END) return; EntityPlayer player = event.player; Minecraft mc = Minecraft.getMinecraft(); World world = mc.getIntegratedServer().worldServerForDimension(player.dimension); Vec3 blockLocation = Vec3.createVectorHelper(403, 35, 250); Block block = world.getBlock((int)blockLocation.xCoord, (int)blockLocation.yCoord, (int)blockLocation.zCoord); if (!world.isRemote){ block.harvestBlock(world, player, (int)blockLocation.xCoord, (int)blockLocation.yCoord, (int)blockLocation.zCoord, 0); } }
  2. I made the mod as a client-side bot.
  3. Hello, I'm working on Path-finding algorithm, also I have a class that makes the player go through the path that he found. I want to programmally make the interaction between the player and a block, when you try to harvest a block it takes time (depends on block and weapon) and while you try to break it you can see crack animation, this is what I'm looking for. I want to call a function the does this interaction, I tried to use "harvestBlock" but it only harvests it without applying the animation and calculating how much time it supposed to take. Any ideas how to it? Thanks in advance.
  4. Hey, for the first answer, can you explain how? I thought that when I use event.player it would run on server. I know that currentItem is the slot, but I want to set it to itemStack field, and I don't know its slot. Thank you for the answer
  5. I'm currently working on pathfinding algorithm mod, when i decrease the inventory like this: @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { InventoryPlayer inventory = event.player.inventory; ItemStack itemStack = null; for (ItemStack stack : inventory.mainInventory){ if (stack != null && stack.getItem() != null && stack.getItem() instanceof ItemBlock){ itemStack = stack; event.player.setItemInUse(stack, stack.getItem().getMaxItemUseDuration(stack)); } } ItemBlock blockItem = (ItemBlock)itemStack.getItem(); inventory.consumeInventoryItem(blockItem); inventory.markDirty(); event.player.inventoryContainer.detectAndSendChanges(); } The stack size is decreasing, but only locally - because next time I mine the same type of block the number is jumping back to its value before the decreasing. Another question is how do I change to held item to the block that I'm using? I found the property: inventory.currentItem (int) but I don't know how to get in which slot my itemstack is... Thanks in advance.
  6. thank you, would it work with Material.Lava too? and would it do any difference between water and flowing water? Thanks!
  7. Hello, I am currently developing a Path-finding mod for 1.7.10. I have a function that tells me what is the block type and it works like that: private static BlockType getBlockType(int[] blockLocation) { return theWorld.getBlock( blockLocation[Coords.X.ordinal()], blockLocation[Coords.Y.ordinal()], blockLocation[Coords.Z.ordinal()]).getBlockHardness(theWorld, blockLocation[Coords.X.ordinal()], blockLocation[Coords.Y.ordinal()], blockLocation[Coords.Z.ordinal()]) >= 0.01f ? BlockType.SOLID : BlockType.NON_SOLID; } The reason I used this method instead of using method such as isBlockNormalCubeDefault is because it identified some blocks (such as leaves) as non-solid. Anyway, I want to check if a block has type of liquids in it, water/lava. it doesn't matter which or whether it's flowing or not, but I must know that it has liquids in it. Any suggestions how? Thanks in advance.
  8. My mistake. The method is from a class named "PathNavigator" which navigate the player through a steps-list that it receives. (It's a path finder mod) @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { if (!run) return; if (null == currentStep && steps.isEmpty()){ run = false; return; } if (null == currentStep){ currentStep = steps.poll(); targetVec = currentStep.getLocation(); isJumpedFlag = false; } EntityPlayer player = Minecraft.getMinecraft().thePlayer; //integer positions are the corner of the block - in order to get to the center we add 0.5 Vec3 direction = Vec3.createVectorHelper(targetVec.xCoord + 0.5 - player.posX, targetVec.yCoord - player.posY + PLAYER_HEIGHT, targetVec.zCoord + 0.5 - player.posZ); //System.out.println((targetVec.xCoord - player.posX) + ", " + (targetVec.yCoord - player.posY) + ", " + (targetVec.zCoord - player.posZ)); direction.yCoord = 0; // if (direction.lengthVector() <= MINIMAL_DISTANCE){ if(direction.dotProduct(Vec3.createVectorHelper(player.motionX, 0, player.motionZ)) < 0 && Step.StepType.Pole != currentStep.getType()) { currentStep = steps.poll(); if(null != currentStep) targetVec = currentStep.getLocation(); //System.out.println((targetVec.xCoord - player.posX) + ", " + (targetVec.yCoord - player.posY) + ", " + (targetVec.zCoord - player.posZ)); isJumpedFlag = false; player.setVelocity(0, 0, 0); return; } else if (Step.StepType.Pole == currentStep.getType()){ if (player.motionY <= 0.01){ if (pollFlag == 0) player.jump(); pollFlag++; } if(pollFlag == 2) { Minecraft mc = Minecraft.getMinecraft(); World world = mc.getIntegratedServer().worldServerForDimension(mc.thePlayer.dimension); ItemStack itemStack = player.getHeldItem(); player.rotationPitch = 180; player.swingItem(); int x = (int)Math.floor(player.posX); int y = (int)Math.floor(player.posY); int z = (int)Math.floor(player.posZ); ItemBlock blockItem = (ItemBlock)player.getHeldItem().getItem(); Block block = blockItem.field_150939_a; world.playSoundEffect(x, y, z, block.stepSound.getBreakSound(), 1.0F, world.rand.nextFloat() * 0.1F + 0.9F); blockItem.placeBlockAt(itemStack, player, world, x, y - 2, z, EnumFacing.UP.ordinal(), 0, 0, 0, player.getHeldItem().getItemDamage());//world.getBlockMetadata(x+1, y-2, z) player.getHeldItem().splitStack(1); pollFlag++; } if (pollFlag >= 3 && player.onGround){ pollFlag = 0; player.rotationPitch = 0; currentStep = steps.poll(); } return; } and this is the whole class, if required package com.custommods.walkmod; import java.util.Queue; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.Vec3; import net.minecraft.world.World; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; public class PathNavigator { private static PathNavigator pathNavigator; private final double NORMAL_SPEED_SIZE = 0.21585; private final double WATER_SPEED_SIZE = NORMAL_SPEED_SIZE / 5; private final double PLAYER_HEIGHT = 1.62; private final double MINIMAL_DISTANCE = 0.15; private final double TURNING_DISTANCE = 1; private Queue<Step> steps; private Step currentStep; private boolean run = false; private boolean isJumpedFlag = false; private Vec3 targetVec = null; private int pollFlag = 0; public static PathNavigator getPathNavigator(){ if (pathNavigator == null) pathNavigator = new PathNavigator(); return pathNavigator; } private PathNavigator(){ this.steps = null; this.currentStep = null; } @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { if (!run) return; if (null == currentStep && steps.isEmpty()){ run = false; return; } if (null == currentStep){ currentStep = steps.poll(); targetVec = currentStep.getLocation(); isJumpedFlag = false; } EntityPlayer player = Minecraft.getMinecraft().thePlayer; //integer positions are the corner of the block - in order to get to the center we add 0.5 Vec3 direction = Vec3.createVectorHelper(targetVec.xCoord + 0.5 - player.posX, targetVec.yCoord - player.posY + PLAYER_HEIGHT, targetVec.zCoord + 0.5 - player.posZ); //System.out.println((targetVec.xCoord - player.posX) + ", " + (targetVec.yCoord - player.posY) + ", " + (targetVec.zCoord - player.posZ)); direction.yCoord = 0; // Vec3 delta = null; // Step nextStep = steps.peek(); // if(nextStep != null) { // Vec3 deltaBeforeNorm = nextStep.getLocation().subtract(targetVec); // delta = deltaBeforeNorm.normalize(); // if(Vec3.createVectorHelper( // TARGET_ADVANCE_SPEED*delta.xCoord, // TARGET_ADVANCE_SPEED*delta.yCoord, // TARGET_ADVANCE_SPEED*delta.zCoord).lengthVector() > deltaBeforeNorm.lengthVector()) // delta = null; // } // if (direction.lengthVector() <= MINIMAL_DISTANCE){ if(direction.dotProduct(Vec3.createVectorHelper(player.motionX, 0, player.motionZ)) < 0 && Step.StepType.Pole != currentStep.getType()) { currentStep = steps.poll(); if(null != currentStep) targetVec = currentStep.getLocation(); //System.out.println((targetVec.xCoord - player.posX) + ", " + (targetVec.yCoord - player.posY) + ", " + (targetVec.zCoord - player.posZ)); isJumpedFlag = false; player.setVelocity(0, 0, 0); return; } else if (Step.StepType.Pole == currentStep.getType()){ if (player.motionY <= 0.01){ if (pollFlag == 0) player.jump(); pollFlag++; } if(pollFlag == 2) { Minecraft mc = Minecraft.getMinecraft(); World world = mc.getIntegratedServer().worldServerForDimension(mc.thePlayer.dimension); ItemStack itemStack = player.getHeldItem(); player.rotationPitch = 180; player.swingItem(); int x = (int)Math.floor(player.posX); int y = (int)Math.floor(player.posY); int z = (int)Math.floor(player.posZ); ItemBlock blockItem = (ItemBlock)player.getHeldItem().getItem(); Block block = blockItem.field_150939_a; world.playSoundEffect(x, y, z, block.stepSound.getBreakSound(), 1.0F, world.rand.nextFloat() * 0.1F + 0.9F); blockItem.placeBlockAt(itemStack, player, world, x, y - 2, z, EnumFacing.UP.ordinal(), 0, 0, 0, player.getHeldItem().getItemDamage());//world.getBlockMetadata(x+1, y-2, z) player.getHeldItem().splitStack(1); pollFlag++; } if (pollFlag >= 3 && player.onGround){ pollFlag = 0; player.rotationPitch = 0; currentStep = steps.poll(); } return; } // else if (direction.lengthVector() < TURNING_DISTANCE) { // if(delta != null) { // targetVec = targetVec.addVector( // TARGET_ADVANCE_SPEED*delta.xCoord, // TARGET_ADVANCE_SPEED*delta.yCoord, // TARGET_ADVANCE_SPEED*delta.zCoord); // } // } //Since we set yCoord to 0, it checks only if the length in x and z is samller than MINIMAL_DISTANCE, // to make sure that the player won't "shake" during the fall direction = direction.normalize(); double multiplyFactor = (player.isInWater()) ? WATER_SPEED_SIZE : NORMAL_SPEED_SIZE; direction = Vec3.createVectorHelper( direction.xCoord*multiplyFactor, direction.yCoord*multiplyFactor, direction.zCoord*multiplyFactor); player.setVelocity(direction.xCoord, player.motionY, direction.zCoord); player.rotationYaw = -(float)(Math.atan2(player.motionX, player.motionZ) * 360 / 2/ Math.PI); if(!isJumpedFlag && Step.StepType.Jump == currentStep.getType() && (player.onGround || player.isInWater())){ player.jump(); isJumpedFlag = true; } } public void run(){ run = true; } public void pause(){ run = false; } public void stop(){ steps = null; } public void setStepsQueue(Queue<Step> steps){ this.steps = steps; } } Thanks
  9. Thank you for the reply. Since I don't use my mod in multiplayer and getting the world like this didn't do the work (it did the exact same issue that I had before): player = Minecraft.getMinecraft().thePlayer; World world = player.worldObj; I tried a solution that I found in the forum, which preformed well, why do you suggest to not use it that way?
  10. Thank you, using this code: Minecraft mc = Minecraft.getMinecraft(); World world = mc.getIntegratedServer().worldServerForDimension(mc.thePlayer.dimension); solved my issue.
  11. Thanks for the quick reply, but what world would you suggest I use? Thanks in advance..!
  12. Hey, I succeeded to place a block using this code: ItemStack itemStack = player.getHeldItem(); player.rotationPitch = 180; player.swingItem(); int x = (int)player.posX; int y = (int)player.posY; int z = (int)player.posZ; ItemBlock block = (ItemBlock)itemStack.getItem(); World world = Minecraft.getMinecraft().theWorld; block.placeBlockAt(itemStack, player, world, x, y - 2, z -1, EnumFacing.UP.ordinal(), 0, 0, 0, player.getHeldItem().getItemDamage());//world.getBlockMetadata(x+1, y-2, z) player.getHeldItem().splitStack(1); but the change doesn't affect the block that item that will fall when this block would be broken. in fact - if I'll reload the world it'll change back to the thing it was in the beggining. here's a video to explain:
  13. Hi, I tried to find something like "entitySwing" but I couldn't, are you sure that it exists in 1.7.10? I found a method of EntityPlayer "swingItem()" but it only swings the item and not actually doing the "right click action" (such as placing the block), I tried to use the function of ItemBlock "placeBlockAt" but it always returns false. I couldn't understand where do I get the metadata from. Is there any example of using this method or something similar that you can suggest? thanks.
  14. Hello, I am currently working on a pathfinding mod, which works fine for now, I want to add the modifying-the-world (mine/ build) functionality and I'm trying lately to find an easy way to place a block where I'm looking to, just like when you press right click regulary. Another issue that I'm working on lately is that my pathfinding algorithm doesn't know how to handle water properly, first - it still doesn't know that you have the ability to "swim" and it tries to find the path through the ground underwater, and second - the jump function that I use regularly (EntityPlayer.jump()) so my questions are, is there any way to identify "water surface" which you can swim of? I have a method that can find "standable blocks" but it can't find the difference between water and air. and could you suggest a function that could handle the "swim" action? Thank you.
  15. Hey. I'm making a mod that includes a pathfinding algorithm, the pathfinding works great, but - since I don't handle the view angle it stays in the same place, I tried to modify the look angle using this: player.rotationYaw = (float)(Math.atan2(direction.xCoord, direction.zCoord) * 360); player is the player, direction is a vec3 which I'm using to set velocity. I checked the result that I'm getting from the atan, most of them are below 1 but they are in range of -2~2 Any ideas? Thank you.
  16. the question is - how do walk stright in that direction and in contstant speed?, setVelocity with direction vector is giving me the walk to the requierd direction, but isn't giving me the constant speed. I tried to modify moveStrafing and moveForward as you said but nothing happend...
  17. Hello, thanks for the reply. I tried to use these properties but for some reason when I changed them I didn't see any difference.
  18. hello, I want to simulate key press on "w". I tried to use "setVelocity" but for some reason the entity stops a few seconds after, something like negative accelartion. I tried to loop the setVelocity but the result was inconstant speed. Any ideas?
  19. Thank you very much. The code that I came out with is: @Mod(modid = WalkMod.MODID, version = WalkMod.VERSION) public class WalkMod { public static final String MODID = "walkMod"; public static final String VERSION = "1.0"; EntityPlayer player; @EventHandler public void init(FMLInitializationEvent event) { player = Minecraft.getMinecraft().thePlayer; } public void movePlayerWhereHePointsTo(){ Vec3 lookVec = player.getLookVec(); player.moveEntity(lookVec.xCoord, lookVec.yCoord, lookVec.zCoord); } } My question is, what is the simplest way to trigger "movePlayerWhereHePointsTo" during the game? I tought about pressing a key as I said but it could be something different.
  20. Hello, I want to make a mod that when I press on a button my character moves automatically to the place that he's pointing to. For that I guess that I'll use the function getlookvec() to find the displacement vector between my place to the place the I'm pointing to, and then use moveEntity() with my vector to move the character to there. But before I do all of that I must find my entityPlayer, something that I couldn't find a way to do yet. Any ideas?
  21. Hello, my name is Itay. Sorry for my English My school project requires me to develop a minecraft mod. I didn't play minecraft a lot (I guess that total of 5-10 hours), I understand most of the physics and logics of the game but now I want to develop a mod to it My project is a bit complicated, but before I can jump into the deep water my teacher gave me a few tasks. I've seen that most of the tutorials are more about creating new items to the game, I need to do something different. I want to "find out" information about the world. For this type of mods I couldn't find any documentation... My first task was to find out about the block that I'm pointing to, by finding out I mean coordinates, and block type. If there is any tutorial that could help me in this task, I'll be glad to hear about it. Thanks.
×
×
  • Create New...

Important Information

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