Skip to content

Commit

Permalink
Handheld storages now have a open state and open/close along with all…
Browse files Browse the repository at this point in the history
… other inventories
  • Loading branch information
kyrptonaught committed Dec 30, 2019
1 parent 80d5c71 commit 12f1bed
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import net.minecraft.util.Identifier;

public class LinkedStorageModClient implements ClientModInitializer {
public static final Identifier TEXTURE = new Identifier(LinkedStorageMod.MOD_ID, "block/chest");
public static final Identifier TEXTURE = new Identifier(LinkedStorageMod.MOD_ID, "block/linkedstorage");
public static BlockEntityType<DummyStorageBlockEntity> dummy = BlockEntityType.Builder.create(DummyStorageBlockEntity::new, ModBlocks.storageBlock).build(null);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public float getAnimationProgress(float f) {
@Override
@Environment(EnvType.CLIENT)
public void tick() {
System.out.println(world.isClient);
if (world != null && world.isClient) {
int viewerCount = countViewers();
lastAnimationAngle = animationAngle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.kyrptonaught.linkedstorage.LinkedStorageMod;
import net.kyrptonaught.linkedstorage.block.StorageBlock;
import net.kyrptonaught.linkedstorage.inventory.LinkedInventoryHelper;
import net.kyrptonaught.linkedstorage.network.ChannelViewers;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
Expand All @@ -23,6 +24,10 @@ public class StorageItem extends Item {
public StorageItem(Settings item$Settings_1) {
super(item$Settings_1);
Registry.register(Registry.ITEM, new Identifier(LinkedStorageMod.MOD_ID, "storageitem"), this);
this.addPropertyGetter(new Identifier("open"), (stack, world, entity) -> {
String channel = LinkedInventoryHelper.getChannelName(LinkedInventoryHelper.getItemChannelOrDefault(stack));
return ChannelViewers.getViewersFor(channel) ? 1 : 0;
});
}

@Override
Expand All @@ -41,10 +46,8 @@ public ActionResult useOnBlock(ItemUsageContext context) {
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
ItemStack stack = playerEntity.getStackInHand(hand);
if (!world.isClient) {
if (LinkedInventoryHelper.itemHasChannel(stack)) {
byte[] channel = LinkedInventoryHelper.getItemChannel(stack);
ContainerProviderRegistry.INSTANCE.openContainer(new Identifier(LinkedStorageMod.MOD_ID, "linkedstorage"), playerEntity, (buf) -> buf.writeByteArray(channel));
}
byte[] channel = LinkedInventoryHelper.getItemChannelOrDefault(stack);
ContainerProviderRegistry.INSTANCE.openContainer(new Identifier(LinkedStorageMod.MOD_ID, "linkedstorage"), playerEntity, (buf) -> buf.writeByteArray(channel));
}
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
}
Expand Down
Loading

0 comments on commit 12f1bed

Please sign in to comment.