Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item Placement with Signs #902

Merged
merged 3 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public void updatePhysics(GlowBlock me) {
}
}

/**
* Called to determine if the target block can be attached to
* when right clicking it.
*
* @param block The location the block is being placed at.
* @param against The face the block is being placed against.
* @return Whether the black can be attached to.
*/
public boolean canAttachTo(GlowBlock block, BlockFace against) {
return !(ItemTable.instance().getBlock(
block.getRelative(against.getOppositeFace()).getType()) instanceof BlockNeedsAttached);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/glowstone/block/blocktype/BlockSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.ItemTable;
import net.glowstone.block.entity.BlockEntity;
import net.glowstone.block.entity.SignEntity;
import net.glowstone.chunk.GlowChunk;
Expand Down Expand Up @@ -40,4 +41,12 @@ public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding,
GlowBlockState oldState) {
player.openSignEditor(block.getLocation());
}

@Override
public boolean canPlaceAt(GlowBlock block, BlockFace against) {
Material targetMat = ItemTable.instance().getBlock(
block.getRelative(against.getOppositeFace()).getType()).getMaterial();
return canAttachTo(block, against) || targetMat == Material.SIGN_POST
|| targetMat == Material.WALL_SIGN;
}
}
16 changes: 15 additions & 1 deletion src/main/java/net/glowstone/block/blocktype/BlockType.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ public void updatePhysics(GlowBlock block) {
public final void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face,
ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
GlowBlock target = against.getRelative(face);
final Material targetMat = ItemTable.instance().getBlock(
target.getRelative(face.getOppositeFace()).getType()).getMaterial();

// prevent building above the height limit
if (target.getLocation().getY() >= target.getWorld().getMaxHeight()) {
Expand Down Expand Up @@ -350,7 +352,19 @@ public final void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFac
}

// call canBuild event
boolean canBuild = canPlaceAt(target, face);
boolean canBuild = true;
switch (targetMat) {
case SIGN_POST:
case WALL_SIGN:
if (player.isSneaking()) {
canBuild = canPlaceAt(target, face);
} else {
return;
}
break;
default:
canBuild = canPlaceAt(target, face);
}
BlockCanBuildEvent canBuildEvent = new BlockCanBuildEvent(target, getId(), canBuild);
if (!EventFactory.getInstance().callEvent(canBuildEvent).isBuildable()) {
//revert(player, target);
Expand Down