Skip to content

Commit

Permalink
Fix render rules, shelf locks, and add sign post waxing.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Aug 12, 2023
1 parent ff153e1 commit 72b399e
Show file tree
Hide file tree
Showing 17 changed files with 380 additions and 89 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,11 @@
- Fixed glassboards not integrating correctly with LambdaBetterGrass.
- Fixed some typo in the compatibility system of wood-based features.

### 1.0.0-beta.20

- Added sign post waxing similar to sign waxing.
- Added shelf NBT property `locked`.
- Fixed render rules model injection issues.
- Fixed shelves not respecting locks (NBT property `Lock`).

[EMI]: https://modrinth.com/mod/emi "EMI Modrinth page"
2 changes: 1 addition & 1 deletion build_logic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sourceSets {
}

dependencies {
utilImplementation implementation("org.quiltmc:loom:1.1.+")
utilImplementation implementation("org.quiltmc:loom:1.2.+")
implementation "org.quiltmc:quilt-json5:1.0.2"
implementation "org.quiltmc:quilt-gradle-licenser:2.+"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -96,14 +97,19 @@ public void finalizeConfiguration() {

private void registerSourceSet(SourceSetContainer sourceSets, String name) {
sourceSets.register(name, sourceSet -> {
sourceSet.setCompileClasspath(sourceSet.getCompileClasspath().plus(sourceSets.getByName("main").getCompileClasspath()));
sourceSet.setRuntimeClasspath(sourceSet.getRuntimeClasspath().plus(sourceSets.getByName("main").getRuntimeClasspath()));
this.addClasspath(sourceSet, sourceSets.getByName("main"));
this.addClasspath(sourceSets.getByName("actualmod"), sourceSet);

var loom = this.project.getExtensions().getByType(LoomGradleExtensionAPI.class);
loom.createRemapConfigurations(sourceSet);
}).get();
}

private void addClasspath(SourceSet source, SourceSet addition) {
source.setCompileClasspath(source.getCompileClasspath().plus(addition.getCompileClasspath()));
source.setRuntimeClasspath(source.getRuntimeClasspath().plus(addition.getRuntimeClasspath()));
}

public static class NamedWriteOnlyList implements Named {
private final String name;
private final ListProperty<Entrypoint> values;
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/dev/lambdaurora/aurorasdeco/block/ShelfBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package dev.lambdaurora.aurorasdeco.block;

import com.google.common.collect.ImmutableMap;
import dev.lambdaurora.aurorasdeco.mixin.block.LockableContainerBlockEntityAccessor;
import dev.lambdaurora.aurorasdeco.registry.AurorasDecoRegistry;
import dev.lambdaurora.aurorasdeco.registry.WoodType;
import dev.lambdaurora.aurorasdeco.util.AuroraUtil;
Expand All @@ -30,6 +31,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.inventory.ContainerLock;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
Expand All @@ -38,6 +40,7 @@
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
import net.minecraft.util.*;
import net.minecraft.util.function.BooleanBiFunction;
import net.minecraft.util.hit.BlockHitResult;
Expand Down Expand Up @@ -227,14 +230,25 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction directio
/* Interaction */

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand,
BlockHitResult hit) {
public ActionResult onUse(
BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit
) {
if (!world.isClient()) {
var shelf = AurorasDecoRegistry.SHELF_BLOCK_ENTITY_TYPE.get(world, pos);

if (shelf != null) {
if (shelf != null && shelf.canPlayerUse(player)) {
var handStack = player.getStackInHand(hand);
if (!handStack.isEmpty()) {

if (shelf.isLocked()) {
player.sendMessage(
Text.translatable("container.isLocked", shelf.getDisplayName()),
true
);
return ActionResult.PASS;
}

if (!handStack.isEmpty()
&& ((LockableContainerBlockEntityAccessor) shelf).getLock().equals(ContainerLock.EMPTY)) {
var facing = state.get(FACING);

int y = 0;
Expand Down Expand Up @@ -270,9 +284,9 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
world.emitGameEvent(player, GameEvent.BLOCK_CHANGE, pos);
return ActionResult.SUCCESS;
}
} else if (shelf.checkUnlocked(player)) {
player.openHandledScreen(shelf);
}

player.openHandledScreen(shelf);
}
}
return ActionResult.SUCCESS;
Expand All @@ -282,7 +296,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
public void onBlockBreakStart(BlockState state, World world, BlockPos pos, PlayerEntity player) {
var shelf = AurorasDecoRegistry.SHELF_BLOCK_ENTITY_TYPE.get(world, pos);

if (shelf != null && !shelf.isEmpty()) {
if (shelf != null && !shelf.isEmpty() && shelf.canPlayerUse(player) && shelf.checkUnlocked(player)) {
Direction facing = state.get(FACING);

var cameraPosVec = player.getCameraPosVec(1.0F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldEvents;
import net.minecraft.world.event.GameEvent;
import org.jetbrains.annotations.Nullable;
import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.loader.api.minecraft.MinecraftQuiltLoader;
Expand All @@ -76,7 +78,7 @@
* Represents a sign post block.
*
* @author LambdAurora
* @version 1.0.0-beta.11
* @version 1.0.0-beta.20
* @since 1.0.0-beta.1
*/
@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -219,6 +221,19 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
if (stack.getItem() instanceof SignPostItem)
return ActionResult.PASS; // Let the item handle it.

if (signPost.isWaxed()) {
world.playSound(null, signPost.getPos(), SoundEvents.BLOCK_SIGN_WAXED_INTERACT_FAIL, SoundCategory.BLOCKS);
return ActionResult.PASS;
}

if (stack.isOf(Items.HONEYCOMB)) {
signPost.setWaxed(true);
world.syncWorldEvent(null, WorldEvents.BLOCK_WAXED, signPost.getPos(), 0);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, signPost.getPos(), GameEvent.Context.create(player, signPost.getCachedState()));
player.incrementStat(Stats.USED.getOrCreateStat(stack.getItem()));
return ActionResult.SUCCESS;
}

boolean handEmpty = stack.isEmpty();
boolean dye = stack.getItem() instanceof DyeItem;
boolean glowInkSac = stack.isOf(Items.GLOW_INK_SAC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.ItemStack;
Expand All @@ -46,12 +47,17 @@
public class ShelfBlockEntity extends LootableContainerBlockEntity
implements ExtendedScreenHandlerFactory, QuiltBlockEntity {
private DefaultedList<ItemStack> inventory;
private boolean locked;

public ShelfBlockEntity(BlockPos pos, BlockState state) {
super(AurorasDecoRegistry.SHELF_BLOCK_ENTITY_TYPE, pos, state);
this.inventory = DefaultedList.ofSize(8, ItemStack.EMPTY);
}

public boolean isLocked() {
return this.locked;
}

@Override
protected Text getContainerName() {
return Text.translatable(this.getCachedState().getBlock().getTranslationKey());
Expand All @@ -71,6 +77,8 @@ public void readNbt(NbtCompound nbt) {
if (!this.deserializeLootTable(nbt)) {
Inventories.readNbt(nbt, this.inventory);
}

this.locked = nbt.getBoolean("locked");
}

@Override
Expand All @@ -79,6 +87,8 @@ public void writeNbt(NbtCompound nbt) {
if (!this.serializeLootTable(nbt)) {
Inventories.writeNbt(nbt, this.inventory);
}

nbt.putBoolean("locked", this.locked);
}

@Override
Expand Down Expand Up @@ -125,4 +135,9 @@ public boolean isValid(int slot, ItemStack stack) {
public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf) {
buf.writeEnumConstant(this.getCachedState().get(ShelfBlock.TYPE));
}

@Override
public boolean checkUnlocked(PlayerEntity player) {
return !this.locked && super.checkUnlocked(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@
* Represents the sign post block entity.
*
* @author LambdAurora
* @version 1.0.0-beta.12
* @version 1.0.0-beta.20
* @since 1.0.0-beta.1
*/
public class SignPostBlockEntity extends BasicBlockEntity {
private Sign up;
private Sign down;
private GenerationSettings generationSettings;
private boolean waxed;
@Nullable
private UUID editor;

Expand Down Expand Up @@ -84,6 +85,17 @@ public void putSignDown(SignPostItem item, Text text, float yaw) {
return up ? this.up : this.down;
}

public boolean isWaxed() {
return this.waxed;
}

public void setWaxed(boolean waxed) {
if (this.waxed != waxed) {
this.waxed = waxed;
this.attemptToSync();
}
}

/* Generation settings */

public GenerationSettings getGenerationSettings() {
Expand Down Expand Up @@ -166,6 +178,7 @@ private void attemptToSync() {
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);
this.readSignPostNbt(nbt);
this.waxed = nbt.getBoolean("waxed");

if (nbt.contains("generation_settings", NbtElement.COMPOUND_TYPE)) {
this.generationSettings = GenerationSettings.fromNbt(nbt.getCompound("generation_settings"));
Expand All @@ -176,6 +189,7 @@ public void readNbt(NbtCompound nbt) {
public void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);
this.writeSignPostNbt(nbt);
nbt.putBoolean("waxed", this.waxed);

if (this.generationSettings != null) {
nbt.put("generation_settings", this.generationSettings.toNbt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import org.quiltmc.qsl.lifecycle.api.client.event.ClientWorldTickEvents;
import org.quiltmc.qsl.networking.api.client.ClientPlayNetworking;
import org.quiltmc.qsl.resource.loader.api.ResourceLoader;
import org.quiltmc.qsl.resource.loader.api.reloader.ResourceReloaderKeys;

import static dev.lambdaurora.aurorasdeco.registry.AurorasDecoRegistry.*;

Expand Down Expand Up @@ -158,11 +157,14 @@ public void onInitializeClient(ModContainer mod) {
WindChimeBlockEntityRenderer::getTexturedModelData);

ResourceLoader resourceLoader = ResourceLoader.get(ResourceType.CLIENT_RESOURCES);
resourceLoader.registerReloader(new RenderRule.Reloader());
resourceLoader.addReloaderOrdering(RenderRule.Reloader.ID, ResourceReloaderKeys.BEFORE_VANILLA);
resourceLoader.getRegisterDefaultResourcePackEvent().register(context -> {
context.addResourcePack(AurorasDecoClient.RESOURCE_PACK.rebuild(ResourceType.CLIENT_RESOURCES, context.resourceManager()));
});
resourceLoader.getRegisterTopResourcePackEvent().register(AurorasDeco.id("reload/render_rules"),
context -> {
RenderRule.reload(context.resourceManager());
}
);

ModelLoadingPlugin.register(context -> {
RenderRule.addModels(context);
Expand Down
Loading

0 comments on commit 72b399e

Please sign in to comment.