Skip to content

Commit

Permalink
Restrict ornament placement positions that would intersect with a block
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Dec 24, 2023
1 parent 785ca38 commit 2499d4e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/xyz/nucleoid/extras/lobby/NEItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ private static ActionResult onUseBlock(PlayerEntity player, World world, Hand ha

var lobbyState = PlayerLobbyState.get(player);

if (lobbyState.collectTaterFromBlock(world, pos, stack, player) == ActionResult.PASS && !(stack.getItem() instanceof TaterBoxItem) && hitResult.getSide() != Direction.UP) {
if (lobbyState.collectTaterFromBlock(world, pos, stack, player) == ActionResult.PASS && !(stack.getItem() instanceof TaterBoxItem)) {
var state = world.getBlockState(pos);

if (state.isIn(BlockTags.LEAVES)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
Expand Down Expand Up @@ -97,6 +98,20 @@ public boolean placeOrnament(ServerPlayerEntity player, ServerWorld world, Hand
if (item == Items.AIR) return false;

var pos = hitResult.getPos();
var side = hitResult.getSide();

if (side == Direction.UP) {
return false;
} else if (side != Direction.DOWN) {
var blockPos = hitResult.getBlockPos();
var belowPos = blockPos.add(side.getOffsetX(), side.getOffsetY() - 1, side.getOffsetZ());

if (world.getBlockState(belowPos).isFullCube(world, belowPos)) {
double minY = blockPos.getY() + OrnamentModel.HEIGHT;
pos = pos.withAxis(Direction.Axis.Y, Math.max(minY, pos.getY()));
}
}

var offset = pos.subtract(this.pos.toCenterPos());

float yaw = player.getYaw() - 180;
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/xyz/nucleoid/extras/lobby/tree/OrnamentModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import xyz.nucleoid.extras.lobby.block.TreeDecorationBlockEntity;

public final class OrnamentModel implements InteractionHandler {
public static final float WIDTH = 8 / 16f;
public static final float HEIGHT = 11 / 16f;

private final TreeDecorationBlockEntity blockEntity;
private final Ornament ornament;

Expand Down Expand Up @@ -48,7 +52,7 @@ public OrnamentModel(TreeDecorationBlockEntity blockEntity, Ornament ornament) {
this.interaction = new InteractionElement(this);

this.interaction.setOffset(ornament.offset().subtract(0, 0.6, 0));
this.interaction.setSize(8 / 16f, 11 / 16f);
this.interaction.setSize(WIDTH, HEIGHT);

this.updateTransformations(true);
}
Expand Down Expand Up @@ -85,8 +89,14 @@ public void attack(ServerPlayerEntity player) {
}
}

private long getTime() {
World world = this.blockEntity.getWorld();

return world == null ? 0 : world.getTime();
}

private void updateTransformations(boolean initial) {
long time = this.blockEntity.getWorld().getTime();
long time = this.getTime();
float rotation;

if (this.wobbleTicks > 0) {
Expand Down

0 comments on commit 2499d4e

Please sign in to comment.