Skip to content

Commit

Permalink
Unify is_locked property for Hydrogen compatibility (#48)
Browse files Browse the repository at this point in the history
* Unify `is_locked` property for Hydrogen compatibility

Closes #47

* [2.0.0-beta.4.1] Bump version
  • Loading branch information
magneticflux- authored Jan 15, 2022
1 parent 2333587 commit e47e028
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1G
fabric_version=0.44.0+1.18

# Mod Properties
mod_version = 2.0.0-beta.4+1.18.1
mod_version = 2.0.0-beta.4.1+1.18.1
maven_group = eu.pb4
archives_base_name = graves

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/eu/pb4/graves/client/GraveRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import eu.pb4.graves.registry.AbstractGraveBlockEntity;
import eu.pb4.graves.registry.GraveBlock;
import net.fabricmc.fabric.api.client.model.BakedModelManagerHelper;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
Expand All @@ -16,7 +15,6 @@
import net.minecraft.client.render.entity.model.EntityModelLayers;
import net.minecraft.client.render.entity.model.SkullEntityModel;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BasicBakedModel;
import net.minecraft.client.util.DefaultSkinHelper;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -28,6 +26,8 @@
import java.util.Map;
import java.util.Random;

import static eu.pb4.graves.registry.AbstractGraveBlock.IS_LOCKED;

public class GraveRenderer implements BlockEntityRenderer<AbstractGraveBlockEntity> {
public static final Identifier GENERIC_GRAVE = new Identifier("universal_graves", "grave/generic");
public static final Identifier GENERIC_UNLOCKED_GRAVE = new Identifier("universal_graves", "grave/generic_unlocked");
Expand Down Expand Up @@ -74,7 +74,7 @@ public void renderHead(AbstractGraveBlockEntity entity, float tickDelta, MatrixS
matrixStack.translate(0.5D, blockModelEnabled ? 0.1D : 0, 0.5D);
matrixStack.scale(-1.0F, -1.0F, 1.0F);
var rotation = 22.5F * entity.getCachedState().get(Properties.ROTATION);
var useSkull = GravesModClient.config.playerHeadsTurnSkull() && !entity.getCachedState().get(GraveBlock.IS_LOCKED);
var useSkull = GravesModClient.config.playerHeadsTurnSkull() && !entity.getCachedState().get(IS_LOCKED);

var model = useSkull ? this.skullModel : this.playerHeadModel;

Expand Down Expand Up @@ -122,7 +122,7 @@ public void renderGrave(AbstractGraveBlockEntity entity, float tickDelta, Matrix
}
}

var model = entity.getCachedState().get(GraveBlock.IS_LOCKED) ? this.graveStoneModel : this.graveStoneUnlockedModel;
var model = entity.getCachedState().get(IS_LOCKED) ? this.graveStoneModel : this.graveStoneUnlockedModel;

if (MinecraftClient.isAmbientOcclusionEnabled() && model.useAmbientOcclusion()) {
renderer.renderSmooth(world, model, entity.getCachedState(), entity.getPos(), matrixStack, vertexConsumers.getBuffer(RenderLayers.getBlockLayer(entity.getCachedState())), false, new Random(), 0, overlay);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/eu/pb4/graves/registry/AbstractGraveBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import eu.pb4.graves.grave.Grave;
import eu.pb4.graves.other.VisualGraveData;
import eu.pb4.polymer.api.block.PlayerAwarePolymerBlock;
import eu.pb4.polymer.api.block.PolymerBlockUtils;
import eu.pb4.polymer.api.client.PolymerClientDecoded;
import eu.pb4.polymer.api.client.PolymerKeepModel;
import eu.pb4.polymer.api.utils.PolymerUtils;
Expand Down Expand Up @@ -55,7 +54,7 @@ public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos
if (!PolymerUtils.isOnClientSide() && context instanceof EntityShapeContext entityShapeContext && entityShapeContext.getEntity() instanceof ServerPlayerEntity player) {
return ConfigManager.getConfig().style.converter.getBlockState(
state.get(Properties.ROTATION),
state.get(AbstractGraveBlock.IS_LOCKED),
state.get(IS_LOCKED),
state.get(Properties.WATERLOGGED),
player
).getCollisionShape(world, pos, context);
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/eu/pb4/graves/registry/GraveBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
Expand All @@ -27,8 +26,6 @@

@SuppressWarnings({"deprecation"})
public class GraveBlock extends AbstractGraveBlock implements BlockEntityProvider {
public static BooleanProperty IS_LOCKED = BooleanProperty.of("is_locked");

public static GraveBlock INSTANCE = new GraveBlock();

private GraveBlock() {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/eu/pb4/graves/registry/GraveBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
Expand All @@ -35,6 +34,8 @@

import java.util.*;

import static eu.pb4.graves.registry.AbstractGraveBlock.IS_LOCKED;

public class GraveBlockEntity extends AbstractGraveBlockEntity {
public static BlockEntityType<GraveBlockEntity> BLOCK_ENTITY_TYPE;
public WorldHologram hologram = null;
Expand Down Expand Up @@ -181,10 +182,10 @@ public static <T extends BlockEntity> void tick(World world, BlockPos pos, Block
return;
}

boolean isProtected = state.get(GraveBlock.IS_LOCKED);
boolean isProtected = state.get(IS_LOCKED);

if (isProtected && !self.data.isProtected()) {
world.setBlockState(pos, state.with(GraveBlock.IS_LOCKED, false));
world.setBlockState(pos, state.with(IS_LOCKED, false));
isProtected = false;
self.updateForAllPlayers();
}
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/eu/pb4/graves/registry/VisualGraveBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.*;
import net.minecraft.loot.context.LootContext;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
Expand All @@ -37,16 +35,12 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Map;

@SuppressWarnings({"deprecation"})
public class VisualGraveBlock extends AbstractGraveBlock implements BlockEntityProvider {
public static BooleanProperty IS_LOCKED = GraveBlock.IS_LOCKED;

public static VisualGraveBlock INSTANCE = new VisualGraveBlock();

private VisualGraveBlock() {
Expand Down Expand Up @@ -193,9 +187,9 @@ public void onClose() {
grave.getGrave().location()), grave.replacedBlockState, true);
}
} else if (itemStack.getItem() == Items.MOSS_BLOCK) {
world.setBlockState(pos, state.with(GraveBlock.IS_LOCKED, false));
world.setBlockState(pos, state.with(IS_LOCKED, false));
} else if (itemStack.getItem() == Items.SPONGE || itemStack.getItem() == Items.WET_SPONGE) {
world.setBlockState(pos, state.with(GraveBlock.IS_LOCKED, true));
world.setBlockState(pos, state.with(IS_LOCKED, true));
} else if (itemStack.getItem() instanceof ShovelItem) {
int val = state.get(Properties.ROTATION) + (player.isSneaking() ? -1 : 1);
if (val < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import java.util.*;

import static eu.pb4.graves.registry.AbstractGraveBlock.IS_LOCKED;

public class VisualGraveBlockEntity extends AbstractGraveBlockEntity {
public static BlockEntityType<VisualGraveBlockEntity> BLOCK_ENTITY_TYPE;
public WorldHologram hologram = null;
Expand Down Expand Up @@ -90,7 +92,7 @@ protected void updateForAllPlayers() {

var converter = ConfigManager.getConfig().style.converter;
var rotation = this.getCachedState().get(Properties.ROTATION);
var isProtected = this.getCachedState().get(VisualGraveBlock.IS_LOCKED);
var isProtected = this.getCachedState().get(IS_LOCKED);
for (var player : ((ServerWorld) this.world).getChunkManager().threadedAnvilChunkStorage.getPlayersWatchingChunk(new ChunkPos(this.pos), false)) {
if (!GraveNetworking.sendGrave(player.networkHandler, pos, isProtected, this.visualData, this.visualData.getPlaceholders(player.server), this.textOverrides)) {
converter.sendNbt(player, this.getCachedState(), pos.toImmutable(), rotation, isProtected, this.visualData, null, this.textOverrides);
Expand Down

0 comments on commit e47e028

Please sign in to comment.