Changing the material using declared fields of a block

Discussion in 'Plugin Development' started by xGhOsTkiLLeRx, Dec 21, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    xGhOsTkiLLeRx

    Hey there!

    I need help again :p
    Because I'm updating BlocksOnGlass a bit, I need to "fix" the blocks.

    Code:java
    1. Block.byId[Block.ICE.id] = null;
    2. Block.byId[Block.ICE.id] = new bogBlockIce(Block.ICE.id, 67).setHardness(0.5F).a("ice");
    3. try {
    4. Field field = Material.ICE.getClass().getDeclaredField("G");
    5. field.setAccessible(true);
    6. field.setBoolean(Material.ICE, true);
    7. } catch (Exception e) {
    8. e.printStackTrace();
    9. }
    10. Block.q[Block.ICE.id] = 3;


    BlockIce (decompiled)

    Show Spoiler
    Code:java
    1. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
    2. // Jad home page: [URL]http://www.kpdus.com/jad.html[/URL]
    3. // Decompiler options: packimports(3) braces deadcode fieldsfirst
    4.  
    5. package net.minecraft.src;
    6.  
    7. import java.util.Random;
    8.  
    9. // Referenced classes of package net.minecraft.src:
    10. // BlockBreakable, Material, World, Block,
    11. // EnumSkyBlock, EntityPlayer, ItemStack
    12.  
    13. public class BlockIce extends BlockBreakable
    14. {
    15.  
    16. public BlockIce(int i, int j)
    17. {
    18. super(i, j, Material.ice, false);
    19. slipperiness = 0.98F;
    20. setTickOnLoad(true);
    21. }
    22.  
    23. public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l)
    24. {
    25. super.harvestBlock(world, entityplayer, i, j, k, l);
    26. Material material = world.getBlockMaterial(i, j - 1, k);
    27. if(material.getIsSolid() || material.getIsLiquid())
    28. {
    29. world.setBlockWithNotify(i, j, k, Block.waterMoving.blockID);
    30. }
    31. }
    32.  
    33. public int quantityDropped(Random random)
    34. {
    35. return 0;
    36. }
    37.  
    38. public void updateTick(World world, int i, int j, int k, Random random)
    39. {
    40. if(world.getSavedLightValue(EnumSkyBlock.Block, i, j, k) > 11 - Block.lightOpacity[blockID])
    41. {
    42. dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k), 0);
    43. world.setBlockWithNotify(i, j, k, Block.waterStill.blockID);
    44. }
    45. }
    46.  
    47. public int getMobilityFlag()
    48. {
    49. return 0;
    50. }
    51.  
    52. protected ItemStack func_41001_e(int i)
    53. {
    54. return null;
    55. }
    56. }



    Can anyone explain me a bit more, what field I'm going to change?
    I don't know where I can find the different fields...
    And what's the difference between

    Block.q and Block.t ?

    => Goal is to change the rules to place things

    Thanks!
     
  2. Offline

    halley

    I'm not understanding your goal here. Bukkit lets you change a block directly, no need to work with the net.minecraft obfuscated fields at all. block.setType(Material.DIRT);
     
  3. Offline

    xGhOsTkiLLeRx

    Yeah. But can I do this before a event?
    I have to change the blocks at the onEnable() part. Otherwise the items will drop (eventually) off.
     
  4. Offline

    nisovin

    I'm not really sure what you're trying to do. The "G" variable seems to be "isReplaceable" and there is no "F" variable.
     
  5. Offline

    xGhOsTkiLLeRx

    Yeah that's my problem. I don't know what which variable is exactly. I searched for hours in all the damn files.
     
  6. Offline

    nisovin

    Well what are you trying to accomplish?
     
  7. Offline

    xGhOsTkiLLeRx

    @nisovin

    To change the material of the block to Dirt or Stone => Would be possible to place doors, rails, redstone, etc.
     
  8. Offline

    halley

    You're not trying to change the material, then. You're trying to change the adjacency rules of glass, so that other stuff is allowed to attach to it.
     
  9. Offline

    xGhOsTkiLLeRx

    @halley

    Not true and not false.
    For some block I can change the material
    Code:java
    1. Block.byId[Block.GLOWSTONE.id] = null;
    2. Block.byId[Block.GLOWSTONE.id] = new bogBlockGlowstone(Block.GLOWSTONE.id, 89, Material.EARTH).setHardness(0.3F).a("glowstone");

    For some block I need to change the "rules", that's true.
    Because it's not my plugin and I'm only updating it, I don't know the code sooooo well.
     
  10. Offline

    xGhOsTkiLLeRx

    no one?
    anyway, a little bump :)

    @halley

    Tried your suggestion, but it changes the block to dirt/stone/whatever

    I updated the OP to be more specific (change the rules like you said)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  11. Offline

    nisovin

    Try setting H to false.

    If that doesn't work, just try random ones until you get it. Sometimes that's all you can do.
     
    xGhOsTkiLLeRx likes this.
  12. Offline

    xGhOsTkiLLeRx

    @nisovin

    WORKS! Wow. Why "H"?
    Can ya tell me why you told me to set H to false?

    But anyway:

    Difference between Block.q and Block.t?
     
Thread Status:
Not open for further replies.

Share This Page