Jump to content

[Solved] [1.7.10] Custom door top doesn't break when bottom is broken?


Recommended Posts

Posted

I'm trying to make a custom door which doesn't open with redstone, only manually, and can't change state if it has a redstone signal. I'm achieving this with a static HashMap associating locations (as x|y|z Strings) with lock states (as Booleans). That all works, and I don't think it has much to do with the problem at hand, though I can't be sure.

 

The problem is that if I break the bottom half of my door, it leaves an invisible, open, top half of the door behind. It's always open regardless of the door's state before breaking. If I break the top half first, then the entire door breaks properly.

 

I don't even see anywhere that the BlockDoor class actually handles its breaking, so I'm not sure what I need to do to make this work. Here's the code I currently have:

 

BlockDiamondDoor.java:

package com.IceMetalPunk.redplus.blocks;

import java.util.HashMap;
import java.util.Random;

import com.IceMetalPunk.redplus.items.RedPlusItems;

import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.world.World;

public class BlockDiamondDoor extends BlockDoor {

public static HashMap<String, Boolean> stateMap = new HashMap<String, Boolean>();

public BlockDiamondDoor() {
	super(Material.anvil);
}

@Override
public void onBlockAdded(World world, int x, int y, int z) {
	boolean powered = world.isBlockIndirectlyGettingPowered(x, y, z);
	stateMap.put(x + "|" + y + "|" + z, Boolean.valueOf(powered));
	int meta = world.getBlockMetadata(x, y, z);
	if ((meta &  == 0) {
		stateMap.put(x + "|" + (y + 1) + "|" + z, Boolean.valueOf(powered));
	}
}

@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
	stateMap.put(x + "|" + y + "|" + z, false);
	if ((meta &  == 0) {
		stateMap.put(x + "|" + (y + 1) + "|" + z, false);
	}
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float px, float py,
		float pz) {
	if (!stateMap.containsKey(x + "|" + y + "|" + z) || stateMap.get(x + "|" + y + "|" + z).equals(Boolean.valueOf(false))) {
		super.onBlockActivated(world, x, y, z, player, side, px, py, pz);
		return true;
	}
	else {
		return false;
	}
}

@Override
public Item getItemDropped(int meta, Random rand, int fortune) {
	return (meta &  != 0 ? null : RedPlusItems.diamondDoor;
}

@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
	boolean hasPower = world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z);
	stateMap.put(x + "|" + y + "|" + z, Boolean.valueOf(hasPower));
	int meta = world.getBlockMetadata(x, y, z);
	if ((meta &  == 0) {
		stateMap.put(x + "|" + (y + 1) + "|" + z, Boolean.valueOf(hasPower));
	}
	else {
		stateMap.put(x + "|" + (y - 1) + "|" + z, Boolean.valueOf(hasPower));
	}
}

}

 

Why is the top-hlaf-door remaining behind after breaking the bottom half (and especially why is it not having the same problem in the other way 'round)?

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

Not sure how I missed that; I just added it in now. But sadly, it hasn't solved the problem. The top half still remains after breaking the bottom half. I'm almost ready to just manually set the top half to air in #breakBlock, but I feel like there's some underlying problem which would only be compounded by that.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

I've greatly simplified the code by moving the check for redstone power into the onBlockActivated() method, removing the need for a hashmap at all. So now I'm not even touching the breakBlock() method...and still, if I break the bottom of the door, the top remains (invisible as ever).

 

Here's the updated, simplified code. Maybe it'll help someone find something I can do to fix this problem?

 

package com.IceMetalPunk.redplus.blocks;

import java.util.Random;

import com.IceMetalPunk.redplus.items.RedPlusItems;

import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.world.World;

public class BlockDiamondDoor extends BlockDoor {

public BlockDiamondDoor() {
	super(Material.anvil);
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float px, float py,
		float pz) {

	// Determine if this block has redstone power
	boolean thisPowered = world.isBlockIndirectlyGettingPowered(x, y, z);
	boolean otherPowered = false;

	// Depending on if this is the top or bottom, determine if the "other" block has redstone power
	if ((world.getBlockMetadata(x, y, z) &  == 0) {
		otherPowered = world.isBlockIndirectlyGettingPowered(x, y + 1, z);
	}
	else {
		otherPowered = world.isBlockIndirectlyGettingPowered(x, y - 1, z);
	}

	// If either half has redstone power, don't change state; otherwise, do what doors do.
	if (thisPowered || otherPowered) {
		return false;
	}
	else {
		super.onBlockActivated(world, x, y, z, player, side, px, py, pz);
		return true;
	}
}

@Override
public Item getItemDropped(int meta, Random rand, int fortune) {
	return (meta &  != 0 ? null : RedPlusItems.diamondDoor;
}

@Override // So redstone doesn't open and close the door
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
}

}

 

*EDIT* Ah, I fixed it! Turns out, the door destruction is handled in the onNeighborBlockChange() method. By overriding that, I was stopping it from detecting when the bottom half was destroyed. So I had to basically copy/paste the code from the BlockDoor#onNeighborBlockChange() method, and just selectively remove the redstone handling condition. Now everything works perfectly! :D

Whatever Minecraft needs, it is most likely not yet another tool tier.

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.