Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Its-Cryptic authored and mrsterner committed May 28, 2024
1 parent 4db6f6c commit d01dd31
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parchment_version=2023.09.03-1.20.1
# Mod Properties
mod_name=Lodestone
mod_id=lodestone
mod_version=1.4.33
mod_version=1.4.34
mod_license=GPLv3
mod_group_id=team.lodestar.lodestone
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import io.github.fabricators_of_create.porting_lib.block.CustomDataPacketHandlingBlockEntity;
import io.github.fabricators_of_create.porting_lib.block.CustomUpdateTagHandlingBlockEntity;
import io.github.fabricators_of_create.porting_lib.extensions.extensions.BlockEntityExtensions;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
Expand All @@ -17,13 +22,14 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import org.jetbrains.annotations.Nullable;
import team.lodestar.lodestone.systems.block.LodestoneEntityBlock;

/**
* A simple block entity with various frequently used methods called from {@link LodestoneEntityBlock}
*/
public class LodestoneBlockEntity extends BlockEntity implements CustomUpdateTagHandlingBlockEntity, CustomDataPacketHandlingBlockEntity {
public class LodestoneBlockEntity extends BlockEntity implements BlockEntityExtensions, CustomUpdateTagHandlingBlockEntity, CustomDataPacketHandlingBlockEntity {

public boolean needsSync;

Expand Down Expand Up @@ -54,21 +60,26 @@ public void onEntityInside(BlockState state, Level level, BlockPos pos, Entity e
}

@Override
public CompoundTag getUpdateTag() {
return this.saveWithoutMetadata();
public void load(CompoundTag pTag) {
needsSync = true;
super.load(pTag);
}

@Override
public void handleUpdateTag(CompoundTag tag) {
if (tag != null) {
CustomUpdateTagHandlingBlockEntity.super.handleUpdateTag(tag);
public void tick() {
if (needsSync) {
init();
needsSync = false;
}
}

public void init() {

}

//Sync
@Override
public void load(CompoundTag pTag) {
needsSync = true;
super.load(pTag);
public CompoundTag getUpdateTag() {
return writeClient(new CompoundTag());
}

@Override
Expand All @@ -77,18 +88,43 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() {
}

@Override
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
handleUpdateTag(getUpdatePacket().getTag());
public void handleUpdateTag(CompoundTag tag) {
readClient(tag);
}

public void tick() {
if (needsSync) {
init();
needsSync = false;
}
@Override
public void onDataPacket(Connection connection, ClientboundBlockEntityDataPacket packet) {
CompoundTag tag = packet.getTag();
readClient(tag == null ? new CompoundTag() : tag);
}

public void init() {
// Special handling for client update packets
public void readClient(CompoundTag tag) {
load(tag);
}

// Special handling for client update packets
public CompoundTag writeClient(CompoundTag tag) {
saveAdditional(tag);
return tag;
}

public void sendData() {
if (level instanceof ServerLevel serverLevel)
serverLevel.getChunkSource().blockChanged(getBlockPos());
}

public void notifyUpdate() {
setChanged();
sendData();
}

public LevelChunk containedChunk() {
return level.getChunkAt(worldPosition);
}

@Override
public void deserializeNBT(BlockState state, CompoundTag nbt) {
this.load(nbt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class LodestoneBlockEntityInventory extends ItemStackHandlerContainer {
public int nonEmptyItemAmount;
public int firstEmptyItemIndex;

private LodestoneBlockEntity blockEntity;

public LodestoneBlockEntityInventory(int slotCount, int allowedItemSize, Predicate<ItemStack> inputPredicate, Predicate<ItemStack> outputPredicate) {
this(slotCount, allowedItemSize, inputPredicate);
this.outputPredicate = outputPredicate;
Expand All @@ -56,6 +58,11 @@ public boolean isEmpty() {
return nonEmptyItemAmount == 0;
}

@Override
public void setChanged() {
super.setChanged();
}

public void clear() {
for (int i = 0; i < slotCount; i++) {
setStackInSlot(i, ItemStack.EMPTY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 150

#moj_import <fog.glsl>
#moj_import <lodestone:commoner.glsl>
#moj_import <lodestone:common_math.glsl>

uniform sampler2D Sampler0;
uniform sampler2D SceneDepthBuffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#moj_import <fog.glsl>
#moj_import <projection.glsl>
#moj_import <lodestone:commoner.glsl>
#moj_import <lodestone:common_math.glsl>

in vec3 Position;
in vec2 UV0;
Expand Down

0 comments on commit d01dd31

Please sign in to comment.