Jump to content

Recommended Posts

Posted

I guess this might be a pretty simple question, but for some reason I can't get this code to work. I'm familiar with java and it seems to be alright, it also produces no errors during compilation nor during testing with the client.

 

So first I made a class called LevelTwoDoor which extended BlockDoor, the only real difference was adding a simple if statement that returned false if the player's level was lower than 2. Here is the class (the rest of the code is just copied from the original BlockDoor class). I added attempts at printing a message to the player before every possible return statement, but none showed. I also tried to kill them by setting their health to 0 before every return statement, and that never happened. So I'm assuming this whole class is somehow not actually in the game, although the item does appear. The if statement was added right at the beginning of the onBlockActivated method:

 

 

import net.minecraft.block.BlockDoor;

import net.minecraft.block.material.Material;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.util.ChatComponentText;

import net.minecraft.util.IChatComponent;

import net.minecraft.world.World;

 

public class LevelTwoDoor extends BlockDoor{

 

public LevelTwoDoor(){

super(Material.wood);

}

 

    public boolean onDoorActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_){

        if(p_149727_5_.experienceLevel < 50){ //originally this was <2 but I was messing around

        p_149727_5_.setHealth((float) 0.0);

        return false;

        }else{

                if (this.blockMaterial == Material.iron)

        {

            p_149727_5_.setHealth(0.0f);

            p_149727_5_.addChatMessage(new ChatComponentText(Integer.toString(p_149727_5_.experienceLevel)));

            return false; //Allow items to interact with the door

        }

        else

        {

            int i1 = this.func_150012_g(p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_);

            int j1 = i1 & 7;

            j1 ^= 4;

 

            if ((i1 & 8) == 0)

            {

                p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_, p_149727_4_, j1, 2);

                p_149727_1_.markBlockRangeForRenderUpdate(p_149727_2_, p_149727_3_, p_149727_4_, p_149727_2_, p_149727_3_, p_149727_4_);

            }

            else

            {

                p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_ - 1, p_149727_4_, j1, 2);

                p_149727_1_.markBlockRangeForRenderUpdate(p_149727_2_, p_149727_3_ - 1, p_149727_4_, p_149727_2_, p_149727_3_, p_149727_4_);

            }

 

            p_149727_1_.playAuxSFXAtEntity(p_149727_5_, 1003, p_149727_2_, p_149727_3_, p_149727_4_, 0);

            p_149727_5_.setHealth((float) 0.0);

            p_149727_5_.addChatMessage(new ChatComponentText(Integer.toString(p_149727_5_.experienceLevel)));

            return true;

        }

        }

    }

 

}

 

 

Assuming that code isn't wrong (probably is considering this is my first attempt), the problem could be in me registering the LevelTwoDoor to the mod. The texture obviously doesn't appear, but the outline of the "level two door" does appear, and does switch orientation when I click it (below level 2 despite the if statement), and the messages never show up nor do I ever die as I should. I guess a problem could be in the casting of levelTwoDoor, but I did try to make it a LevelTwoDoor, a BlockDoor, and a Block, and I tried casting it in multiple ways. There's a chance I missed one, so if you think that's the problem let me know.

 

 

public static Block levelTwoDoor;

...

levelTwoDoor = new LevelTwoDoor().setCreativeTab(heavenstab).setBlockTextureName(modid + ":" + "wood");

GameRegistry.registerBlock(levelTwoDoor, "levelTwoDoor");

 

 

 

Again I could be doing something completely wrong, or there could be a silly mistake, either way I'll appreciate any help I could get. Also, has no one implemented level-gated doors yet? I didn't find any when I searched around.

 

 

Posted

Nice idea! I quite like it. Can't wait to see it in action!

 

And as to the question... Isn't the vanilla door a tile entity?

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Posted

Errr that could be the case. But when I read the documentation online the DoorBlock had an onActivateMethod which was a response to a right click,  so I just assumed that was the "door" I needed. I mean an actual block of wood wouldn't have such a method? No idea it seemed to simple but I'm going crazy.

Posted

No, all blocks can have that method if they choose to override it.

 

I just checked and no, there is no tile entity for a door. Oh well. I have no idea what the problem is.

 

Please show your code so we can get a better idea of the problem.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Posted

Hi

 

Some thoughts

 

Have you registered your door block using GameRegistry?

 

Try @Override before

onDoorActivated()

maybe your parameter list is wrong

 

Your approach for onActivateMethod seems fine to me. 

 

How are you placing your door into the world?  You mention an item that seems ok?

 

-TGG

 

 

 

Posted

Good news!!!!!

 

I love how all of us missed this. I named the method "onDoorActivated" when it should've been "onBlockActivated". Whoever told me to try @Override saved my life, because when I put it above the method it told me no  method was being overridden which allowed me to see the mistake in naming. Thanks guys!

Posted

Oh wow >.> This is what I get for assuming that doors had a onDoorActivated method. I mean, it makes so much sense!

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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