fuzzybat23
Members-
Posts
131 -
Joined
-
Last visited
Everything posted by fuzzybat23
-
This only pulls the total number of villagers, adult and child combined. WorldServer worldServer = DimensionManager.getWorld(player.dimension); Village village = worldServer.getVillageCollection().getNearestVillage(player.getPosition(), 5000); int numVillagers = village.getNumVillagers(); Is there a way to split this into the number of adult villagers and the number of child villagers?
-
Right now, I'm trying to get at least the position of the nearest village, say within a radius of x, which at the moment is 10,000. I scraped this together, but it's firing a null exception when trying to populate my village variable. Any pointers? package com.fuzzybat23; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.village.Village; import net.minecraft.village.VillageCollection; import net.minecraft.world.WorldServer; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.ModMetadata; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @net.minecraftforge.fml.common.Mod(modid = "villageinfo", version = "1.0", clientSideOnly = true, acceptedMinecraftVersions = "[1.12, 1.13]") public class VillageInfo { @net.minecraftforge.fml.common.Mod.Instance("VillageInfo") public static final String MODID = "villageinfo"; @Mod.Instance public static VillageInfo instance; public static final Logger logger = LogManager.getLogger(); @Mod.EventHandler @SideOnly(Side.CLIENT) public void preInit(FMLPreInitializationEvent event) { ModMetadata data = event.getModMetadata(); data.autogenerated = false; data.version = "1.0"; data.name = "Village Info"; data.description = "Displays nearby village info."; data.authorList.add("Fuzzybat23"); data.url = "https://minecraft.curseforge.com/members/fuzzybat23/projects"; data.credits = "Bats everywhere."; data.logoFile = "assets/logo/logo.png"; FMLCommonHandler.instance().bus().register(instance); MinecraftForge.EVENT_BUS.register(instance); } @SubscribeEvent public void onRenderTextOverlay(RenderGameOverlayEvent.Text event) { Minecraft mc = Minecraft.getMinecraft(); EntityPlayer player = mc.player; if(mc.gameSettings.showDebugInfo) getVillageData(event, player); } private void getVillageData(RenderGameOverlayEvent.Text event, EntityPlayer player) { if(player == null) return; WorldServer worldServer = DimensionManager.getWorld(player.dimension); VillageCollection villageCollection = null; Village village = villageCollection.getNearestVillage(player.getPosition(),10000); event.getLeft().add("Test1: " + worldServer.toString()); if(village != null) event.getLeft().add("Test2: " + village.toString()); } }
-
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
I was rooting around through BlockDoor.java looking for something unrelated and I saw a few snippets that sparked inspiration. Ran and tested this and it seems to work just fine public static boolean isDoubleDoor(World world, BlockPos pos, EnumFacing offsetPos) { String RIGHT = "RIGHT"; String LEFT = "LEFT"; boolean flag = false; IBlockState targetState = world.getBlockState(pos); Block targetBlock = targetState.getBlock(); IBlockState offsetState = world.getBlockState(pos.offset(offsetPos)); Block offsetBlock = offsetState.getBlock(); //Get correct blockState, including hinge, for targeted door. if(targetState.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER) if(targetState.getBlock() == targetBlock) targetState = world.getBlockState(pos.up()); BlockDoor.EnumHingePosition targetHinge = targetState.getValue(BlockDoor.HINGE); //get correct blockState, including hinge, for offset door. if(offsetState.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER) if(offsetState.getBlock() == offsetBlock) offsetState = world.getBlockState(pos.offset(offsetPos).up()); BlockDoor.EnumHingePosition offsetHinge = offsetState.getValue(BlockDoor.HINGE); logger.info("(targetHinge)(name)" + targetHinge.name() + "=? (offsetHinge)(name)" + offsetHinge.name() ); if(((targetHinge.name() == RIGHT) && (offsetHinge.name() == LEFT)) || ((targetHinge.name() == LEFT) && (offsetHinge.name() == RIGHT))) flag = true; return flag; } First checks if it's the lower half of the door and if so, resets the blockState to the upper half. Then it grabs the side of the door the hinge is on and checks if hinges on the two doors are on the opposite outer sides. -
I forgot to add @net.minecraftforge.fml.common.Mod just before the public class HorseInfo Anyway, it does seem to work.
-
Or I could be an idiot and realize it isn't even loading the mod when I run the client in IntelliJ..
-
I added that just after where I declared my mc and player variables, just before entering the first if statement. Nothing happened still. It's like it isn't even subscribing to the RenderGameOverlayEvent.Text properly.
-
I added some logger bits to help debug. It doesn't seem to be registering when it enters the debug screen. The horse stuff might actually work, but it doesn't seem to be even getting that far. It should be listening for the RenderGameOverlayEvent, when text is drawn on the screen, and check if it's the debug info being shown. @SideOnly(Side.CLIENT) @SubscribeEvent public void onLookHorse(RenderGameOverlayEvent.Text event) { Minecraft mc = Minecraft.getMinecraft(); EntityPlayer player = Minecraft.getMinecraft().player; if(mc.gameSettings.showDebugInfo) { logger.info("Debug screen successfully entered.."); if(mc.objectMouseOver != null && mc.objectMouseOver.entityHit instanceof EntityHorse ) { logger.info("objectMouseOver is a horse.."); getHorseInfo(event, player, (EntityHorse)mc.objectMouseOver.entityHit); } } }
-
Nope, not at all -.-
-
Basically, I'm trying to determine if the entity the player is currently looking at is a horse. Does this sound about right? @SubscribeEvent public void isHorse(RenderGameOverlayEvent.Text event) { Minecraft mc = Minecraft.getMinecraft(); If(mc.gameSettings.showDebugInfo) if(mc.objectMouseOver != null && mc.objectMouseOver.entityHit instanceof EntityHorse) { //Do stuff if it's a horse } }
-
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
Oh crap, that code is from a bukkit plugin x.x I just decompiled it again and checked the imports. Dunno how I missed that before -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
You said that the hinge is on the top half of the door, and the hinge side is used to determine if the doors face each other, right? I found this in an older mod, but I'm not sure what the updated code would look like. I know that this is definitely outdated, though, but from what I can tell it did exactly that. Determined if it was the upper or lower part of the door being interacted with and set a door variable to the top portion. Block blockBottom = block.getRelative(BlockFace.DOWN); Block blockTop = block.getRelative(BlockFace.UP); Block blockNearBottom = blockBottom.getRelative(BlockFace.NORTH); Block blockNearTop = blockTop.getRelative(BlockFace.NORTH); Door door = (Door)block.getState().getData(); Door doorTop = (Door)block.getState().getData(); Door doorBottom = (Door)block.getState().getData(); Door doorNearBottom = (Door)block.getState().getData(); Door doorNearTop = (Door)block.getState().getData(); if (door.isTopHalf()) { blockTop = block; doorTop = door; doorBottom = (Door)blockBottom.getState().getData(); } else { blockBottom = block; doorBottom = door; doorTop = (Door)blockTop.getState().getData(); } I don't think getRelative exists anymore, and Door isn't a type anymore, it's now BlockDoor. -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
Also, does this look about right as far as looping through the enumfacing? Passing in the right click event to generate the new target block, using offset(facing) to offset targetblock from block. public void checkForDoors(PlayerInteractEvent.RightClickBlock event, Block block) { for(EnumFacing facing : EnumFacing.HORIZONTALS) { Block targetblock = event.getWorld().getBlockState(event.getPos().offset(facing)).getBlock(); if(targetblock == block) //Do stuff if block that is offset to original block is same as original block } } -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
Mmmm, so instead of this: public static boolean isWoodenDoor(Block block) { if(block == Blocks.ACACIA_DOOR || block == Blocks.BIRCH_DOOR || block == Blocks.DARK_OAK_DOOR || block == Blocks.JUNGLE_DOOR || block == Blocks.OAK_DOOR || block == Blocks.SPRUCE_DOOR) return true; return false; } Use something like this? public static boolean isWoodenDoor(IBlockState state) { if(state.getBlock() instanceof BlockDoor && state.getMaterial() == Material.WOOD) return true; return false; } -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
Second phase of what I'm doing is determining if an adjacent block contains a door. In other words, two doors side by side. Then figure out if those doors are mirror to each other, and when one of the two is right clicked, it will send a door toggle to the other opening it automatically. Say you're standing in the world facing north and you place a door in front of you. It's hinges are facing east. You place a door next to it one block to the west. It's hinges are facing west. You have a set of proper double doors now. -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
See, when people say use an instance of BlockDoor, that just confuses the hell out of me -.- I live in a world of examples. Unless an example is given, then something like what you said is completely lost to me Anyway, for what i'm working on, the first step was being able to identify the block being interacted with, in this case by right click, as a door. Not just as a door, but as a wooden door. Since iron doors fall into the category of BlockDoor, I just can't run a generic test to say "Is it a door? Yup." No, it has to be "Is it an Acacia door, a jungle door, a dark oak door, a birch door, an oak door or a spruce door? Yes." A few versions ago, pre 1.9 I think, all you had to check was wooden_door, but now wooden_door only pertains to oak doors, where they should have given oak doors their own name in code and kept wooden_doors as a check for all wood type doors. -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
And yes, event.getWorld().getBlockState(event.getPos()).getBlock() does seem to work a little better as far as getting the block being right clicked. Cleans up my code by five lines at least xD -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
That's wrong. This is the code directly from PlayerInteractEvent.java /** * @return The hit vector of this click */ public Vec3d getHitVec() { return hitVec; } Unless I'm wrong, a hit vector is the X Y Z coordinates of a hit, right? -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
I know almost noth9ing about gethitvec, but based on those different xyz values, the torch will of course be on whole numbers. 7, 84 and 19. The gethitvec is probably returning the exact area within the bounding box that you clicked on, which can't possibly be whole numbers? -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
I think I figured this one out. I ended up using this code and tested it and it worked just fine, letting me know if what I clicked on was a door and if it wasn't. I've even gotten it to distinguish between the different kinds of doors. @SubscribeEvent public void onBlockInteract(PlayerInteractEvent.RightClickBlock event) { Minecraft mc = Minecraft.getMinecraft(); EntityPlayer player = event.getEntityPlayer(); BlockPos pos = mc.objectMouseOver.getBlockPos(); Block block = player.getEntityWorld().getBlockState(pos).getBlock(); IBlockState state = player.getEntityWorld().getBlockState(pos); logger.info("Begin check if it's a door..."); if( isWoodenDoor(block)) logger.info("It's a door!" + WoodenDoor.whichDoor(block)); } public static boolean isWoodenDoor(Block block) { if(block == Blocks.ACACIA_DOOR || block == Blocks.BIRCH_DOOR || block == Blocks.DARK_OAK_DOOR || block == Blocks.JUNGLE_DOOR || block == Blocks.OAK_DOOR || block == Blocks.SPRUCE_DOOR) return true; return false; } public static BlockDoor whichDoor(Block block) { if(block == Blocks.ACACIA_DOOR) return Blocks.ACACIA_DOOR; if(block == Blocks.BIRCH_DOOR) return Blocks.BIRCH_DOOR; if(block == Blocks.DARK_OAK_DOOR) return Blocks.DARK_OAK_DOOR; if(block == Blocks.JUNGLE_DOOR) return Blocks.JUNGLE_DOOR; if(block == Blocks.OAK_DOOR) return Blocks.OAK_DOOR; if(block == Blocks.SPRUCE_DOOR) return Blocks.SPRUCE_DOOR; return null; } -
So.. I know how to get the block info for a block I'm currently looking at, or interacting with. Let's use right clicking, for this example. @SubscribeEvent public void onBlockInteract(PlayerInteractEvent.RightClickBlock event) { Minecraft mc = Minecraft.getMinecraft(); EntityPlayer player = event.getEntityPlayer(); BlockPos pos = mc.objectMouseOver.getBlockPos(); Block block = player.getEntityWorld().getBlockState(pos).getBlock(); //Based on pos, block is the block the player is targeting IBlockState state = player.getEntityWorld().getBlockState(pos); } Now what I'd like to know is, how do you get Block adjacent to the one being right clicked? Let's say.. the block north, south, east or west of the target block.
-
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
@SubscribeEvent public void onDoorInteract(PlayerInteractEvent.RightClickBlock event) { EntityPlayer player = event.getEntityPlayer(); BlockPos blockpos = event.getPos().offset(event.getFace()); Block block = player.getEntityWorld().getBlockState(blockpos).getBlock(); logger.info("Begin check if it's a door..."); if( isWoodenDoor(block)) logger.info("It's a door!"); } public static boolean isWoodenDoor(Block block) { if(block == Blocks.ACACIA_DOOR || block == Blocks.DARK_OAK_DOOR || block == Blocks.BIRCH_DOOR || block == Blocks.JUNGLE_DOOR || block == Blocks.OAK_DOOR || block == Blocks.SPRUCE_DOOR) return true; return false; } -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
Ok.. I managed to find something about PlayerInteractEvent.RightClickBlock after lots of google digging I did managed to get it to register when I right click, but it doesn't seem to want to correctly check if it's a door or not, now. -
Is the block under the cross hairs a door?
fuzzybat23 replied to fuzzybat23's topic in Modder Support
Probably because I didn't know about the RIGHTCLICKBLOCK event -
I found some old code for detecting if the block you're looking at is a door: public boolean isDoor(PlayerInteractEvent event) { BlockDoor door = (BlockDoor)Blocks.wooden_door; BlockLocation loc = BlockLocation.get(event.world, event.x, event.y, event.z); if((event.action == Action.RIGHT_CLICK_BLOCK) && (loc.getBlock() == door)) return true; } Of course this is out dated as BlockLocation is no longer used. That and Blocks.wooden_door doesn't exist anymore either. For an updated version of this, does this look about right? public void onDoorInteract(PlayerInteractEvent event) { Minecraft mc = Minecraft.getMinecraft(); BlockPos blockpos = mc.objectMouseOver.getBlockPos(); Block block = event.getEntityPlayer().getEntityWorld().getBlockState(blockpos).getBlock(); //call return if block isn't a door if((event.action != Action.RIGHT_CLICK_BLOCK) || !(WoodenDoor(block))) return; //Do stuff if it is a door } public boolean WoodenDoor(Block block) { BlockDoor[] doors = {(BlockDoor) Blocks.ACACIA_DOOR, (BlockDoor) Blocks.BIRCH_DOOR, (BlockDoor) Blocks.DARK_OAK_DOOR, (BlockDoor) Blocks.JUNGLE_DOOR, (BlockDoor) Blocks.OAK_DOOR, (BlockDoor) Blocks.SPRUCE_DOOR}; for(BlockDoor door : doors) { if(block == door) return true; } return false; } Also, event.action != Action.RIGHT_CLICK_BLOCK doesn't seem to exist since 1.8, either. Does anyone know how to do this in the current 1.12 environment?