Jump to content

Recommended Posts

Posted

I'm brand new to Java, however I have a fair amount of prior programming experience in other object oriented languages.

For the past few days, I have been attempting to create a custom door, however I have had no luck. The top half of the door does not spawn, and the door is not placed on the correct side of the block. The game is not crashing, but I have attempted to fix this and I'm unsure what I have done wrong. I am considering starting over again from scratch as I have been referencing code from 1.8 and earlier, and as a result something has definitely gone wrong somewhere.

 

If I were to start again from scratch, how would I (correctly) do this? I know I need to extend BlockDoor into a custom class, but I do not know which functions are necessary to port over as after deleting some, nothing changed. The same goes for the Item class - do I need to create a new class for the ItemDoor, or have to use any special functions to render/generate a second block?

 

I would really appreciate it if somebody outlined the steps and functions I need to use to create a simple, retextured wooden door (I may create more complex ones when I have figured out how to do this).

 

Thanks in advance

Posted

Post your code. We're not telepathic.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Yes, you have extend BlockDoor and ItemDoor classes to create your implementations. Also you will have to create assets for it - blockstate and models for each variant. I will give more information when I'm back home. But you can look at vanilla door blockstates and models for reference.

Posted
9 hours ago, Draco18s said:

Post your code. We're not telepathic.

 

2 hours ago, Alexiy said:

Yes, you have extend BlockDoor and ItemDoor classes to create your implementations. Also you will have to create assets for it - blockstate and models for each variant. I will give more information when I'm back home. But you can look at vanilla door blockstates and models for reference.

 

Here is my current code for reference. I did not add it in my original question as I was planning on completely restarting my Item and Block classes from scratch.

 

I made a few edits to my code when I realised that the problem was that I was placing the Block version of the door, not the Item version.

 

ItemMyDoor class:

 

public class ItemMyDoor extends ItemDoor implements IHasModel

{

 private final Block block;
 public ItemMyDoor(Block doorBlock, String name)
 {
  super(doorBlock);
  setUnlocalizedName(name);
  setRegistryName(name);
  this.block = doorBlock;
  
  setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
  ModItems.ITEMS.add(this);
  
 }

 

BlockMyDoor class:

 

public class BlockMyDoor extends BlockDoor implements IHasModel{
 
public Item placerItem;
 
 public BlockMyDoor(String name, Item item, Material par2Material)
 {
  
  super(par2Material);
  setUnlocalizedName(name);
  setRegistryName(name);
  placerItem = item;
  
  ModBlocks.BLOCKS.add(this);
 }
 
 public void setDoorItem(Item doorItem)
    {
        this.placerItem = doorItem;
    }
 
 public Item getDoorItem()
    {
        return placerItem;
    }

 @Override
 public void registerModels() {
  Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
  
 }
 
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        if (this.blockMaterial == Material.IRON)
        {
            return true;
        }
        else
        {
            BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
            IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);
            if (iblockstate.getBlock() != this)
            {
                return false;
            }
            else
            {
                state = iblockstate.cycleProperty(OPEN);
                worldIn.setBlockState(blockpos, state, 2);
                worldIn.markBlockRangeForRenderUpdate(blockpos, pos);             
                return true;
            }
        }
    }
}
 
Initialisation Classes (ModBlocks & ModItems)
 
public static final Block WHITE_DOOR = new BlockMyDoor("white_door", ModItems.WHITE_DOOR, Material.WOOD);
 
 
public static final Item WHITE_DOOR = new ItemMyDoor(ModBlocks.WHITE_DOOR, "white_door");
 
 
 
I'm also pretty sure that my .json files are valid, as I copied them directly from a copy of the default texture pack and just replaced the names (acacia_door_bottom_rh became white_door_bottom_rh, etc.)
 
 

 

 

Posted

code.png

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • 2 weeks later...
Posted (edited)
On 5/19/2018 at 10:56 PM, ThunderStrikeBlue said:

Is anyone able to help? I haven't done much work on this in the past week and I was hoping somebody could help me with this by the end of this weekend.

Can’t see anything wrong with your code but I’ve never done anything with doors. Try doing some debugging, adding print statements to see what gets called

also a GitHub would be appreciated

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.