Jump to content

MSpace-Dev

Members
  • Posts

    180
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by MSpace-Dev

  1. Awesome, got it working fine now. Thank you. public static SoundEvent infused_log_ambient; private static final ResourceLocation infusedLogAmbientRL = new ResourceLocation(Reference.MODID, "blocks.infused_log_ambient"); @SubscribeEvent public static void registerSounds(RegistryEvent.Register<SoundEvent> event) { infused_log_ambient = new SoundEvent(infusedLogAmbientRL).setRegistryName(infusedLogAmbientRL); registerSound(infused_log_ambient, event); } private static void registerSound(SoundEvent soundID, RegistryEvent.Register<SoundEvent> event) { Utils.getLogger().info(soundID + " loaded"); event.getRegistry().register(soundID); }
  2. Hey everyone, Having trouble loading my custom sound using the playSound method in code. My sound loads completely fine when I use /playsound in-game, but as soon as the playSound method gets called, the game crashes. Really not sure why. I should have everything registered correctly, as the sound does actually play when using commands. Common Proxy: public class CommonProxy { @Mod.EventHandler public void preInit(FMLPreInitializationEvent event){ RegistryEventHandler.registerSounds(); } } Registry Event Handler: ( Courtesy of @Choonster TestMod3 code ) @Mod.EventBusSubscriber public class RegistryEventHandler { public static SoundEvent infused_log_ambient; public static void registerSounds() { infused_log_ambient = registerSound("infused_log_ambient"); } private static SoundEvent registerSound(String sound) { Utils.getLogger().info(sound + " loaded"); final ResourceLocation soundID = new ResourceLocation(Reference.MODID, sound); return GameRegistry.register(new SoundEvent(soundID).setRegistryName(soundID)); } } Play Sound called in this class: public class ItemSpiritBase extends ItemBase { public ItemSpiritBase(String name) { super(name); } protected void conversionDisplay(World world, BlockPos pos) { if(world.isRemote) { world.playSound(pos.getX(), pos.getY(), pos.getZ(), RegistryEventHandler.infused_log_ambient, SoundCategory.BLOCKS, 1.0f, 1.0f, false); } } } conversionDisplay() is called from here: @Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { Utils.getLogger().info("Used item!"); if(worldIn.getBlockState(pos) == Blocks.LOG.getDefaultState() || worldIn.getBlockState(pos) == Blocks.LOG2.getDefaultState()) { Utils.getLogger().info("Log test worked!"); conversionDisplay(worldIn, pos); worldIn.setBlockState(pos, ModBlocks.zombie_infused_log.getDefaultState()); } return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); } Sooo yeah, game crashes as soon as I R-click on the MC logs. Definitely because of the playSound() method. CRASH REPORT:
  3. Ah, @jabelar That makes a TON of sense. Thanks for the in-depth explanation there, really helps me understand what went wrong in the beginning. Also, the knowledge of those ItemStack methods will definitely help in the future, I'm sure! Also, I completely understand how trying to compare a new instance of an item stack would never work, and has also increased my understanding of the difference between '==' and .equals(). Super grateful!
  4. Could you tell me why comparing the two ItemStacks would fail though, compared to comparing two Items? (Again, fuzzy about the difference between the two)
  5. Ohhhh, haha. Thanks. Got it working now. (I thought the problem was that they were pointing at different locations in memory, or something like that, thus I needed to use .equals()) But yeah, still not the best. I think I should probably do more research on the difference between Items and ItemStacks are too. Still pretty fuzzy on what each's purpose is, and the difference between them.
  6. Haha, funny Well, did some research on the difference, and have an understanding now, between '==' VS '.equals()'. So, I've managed to get to this so far, still fails. New if statement: if(killerEntity instanceof EntityLivingBase) { EntityLivingBase killer = (EntityLivingBase) killerEntity; Utils.getLogger().info("Player is holding " + killer.getHeldItemMainhand()); Utils.getLogger().info("Player SHOULD BE holding " + (new ItemStack(ModItems.spirit_knife))); if (killer.getHeldItemMainhand().equals(new ItemStack(ModItems.spirit_knife))) { Utils.getLogger().info(killer + " has knife"); } } The above outputs this when I kill something: [21:38:05] [Server thread/INFO]: Player is holding 1xitem.spirit_knife@0 [21:38:05] [Server thread/INFO]: Player SHOULD BE holding 1xitem.spirit_knife@0 So, they're both the same. I'm using .equals(). Still not sure why it isn't working. (Still not outputting ' killer has knife ')
  7. Also, my IDE is telling me that will always return true. Is that correct?
  8. Hey everyone, I am trying to get the held item of a player when an entity dies, using the LivingDropsEvent. But the current code I have doesn't seem to work. My message never comes through, and I really have no idea why. I'm guessing I'm not checking the held item correctly, but not sure. public void interceptMobDeath(LivingDropsEvent event) { Entity killerEntity = event.getSource().getSourceOfDamage(); if(killerEntity instanceof EntityLivingBase) { EntityLivingBase killer = (EntityLivingBase) killerEntity; if(killer.getHeldItemMainhand() != null) { if (killer.getHeldItem(EnumHand.MAIN_HAND) == new ItemStack(ModItems.spirit_knife)) { Utils.getLogger().info(killer); } } } }
  9. Hey everyone, I want to make a custom tool that loses durability when either, right-clicking a specific block, or breaking any block. (I can do basic block checks here) The main thing I'm struggling with is actually removing durability from the tool, and registering it correctly. I currently have a tool that extends ItemTool and have registered it. Just having trouble setting and removing durability. (I know this is probably super wrong what I'm tying to do here) Bottom code crashes immediately when breaking a block, a null pointer on something called getStrVsBlock() . Item Carving Tool: public class ItemCarvingTool extends ItemToolBase { public ItemCarvingTool(String name, float attackDamageIn, float attackSpeedIn, ToolMaterial materialIn, Set<Block> effectiveBlocksIn) { super(name, attackDamageIn, attackSpeedIn, materialIn, effectiveBlocksIn); setMaxStackSize(1); setMaxDamage(15); } @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) { stack.setItemDamage(stack.getItemDamage() - 1); return false; } } Item Tool Base: public class ItemToolBase extends ItemTool { public ItemToolBase(String name, float attackDamageIn, float attackSpeedIn, ToolMaterial materialIn, Set<Block> effectiveBlocksIn) { super(attackDamageIn, attackSpeedIn, materialIn, effectiveBlocksIn); this.setUnlocalizedName(name); this.setRegistryName(new ResourceLocation(Reference.MODID, name)); } } Register item: public static final Item carving_tool = new ItemCarvingTool("carving_tool", 2.0f, 2.0f, Item.ToolMaterial.IRON, null);
  10. Thought I'd paste my final function here: public static void findRadiusBlock(Event event, int radius) { BlockPos pos = event.getEntity().getPosition(); int chunkPosX = pos.getX() >> 4; int chunkPosZ = pos.getZ() >> 4; if (!event.getWorld().isRemote) { for (int x = chunkPosX - radius; x < chunkPosX + radius; x++) { for (int z = chunkPosZ - radius; z < chunkPosZ + radius; z++) { Map<BlockPos, TileEntity> currentChunkTE = event.getWorld().getChunkFromChunkCoords(x, z).getTileEntityMap(); for (TileEntity te : currentChunkTE.values()) { if (te != null) { if (te instanceof TileEntityRadiusBlock) { myFunction(); } } } } } } }
  11. Thank you everyone! @diesieben07 for specifics on the code syntax and explantion, @Matryoshika for pointing out that I'm not iterating through all Block Pos' to get chunks from each and clarifying the rest of pretty much everything, and finally @jabelar for the super helpful tips! I have finally got everything working, and it is working great. I'm super grateful and really happy with how it's turned out. With this, my mod is fairly close to complete, code side. Couldn't have figured this out without the awesome, in-depth explanations from you guys.
  12. Boy... I am not experienced with this... Firstly, I am having trouble accessing Chunk::getTileEntityMap, as I have no clue how to get the Chunk using these chunk coords. Secondly, won't you still be iterating through all BlockPos because you're still converting all of them into chunk coords, meaning, you'll get the same chunk out of multiple BlockPos'. How would I skip the chunk once I've found and checked it? Thridly, how do I check if TileEntities are in "block coordiante boundaries", and if they're not, how do I make them. Super confused, sorry This is literally all I have. I've been thinking about it, and have no idea where to go from here. for (BlockPos pos : boxRadius) { int chunkCoordX = pos.getX() >> 4; int chunkCoordZ = pos.getZ() >> 4; }
  13. So, instead of using Iterable<BlockPos> = BlockPos#getAllInBox. How do I find all chunks in the radius instead?
  14. Hey everyone, I am making a block that acts on entities in an area of 256x256x256. The problem I am having is that iterating through all these block pos's obviously puts EVERYTHING at a halt. Makes sense, since it's iterating through 16,777,216 blocks! I have no idea how you could possible optimize something like this! I was looking through the MEGA TORCH source code, and couldn't really figure out what he could have possibly done to make his thing work in a 64x64x64 radius. Any help appreciated! My (16 million block check) code: Iterable<BlockPos> tileEntityRadiusBlock = BlockPos.getAllInBox(eventPos.add(256.0f, 256.0f, 256.0f), eventPos.add(-256.0f, -256.0f, -256.0f)); // 256x256x256 range for(BlockPos pos : tileEntityRadiusBlock) { Utils.getLogger().info(pos); // Starts printing 16.7 million lines of block pos =p if(world.getTileEntity(pos) != null){ if(world.getTileEntity(pos) instanceof TileEntityRadiusBlock){ // Run code here } } } Really guys! All help is appreciated! This is a HUGE BRICK WALL for me!
  15. I have found the problem. So obvious. During trying to make sound and particles work, I changed !worldIn.isRemote to worldIn.isRemote! Changed that back, and now all's working fine! Just need to figure out how I can do particles and sound for the block and the logic server side, without having to duplicate the function
  16. UPDATE: I've also tried adding getWorld().removeTileEntity(getPos()); just before the code that sets the block state. Still reverts back immediately. I should also mention that a lot of different blocks use this Tile Entity when registered through overriding createTileEntity() in each block's class.
  17. Hey everyone, So, I have a block that has a Tile Entity. When I right click this block with one of my items, I check if this block that was right clicked is an instanceof this Tile Entity. If it is, I run a getWorld().setBlockState() method inside of the Tile Entities code. All the code runs, except, as soon as it changes the block, it INSTANTLY REVERTS back to the old block. I feel this may be because the Tile Entity might still be there, or something? Anyways, here's my code. (NOTE: I have shortened this code on purpose in the Tile Entity. PlaceNewModBlock actually has a bunch of other conditions in it to change the block into others. I removed these other conditions in my code to test if it was the others interfering, but they weren't.) TILE ENTITY CLASS: public class TileEntityModBlock extends TileEntity { public int carveAmount = 0; public void placeNewModBlock() { Block mod_block = getWorld().getBlockState(getPos()).getBlock(); Utils.getLogger().info(mod_block.getUnlocalizedName()); if(mod_block == ModBlocks.new_mod_block) { getWorld().setBlockState(getPos(), ModBlocks.new_mod_block.getDefaultState()); } } } ITEM CLASS: @Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if(worldIn.isRemote) { if (worldIn.getTileEntity(pos) != null) { if (worldIn.getTileEntity(pos) instanceof TileEntityModBlock) { TileEntityModBlock modBlock = (TileEntityModBlock) worldIn.getTileEntity(pos); modBlock.carveAmount++; if(modBlock.carveAmount >= 3){ modBlock.placeNewModBlock(); } } } } return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); } So, when the carveAmount is greater than 3 (R-Click block 3 times) The block should change to the new one, based on whatever block you're right clicking is. It does change, but REVERTS back immediately. Again, I think it may be something to do with the Tile Entity still being there... anways, help is appreciated! Thanks!
  18. Thanks, diesieben for the actual answer, exactly what I am looking for! Leviathan, I want to see what block I am looking at with the item I am holding from my mod... Not trying to add right click action... (This item is a tool) I'm not that stupid.
  19. Hey everyone, So I am trying to make a switch statement to compare the block that I am looking at, to the blocks within my mod. Yet, when I try make my first case, I get Constant Expression Required error. I'm not sure how to fix this. All my blocks in my mod are declared as final variables. Here are the two things I've tried so far: switch (worldIn.getBlockState(pos).getBlock()) { case ModBlocks.my_mod_block : Utils.getLogger().info("mod block right clicked"); break; } switch (true) { case (worldIn.getBlockState(pos).getBlock() == ModBlocks.my_mod_block) : Utils.getLogger().info("mod block right clicked"); break; } ModBlocks.class public class ModBlocks { public static final Block my_mod_block = new MyModBlock("my_mod_block", Material.WOOD); public static final Block[] BLOCKS = { my_mod_block }; } Thanks!
  20. Finally figured it out, after trawling through the MC code worldIn.spawnParticle(EnumParticleTypes.BLOCK_CRACK, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, 1.0, 1.0, 1.0, Block.getIdFromBlock(worldIn.getBlockState(pos).getBlock()));
×
×
  • Create New...

Important Information

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