Jump to content

brsseb

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by brsseb

  1. Thanks for the reply. Im using the "jar" gradle task from IntelliJ, which outputs a JAR file in the build directory. I was thinking that was the finished "product" that I could drop into any mod folder in my minecraft installation (with forge installed ofc. But I guess its not the case?
  2. So, Ive made a simple mod that basically listens for a BlockEvent.BreakEvent event, then figures out which direction the player is facing, and scans the next 30 blocks ahead for diamonds or any other valuable ore, and outputs the results in text format. It works fine when running it from IntelliJ and in a simple test world thatI have created, but when I build a JAR and put the JAR in my mod folder for my regular minecraft install (with the correct forgemod version installed of course), it causes all sorts of problems. First, when breaking a block, the block disappears, but its still there, as u are not able to move into it. Its like its invisible. And the text doesnt appear either. And after a while, minecraft crashes....any tips? Here is the code from my event handler private static final int RANGE = 30; private static Set<String> skipList = new HashSet<String>(); static { skipList.add("tile.stone"); skipList.add("tile.dirt"); skipList.add("tile.grass"); skipList.add("tile.tallgrass"); skipList.add("tile.log"); skipList.add("tile.leaves"); skipList.add("tile.vine"); } @SubscribeEvent public void sendMessage(BlockEvent.BreakEvent event) { EntityPlayer player = event.getPlayer(); World world = player.getEntityWorld(); BlockPos playerPos = player.getPosition(); int x = playerPos.getX(); int y = playerPos.getY(); int z = playerPos.getZ(); Map<String, Integer> blocksCount = new HashMap<String, Integer>(); // Figure out what direction the player is looking at Vec3d lookVec = player.getLookVec(); double lookX = lookVec.xCoord; double lookY = lookVec.yCoord; double lookZ = lookVec.zCoord; double factor = 0.8; if (Math.abs(lookX) > factor) { //showMessage(player, "Player is facing X (" + lookX+ ")"); if (lookX < 0.0f) { for (int i = 1; i <= RANGE; i++) { Block block = world.getBlockState(new BlockPos(x - i, y, z)).getBlock(); countBlock(block, blocksCount); } } else { for (int i = 1; i <= RANGE; i++) { Block block = world.getBlockState(new BlockPos(x + i, y, z)).getBlock(); countBlock(block, blocksCount); } } } else if (Math.abs(lookY) > factor) { //showMessage(player, "Player is facing Y (" + lookY+ ")"); if (lookY < 0.0f) { for (int i = 1; i <= RANGE; i++) { Block block = world.getBlockState(new BlockPos(x, y - i, z)).getBlock(); countBlock(block, blocksCount); } } else { for (int i = 1; i <= RANGE; i++) { Block block = world.getBlockState(new BlockPos(x, y + i, z)).getBlock(); countBlock(block, blocksCount); } } } else if (Math.abs(lookZ) > factor) { //showMessage(player, "Player is facing Z (" + lookZ+ ")"); if (lookZ < 0.0f) { for (int i = 1; i <= RANGE; i++) { Block block = world.getBlockState(new BlockPos(x, y, z - i)).getBlock(); countBlock(block, blocksCount); } } else { for (int i = 1; i <= RANGE; i++) { Block block = world.getBlockState(new BlockPos(x, y, z + i)).getBlock(); countBlock(block, blocksCount); } } } if (!blocksCount.isEmpty()){ showMessage(player, blocksCount.toString()); } event.setResult(Event.Result.ALLOW); } private void countBlock(Block block, Map<String, Integer> blocksCount) { String name = block.getUnlocalizedName(); if (skipList.contains(name)) { // We dont care about blocks on the skip list return; } if (blocksCount.containsKey(name)) { int curVal = blocksCount.get(name); blocksCount.put(name, ++curVal); } else { blocksCount.put(name, 1); } } private void showMessage(EntityPlayer player, String message) { TextComponentString textComponents = new TextComponentString(message); player.addChatMessage(textComponents); }
×
×
  • Create New...

Important Information

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