Skip to content

Commit

Permalink
you guessed it, even more tablet stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
MehVahdJukaar committed Oct 30, 2024
1 parent 7b623a9 commit ca6045b
Show file tree
Hide file tree
Showing 21 changed files with 318 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public StoneTabletScreen(StoneTabletBlockEntity sign, boolean isFiltered, Compon
this.messages = IntStream.range(0, maxLines)
.mapToObj(i -> this.text.getMessage(i, isFiltered))
.map(Component::getString).toArray(String[]::new);
this.canEdit = !sign.getBlockState().getValue(StoneTabletBlock.ENGRAVED);
this.canEdit = sign.getBlockState().getValue(StoneTabletBlock.TYPE).canEdit();
}

@Override
Expand All @@ -72,7 +72,7 @@ protected void init() {
this.addRenderableWidget(Button.builder(Component.translatable("gui.doom_and_gloom.stone_tablet.engrave"), (p_98177_) -> {
this.onEngrave();
}).bounds(this.width / 2 - 100, 196, 98, 20).build());
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (p_280851_) -> {
this.addRenderableWidget(Button.builder(Component.translatable("gui.doom_and_gloom.stone_tablet.cancel"), (p_280851_) -> {
this.onDone();
}).bounds(this.width / 2 + 2, 196, 98, 20).build());
}
Expand Down Expand Up @@ -246,14 +246,15 @@ private void drawEngravedString(GuiGraphics guiGraphics, String string, int pX,
private void setMessage(String message) {
this.messages[this.line] = message;
this.text = this.text.withMessage(this.line, Component.literal(message));
this.sign.setText(this.text);
}

private void onDone() {
this.minecraft.setScreen(null);
}

private void onEngrave() {
//TODO: Engrave sound
this.sign.setText(this.text);
this.engraveOnClose = true;
this.minecraft.setScreen(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import galena.doom_and_gloom.network.packet.EngraveStoneTabletPacket;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.contents.LiteralContents;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
Expand All @@ -24,9 +27,11 @@
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.network.PacketDistributor;
Expand All @@ -39,46 +44,66 @@ public class StoneTabletBlock extends Block implements SimpleWaterloggedBlock, T

public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final BooleanProperty ATTACHED_TO_WALL = BlockStateProperties.ATTACHED;
public static final BooleanProperty ENGRAVED = BooleanProperty.create("engraved");
public static final EnumProperty<Attachment> ATTACHMENT = EnumProperty.create("attachment", Attachment.class);
public static final EnumProperty<Type> TYPE = EnumProperty.create("type", Type.class);

protected static final VoxelShape SHAPE_X = Block.box(6.0, 0.0, 2.0, 10.0, 16.0, 14.0);
protected static final VoxelShape SHAPE_Z = Block.box(2.0, 0.0, 6.0, 14.0, 16.0, 10.0);
protected static final VoxelShape SHAPE_Z = Block.box(6.0, 0.0, 2.0, 10.0, 16.0, 14.0);
protected static final VoxelShape SHAPE_X = Block.box(2.0, 0.0, 6.0, 14.0, 16.0, 10.0);

protected static final VoxelShape SHAPE_SOUTH = Block.box(2.0D, 0.0D, 0.0D, 14.0D, 16.0D, 4.0D);
protected static final VoxelShape SHAPE_NORTH = Block.box(2.0D, 0.0D, 12.0D, 14.0D, 16.0D, 16.0D);

protected static final VoxelShape SHAPE_EAST = Block.box(0.0D, 0.0D, 2.0D, 4.0D, 16.0D, 14.0D);
protected static final VoxelShape SHAPE_WEST = Block.box(12.0D, 0.0D, 2.0D, 16.0D, 16.0D, 14.0D);

protected static final VoxelShape SHAPE_FLOOR_Z = Block.box(2.0, 0.0, 0.0, 14.0, 4.0, 16.0);
protected static final VoxelShape SHAPE_FLOOR_X = Block.box(0.0, 0.0, 2.0, 16.0, 4.0, 14.0);

protected static final VoxelShape SHAPE_CEILING_Z = Block.box(2.0, 0.0, 12.0, 14.0, 16.0, 16.0);
protected static final VoxelShape SHAPE_CEILING_X = Block.box(0.0, 0.0, 12.0, 16.0, 16.0, 14.0);

public StoneTabletBlock(Properties pProperties) {
super(pProperties);
this.registerDefaultState(this.getStateDefinition().any()
.setValue(WATERLOGGED, false)
.setValue(FACING, Direction.NORTH).setValue(ATTACHED_TO_WALL, false)
.setValue(ENGRAVED, false));
.setValue(FACING, Direction.NORTH).setValue(ATTACHMENT, Attachment.CENTER_UPRIGHT)
.setValue(TYPE, Type.DEFAULT));
}

@Override
public @Nullable BlockState getStateForPlacement(BlockPlaceContext pContext) {
boolean water = pContext.getLevel().getFluidState(pContext.getClickedPos()).getType() == Fluids.WATER;
BlockPos pos = pContext.getClickedPos();
boolean water = pContext.getLevel().getFluidState(pos).getType() == Fluids.WATER;
BlockState state = this.defaultBlockState().setValue(WATERLOGGED, water);

Level level = pContext.getLevel();

Direction clickFace = pContext.getClickedFace();
if (clickFace.getAxis() == Direction.Axis.Y) {
BlockState below = level.getBlockState(pos.relative(clickFace.getOpposite()));
if (below.getBlock() instanceof StoneTabletBlock && below.getValue(ATTACHMENT).isUpright()) {
return state.setValue(FACING, below.getValue(FACING))
.setValue(ATTACHMENT, below.getValue(ATTACHMENT));
}

Player p = pContext.getPlayer();
if (p != null && p.isShiftKeyDown()) {
return state.setValue(FACING, pContext.getHorizontalDirection().getOpposite())
.setValue(ATTACHMENT, clickFace == Direction.UP ? Attachment.CEILING : Attachment.FLOOR);
}

if (pContext.getClickedFace().getAxis() == Direction.Axis.Y) {
return this.defaultBlockState().setValue(FACING, pContext.getHorizontalDirection().getOpposite())
.setValue(ATTACHED_TO_WALL, false)
.setValue(WATERLOGGED, water);
return state.setValue(FACING, pContext.getHorizontalDirection().getOpposite())
.setValue(ATTACHMENT, Attachment.CENTER_UPRIGHT);
} else {
return this.defaultBlockState().setValue(FACING, pContext.getClickedFace().getOpposite())
.setValue(ATTACHED_TO_WALL, true)
.setValue(WATERLOGGED, water);
return this.defaultBlockState().setValue(FACING, clickFace)
.setValue(ATTACHMENT, Attachment.WALL);
}
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
super.createBlockStateDefinition(pBuilder);
pBuilder.add(WATERLOGGED, FACING, ATTACHED_TO_WALL, ENGRAVED);
pBuilder.add(WATERLOGGED, FACING, ATTACHMENT, TYPE);
}

@Override
Expand All @@ -91,19 +116,29 @@ public BlockState updateShape(BlockState pState, Direction pFacing, BlockState p

@Override
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
if (pState.getValue(ATTACHED_TO_WALL)) {
return switch (pState.getValue(FACING)) {
return switch (pState.getValue(ATTACHMENT)) {
case FLOOR -> switch (pState.getValue(FACING)) {
case NORTH, SOUTH -> SHAPE_FLOOR_Z;
default -> SHAPE_FLOOR_X;
};

case CEILING -> switch (pState.getValue(FACING)) {
case NORTH, SOUTH -> SHAPE_CEILING_Z;
default -> SHAPE_CEILING_X;
};

case WALL -> switch (pState.getValue(FACING)) {
case SOUTH -> SHAPE_SOUTH;
case EAST -> SHAPE_EAST;
case WEST -> SHAPE_WEST;
default -> SHAPE_NORTH;
};
} else {
return switch (pState.getValue(FACING)) {

case CENTER_UPRIGHT -> switch (pState.getValue(FACING)) {
case NORTH, SOUTH -> SHAPE_X;
default -> SHAPE_Z;
};
}
};
}

@Override
Expand Down Expand Up @@ -142,6 +177,21 @@ public FluidState getFluidState(BlockState pState) {
return pState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(pState);
}

@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos, Player player) {
if (level.getBlockEntity(pos) instanceof StoneTabletBlockEntity tile) {
ItemStack stack = this.asItem().getDefaultInstance();
CompoundTag tag = new CompoundTag();
tag.put("BlockEntityTag", tile.saveWithoutMetadata());
CompoundTag c = new CompoundTag();
c.putString("type", state.getValue(TYPE).getSerializedName());
tag.put("BlockStateTag", c);
stack.setTag(tag);
return stack;
}
return super.getCloneItemStack(state, target, level, pos, player);
}

public void openTextEdit(ServerPlayer pPlayer, StoneTabletBlockEntity pSignEntity) {
pSignEntity.setAllowedPlayerEditor(pPlayer.getUUID());
DGNetwork.CHANNEL.send(
Expand All @@ -155,7 +205,33 @@ private boolean otherPlayerIsEditingSign(Player pPlayer, StoneTabletBlockEntity
}

@Override
public BlockEntityType getType() {
public BlockEntityType<?> getType() {
return OBlockEntities.STONE_TABLET.get();
}

public enum Type implements StringRepresentable {
DEFAULT, ENGRAVED, CRACKED;

@Override
public String getSerializedName() {
return this.name().toLowerCase();
}

public boolean canEdit() {
return this == DEFAULT;
}
}

public enum Attachment implements StringRepresentable {
CENTER_UPRIGHT, WALL, CEILING, FLOOR;

@Override
public String getSerializedName() {
return this.name().toLowerCase();
}

public boolean isUpright() {
return this == CENTER_UPRIGHT || this == WALL;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -62,6 +63,7 @@ protected void saveAdditional(CompoundTag tag) {
@Override
public void load(CompoundTag tag) {
super.load(tag);

if (tag.contains("text")) {
StoneTabletText.DIRECT_CODEC
.parse(NbtOps.INSTANCE, tag.getCompound("text"))
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/galena/doom_and_gloom/data/OLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ protected void addTranslations() {
addSubtitle("entity", "holler_death", "Holler dies");
addSubtitle("entity", "holler_hurt", "Holler hurts");
addSubtitle("entity", "holler_shrieks", "Holler shrieks");
addSubtitle("entity", "holler_hollers", "Holler hollers");
addSubtitle("entity", "holler_hollers", "Holler wails"); //howls? howls? whispers?

addSubtitle("gui", "stone_tablet.engrave", "Engrave");
addSubtitle("gui", "stone_tablet.cancel", "Cancel");

/*
Automatically create translations for blocks and items based on their registry name.
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/galena/doom_and_gloom/index/OSoundEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public class OSoundEvents {
public static final RegistryObject<SoundEvent> SEPULCHER_UNSEALING = HELPER.createSoundEvent("block.sepulcher.unsealing");
public static final RegistryObject<SoundEvent> SEPULCHER_HARVEST = HELPER.createSoundEvent("block.sepulcher.harvest");

public static final RegistryObject<SoundEvent> GRAVETENDER_WORK = HELPER.createSoundEvent("entity.villager.work_carpenter");
//TODO: add these 2
public static final RegistryObject<SoundEvent> GRAVETENDER_WORK = HELPER.createSoundEvent("entity.villager.work_gravetender");

public static final RegistryObject<SoundEvent> STONE_TABLET_ENGRAVE = HELPER.createSoundEvent("block.stone_tablet.engrave");

public static final RegistryObject<SoundEvent> HOLLER_DEATH = HELPER.createSoundEvent("entity.holler_death");
public static final RegistryObject<SoundEvent> HOLLER_HURTS = HELPER.createSoundEvent("entity.holler_hurts");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import galena.doom_and_gloom.content.block.StoneTabletBlock;
import galena.doom_and_gloom.content.block.StoneTabletBlockEntity;
import galena.doom_and_gloom.index.OSoundEvents;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.FilteredText;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraftforge.network.NetworkEvent;

import java.util.List;
Expand Down Expand Up @@ -53,7 +56,11 @@ private void updateSignText(ServerPlayer player, List<FilteredText> filteredText
if (level.hasChunkAt(pos) && level.getBlockEntity(pos) instanceof StoneTabletBlockEntity te) {
te.updateStoneTabletText(player, filteredText);
if(engrave){
level.setBlockAndUpdate(pos, level.getBlockState(pos).setValue(StoneTabletBlock.ENGRAVED, true));
level.setBlockAndUpdate(pos, level.getBlockState(pos)
.setValue(StoneTabletBlock.TYPE, StoneTabletBlock.Type.ENGRAVED));
level.playSound(null, pos, OSoundEvents.STONE_TABLET_ENGRAVE.get(),
SoundSource.BLOCKS, 1.0f, 1.0f);
level.gameEvent(player, GameEvent.BLOCK_CHANGE, pos);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ TODO
mandatory=true
versionRange="[7.1.0,)"
ordering="AFTER"
side="BOTH"

[[dependencies.doom_and_gloom]]
modId="oreganized"
mandatory=true
versionRange="*"
ordering="AFTER"
side="BOTH"

This file was deleted.

Loading

0 comments on commit ca6045b

Please sign in to comment.