Skip to content

Commit

Permalink
add uuid to screen + summon function
Browse files Browse the repository at this point in the history
  • Loading branch information
afamiliarquiet committed Oct 15, 2024
1 parent ef2c99b commit 4756a36
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP
if (!level.isClientSide
&& player instanceof ServerPlayer serverPlayer
&& level.getBlockEntity(pos) instanceof SummoningTableBlockEntity zeraxos) {
serverPlayer.openMenu(zeraxos);
if (serverPlayer.isCrouching() && level.getBlockEntity(pos) instanceof SummoningTableBlockEntity tableEntity) {
tableEntity.tryActivate();
} else {
serverPlayer.openMenu(zeraxos);
}
}

return InteractionResult.sidedSuccess(level.isClientSide);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.afamiliarquiet.familiar_magic.block.entity;

import io.github.afamiliarquiet.familiar_magic.FamiliarMagic;
import io.github.afamiliarquiet.familiar_magic.block.EnchantedCandleBlock;
import io.github.afamiliarquiet.familiar_magic.block.FamiliarBlocks;
import io.github.afamiliarquiet.familiar_magic.gooey.SummoningTableMenu;
Expand All @@ -12,9 +11,12 @@
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.LockCode;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.Nameable;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
Expand Down Expand Up @@ -49,7 +51,7 @@ public class SummoningTableBlockEntity extends BlockEntity implements IItemHandl
@Override
public int get(int index) {
return switch (index) {
case 0, 1, 2, 3 -> UUIDUtil.uuidToIntArray(target)[index];
case 0, 1, 2, 3 -> target == null ? 0 : UUIDUtil.uuidToIntArray(target)[index];
default -> 0;
};
}
Expand Down Expand Up @@ -82,11 +84,22 @@ public SummoningTableBlockEntity(BlockPos pos, BlockState blockState) {
super(FamiliarBlocks.SUMMONING_TABLE_BLOCK_ENTITY.get(), pos, blockState);
}

public boolean tryActivate() {
if (this.target != null && this.level instanceof ServerLevel serverLevel) {
Entity targetEntity = serverLevel.getEntity(this.target);
if (targetEntity instanceof LivingEntity livingTarget) {
BlockPos destination = this.getBlockPos();
livingTarget.teleportTo(destination.getX() + 0.5, destination.getY() + 1, destination.getZ() + 0.5);
return true;
}
}
return false;
}

public static void tick(Level level, BlockPos pos, BlockState state, SummoningTableBlockEntity thisish) {
UUID oldTarget = thisish.target;
if (level.getGameTime() % 80L == 0L) {
thisish.target = processCandles(level, pos);
FamiliarMagic.LOGGER.debug("New target processed: " + (thisish.target == null ? "null" : thisish.target.toString()));
}
}

Expand Down Expand Up @@ -130,7 +143,6 @@ private static byte nybbleFromCandleColumn(Level level, BlockPos pos) {
for (int yOffset = 4; yOffset > 0; yOffset--) {
BlockState curiousBlockState = level.getBlockState(pos.offset(0, yOffset, 0));
if (curiousBlockState.is(FamiliarBlocks.ENCHANTED_CANDLE_BLOCK)) {
//FamiliarMagic.LOGGER.debug("Found " + curiousBlockState.getValue(EnchantedCandleBlock.CANDLES) + " candles " + yOffset + " blocks up")
return (byte) ((yOffset - 1) << 2 | (curiousBlockState.getValue(EnchantedCandleBlock.CANDLES) - 1));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SummoningTableMenu extends AbstractContainerMenu {
static final ResourceLocation EMPTY_SLOT_TRUE_NAME = ResourceLocation.fromNamespaceAndPath(MOD_ID, "item/empty_slot_true_name");

private final ContainerLevelAccess levelAccess;
private final ContainerData tableData;
protected final ContainerData tableData;
private final SlotItemHandler trueNameSlot;

public SummoningTableMenu(int containerId, Inventory playerInv) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.core.UUIDUtil;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
Expand Down Expand Up @@ -30,4 +31,22 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
super.render(graphics, mouseX, mouseY, partialTick);
this.renderTooltip(graphics, mouseX, mouseY);
}

@Override
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
super.renderLabels(guiGraphics, mouseX, mouseY);

guiGraphics.drawString(
this.font,
Component.literal(UUIDUtil.uuidFromIntArray(new int[]{
menu.tableData.get(0),
menu.tableData.get(1),
menu.tableData.get(2),
menu.tableData.get(3)
}).toString()),
52,
31,
4210752,
false);
}
}

0 comments on commit 4756a36

Please sign in to comment.