Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ minecraft {

dependencies {
compileOnly("org.spongepowered:mixin:0.8.5")
// This is just the eventbus implementation from neoforge, it does not require
// the rest of neoforge.
api("net.neoforged:bus:8.0.5")
}

configurations {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.jaquadro.minecraft.storagedrawers.api.event;

import com.jaquadro.minecraft.storagedrawers.block.tile.BaseBlockEntity;
import net.minecraft.core.BlockPos;
import net.neoforged.bus.api.Event;

public class INetworkedLoadedEvent extends Event {
private final BlockPos pos;
private final BaseBlockEntity entity;

public INetworkedLoadedEvent(BaseBlockEntity entity, BlockPos pos) {
this.pos = pos;
this.entity = entity;
}

public BlockPos getPos() {
return pos;
}

public BaseBlockEntity getEntity() {
return entity;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.jaquadro.minecraft.storagedrawers.api.event;

import com.jaquadro.minecraft.storagedrawers.block.tile.BaseBlockEntity;
import net.minecraft.core.BlockPos;
import net.neoforged.bus.api.Event;

public class INetworkedUnloadedEvent extends Event {
private final BlockPos pos;
private final BaseBlockEntity entity;

public INetworkedUnloadedEvent(BaseBlockEntity entity, BlockPos pos) {
this.entity = entity;
this.pos = pos;
}

public BlockPos getPos() {
return pos;
}

public BaseBlockEntity getEntity() {
return entity;
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.jaquadro.minecraft.storagedrawers.block.tile;

import com.jaquadro.minecraft.storagedrawers.api.event.INetworkedLoadedEvent;
import com.jaquadro.minecraft.storagedrawers.api.event.INetworkedUnloadedEvent;
import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked;
import com.jaquadro.minecraft.storagedrawers.block.tile.tiledata.BlockEntityDataShim;
import com.jaquadro.minecraft.storagedrawers.core.ModINetworkedLocations;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -29,6 +33,22 @@ public BaseBlockEntity (BlockEntityType<?> blockEntityType, BlockPos pos, BlockS
super(blockEntityType, pos, state);
}

@Override
public void setRemoved () {
BlockPos pos = getBlockPos();
super.setRemoved();
if (this instanceof INetworked && getLevel() != null && !getLevel().isClientSide()) {
ModINetworkedLocations.EVENT_BUS.post(new INetworkedUnloadedEvent(this, pos));
}
}

public void onEntityLoad() {
if (this instanceof INetworked && getLevel() != null && !getLevel().isClientSide()) {
BlockPos ourPos = getBlockPos();
ModINetworkedLocations.EVENT_BUS.post(new INetworkedLoadedEvent(this, ourPos));
}
}

public boolean hasDataPacket () {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.jaquadro.minecraft.storagedrawers.ModServices;
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
import com.jaquadro.minecraft.storagedrawers.api.event.INetworkedUnloadedEvent;
import com.jaquadro.minecraft.storagedrawers.api.framing.IFramedBlockEntity;
import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider;
import com.jaquadro.minecraft.storagedrawers.api.storage.*;
Expand All @@ -17,16 +18,14 @@
import com.jaquadro.minecraft.storagedrawers.capabilities.DrawerItemRepository;
import com.jaquadro.minecraft.storagedrawers.config.ModCommonConfig;
import com.jaquadro.minecraft.storagedrawers.core.ModBlockEntities;
import com.jaquadro.minecraft.storagedrawers.core.ModBlocks;
import com.jaquadro.minecraft.storagedrawers.core.ModINetworkedLocations;
import com.jaquadro.minecraft.storagedrawers.security.SecurityManager;
import com.jaquadro.minecraft.storagedrawers.storage.StorageUtil;
import com.jaquadro.minecraft.storagedrawers.util.ItemCollectionRegistry;
import com.texelsaurus.minecraft.chameleon.util.WorldUtils;
import com.mojang.authlib.GameProfile;
import com.texelsaurus.minecraft.chameleon.capabilities.ChameleonCapability;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -117,8 +116,6 @@ public int compareTo (SlotRecord other) {
}
}

private final Queue<BlockPos> searchQueue = new LinkedList<>();
private final Set<BlockPos> searchDiscovered = new HashSet<>();
private final Comparator<SlotRecord> slotRecordComparator = (o1, o2) -> {
if (o1.priorityGroup != o2.priorityGroup)
return o2.priorityGroup - o1.priorityGroup;
Expand Down Expand Up @@ -298,10 +295,12 @@ public boolean isSoftBindingValid (BlockPos pos, IDrawerGroup node) {
return record.storage == node;
}

@Override
public void onEntityLoad () {
if (ModCommonConfig.INSTANCE.GENERAL.debugTrace.get())
ModServices.log.info("controller [{}] onEntityLoad", worldPosition);

super.onEntityLoad();
if (getLevel() == null || getLevel().isClientSide())
return;

Expand Down Expand Up @@ -753,9 +752,6 @@ private void populateNodes () {
if (getLevel() == null)
return;

searchQueue.clear();
searchDiscovered.clear();

if (!getLevel().isClientSide())
controllerHostData.validateRemoteNodes(this, level);

Expand All @@ -766,66 +762,53 @@ private void populateNodes () {
int remoteRange = confRemoteRange > 0 ? Math.min(globalRange, confRemoteRange) : globalRange;
int remoteGroupRange = confRemoteGroupRange > 0 ? Math.min(globalRange, confRemoteGroupRange) : globalRange;

populateRoot(getBlockPos(), globalRange, true);
populateRoot(getBlockPos(), globalRange);

getBoundRemoteNodes().forEach(n -> {
if (n.getBoundControlGroup() == this && n instanceof BlockEntity blockEntity) {
boolean recurse = n.canRecurseSearch();
int range = recurse ? remoteGroupRange : remoteRange;
populateRoot(blockEntity.getBlockPos(), range, recurse);
populateRoot(blockEntity.getBlockPos(), range);
}
});
}

private void populateRoot (BlockPos root, int range, boolean recursiveSearch) {
searchQueue.add(root);
searchDiscovered.add(root);
private void populateRoot (BlockPos root, int range) {

BlockPos origin = getBlockPos();

while (!searchQueue.isEmpty()) {
BlockPos coord = searchQueue.remove();
int depth = Math.max(Math.max(Math.abs(coord.getX() - origin.getX()), Math.abs(coord.getY() - origin.getY())), Math.abs(coord.getZ() - origin.getZ()));
if (depth > range)
continue;
// Ask for the drawer locations that are in range
if (ModCommonConfig.INSTANCE.GENERAL.debugTrace.get())
ModServices.log.info("Controller [{}] searching for drawers in range {}", origin, range);

if (!getLevel().isLoaded(coord))
var networkedThingsInRange = ModINetworkedLocations.getINetworkedLocationsInRange(origin, range);
if (ModCommonConfig.INSTANCE.GENERAL.debugTrace.get())
ModServices.log.info("Controller [{}] found {} drawers in range", origin, networkedThingsInRange.size());
for (var pos: networkedThingsInRange) {
if (!getLevel().isLoaded(pos))
continue;

Block block = getLevel().getBlockState(coord).getBlock();
Block block = getLevel().getBlockState(pos).getBlock();
if (block instanceof INetworked networked) {
IControlGroup group = networked.getBoundControlGroup();
if (group != null && group != this)
continue;
} else
continue;

StorageRecord record = storage.get(coord);
StorageRecord record = storage.get(pos);
if (record == null) {
record = new StorageRecord();
storage.put(coord, record);
storage.put(pos, record);
}

if (block instanceof BlockControllerIO) {
WorldUtils.getBlockEntity(getLevel(), coord, BlockEntityControllerIO.class);
WorldUtils.getBlockEntity(getLevel(), pos, BlockEntityControllerIO.class);
}

updateRecordInfo(coord, record, getLevel().getBlockEntity(coord));
updateRecordInfo(pos, record, getLevel().getBlockEntity(pos));
record.mark = true;
record.distance = depth;

if (recursiveSearch) {
BlockPos[] neighbors = new BlockPos[]{
coord.west(), coord.east(), coord.south(), coord.north(), coord.above(), coord.below()
};

for (BlockPos n : neighbors) {
if (!searchDiscovered.contains(n)) {
searchQueue.add(n);
searchDiscovered.add(n);
}
}
}
record.distance = Math.max(Math.max(Math.abs(pos.getX() - origin.getX()), Math.abs(pos.getY() - origin.getY())), Math.abs(pos.getZ() - origin.getZ()));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jaquadro.minecraft.storagedrawers.block.tile;

import com.jaquadro.minecraft.storagedrawers.ModServices;
import com.jaquadro.minecraft.storagedrawers.api.event.*;
import com.jaquadro.minecraft.storagedrawers.api.framing.IFramedBlockEntity;
import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider;
import com.jaquadro.minecraft.storagedrawers.api.storage.*;
Expand All @@ -11,14 +12,14 @@
import com.jaquadro.minecraft.storagedrawers.block.tile.modelprops.DrawerModelProperties;
import com.jaquadro.minecraft.storagedrawers.block.tile.modelprops.RenderDataProvider;
import com.jaquadro.minecraft.storagedrawers.block.tile.tiledata.ControllerData;
import com.jaquadro.minecraft.storagedrawers.block.tile.tiledata.DetachedDrawerData;
import com.jaquadro.minecraft.storagedrawers.block.tile.tiledata.MaterialData;
import com.jaquadro.minecraft.storagedrawers.block.tile.tiledata.UpgradeData;
import com.jaquadro.minecraft.storagedrawers.capabilities.BasicDrawerAttributes;
import com.jaquadro.minecraft.storagedrawers.capabilities.Capabilities;
import com.jaquadro.minecraft.storagedrawers.components.item.DetachedDrawerContents;
import com.jaquadro.minecraft.storagedrawers.config.ModCommonConfig;
import com.jaquadro.minecraft.storagedrawers.core.ModDataComponents;
import com.jaquadro.minecraft.storagedrawers.core.ModINetworkedLocations;
import com.jaquadro.minecraft.storagedrawers.core.ModItems;
import com.jaquadro.minecraft.storagedrawers.core.ModSecurity;
import com.jaquadro.minecraft.storagedrawers.inventory.*;
Expand All @@ -33,18 +34,15 @@
import com.texelsaurus.minecraft.chameleon.inventory.content.PositionContent;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Vec3i;
import net.minecraft.core.component.DataComponentGetter;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentSerialization;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.ProblemReporter;
import net.minecraft.world.Nameable;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySelector;
Expand All @@ -53,14 +51,12 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.storage.TagValueInput;
import net.minecraft.world.level.storage.ValueInput;
import net.minecraft.world.level.storage.ValueOutput;
import net.minecraft.world.phys.AABB;
Expand All @@ -71,8 +67,6 @@

import java.util.*;

import static com.ibm.icu.impl.CurrencyData.provider;

public abstract class BlockEntityDrawers extends BaseBlockEntity implements IDrawerGroup, IProtectable, INetworked, IFramedBlockEntity, Nameable, RenderDataProvider
{
private MaterialData materialData = new MaterialData();
Expand Down Expand Up @@ -266,6 +260,7 @@ public void validateBoundController() {
}

public void onEntityLoad () {
super.onEntityLoad();
try {
if (getLevel() == null || getLevel().isClientSide())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
public final class ModCommonConfig extends ConfigSpec
{
public static ModCommonConfig INSTANCE = new ModCommonConfig();

private final ChameleonConfig commonConfig;
public General GENERAL;
public Drawers DRAWERS;
Expand Down
Loading