Skip to content

Commit

Permalink
Split lootr integration into client/server
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Dec 6, 2023
1 parent 3a8233f commit 1eec7c0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 32 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/violetmoon/quark/base/QuarkClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.violetmoon.quark.base;

import org.violetmoon.quark.integration.lootr.client.ClientLootrIntegration;
import org.violetmoon.quark.integration.lootr.client.IClientLootrIntegration;
import org.violetmoon.zeta.client.ClientTicker;
import org.violetmoon.zeta.client.ZetaClient;
import org.violetmoon.zeta.util.ZetaSide;
Expand All @@ -21,6 +23,10 @@ public class QuarkClient {
public static final String INV_GROUP = "quark.gui.keygroup.inv";
public static final String EMOTE_GROUP = "quark.gui.keygroup.emote";

public static final IClientLootrIntegration LOOTR_INTEGRATION = Quark.ZETA.modIntegration("lootr",
() -> ClientLootrIntegration::new,
() -> IClientLootrIntegration.Dummy::new);

public static void start() {
instance = new QuarkClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ public final void clientSetup(ZClientSetup event) {
BlockEntityRenderers.register(chestTEType, ctx -> new VariantChestRenderer(ctx, false));
BlockEntityRenderers.register(trappedChestTEType, ctx -> new VariantChestRenderer(ctx, true));

Quark.LOOTR_INTEGRATION.clientSetup();

for(Block b : regularChests)
QuarkClient.ZETA_CLIENT.setBlockEntityWithoutLevelRenderer(b.asItem(), new SimpleWithoutLevelRenderer(chestTEType, b.defaultBlockState()));
for(Block b : trappedChests)
QuarkClient.ZETA_CLIENT.setBlockEntityWithoutLevelRenderer(b.asItem(), new SimpleWithoutLevelRenderer(trappedChestTEType, b.defaultBlockState()));

QuarkClient.LOOTR_INTEGRATION.clientSetup(event);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.module.ZetaModule;
Expand Down Expand Up @@ -38,11 +36,6 @@ default void postRegister() {
// NO-OP
}

@OnlyIn(Dist.CLIENT)
default void clientSetup() {
// NO-OP
}

class Dummy implements ILootrIntegration { }

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package org.violetmoon.quark.integration.lootr;

import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.QuarkClient;
import org.violetmoon.quark.integration.lootr.client.LootrVariantChestRenderer;
import org.violetmoon.zeta.client.SimpleWithoutLevelRenderer;
import org.violetmoon.zeta.module.ZetaModule;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.BooleanSupplier;
Expand All @@ -28,13 +21,13 @@
*/
public class LootrIntegration implements ILootrIntegration {

private BlockEntityType<LootrVariantChestBlockEntity> chestTEType;
private BlockEntityType<LootrVariantTrappedChestBlockEntity> trappedChestTEType;
public BlockEntityType<LootrVariantChestBlockEntity> chestTEType;
public BlockEntityType<LootrVariantTrappedChestBlockEntity> trappedChestTEType;

private final Map<Block, Block> chestMappings = new HashMap<>();
public final Map<Block, Block> chestMappings = new HashMap<>();

private final List<Block> lootrRegularChests = new ArrayList<>();
private final List<Block> lootrTrappedChests = new ArrayList<>();
public final List<Block> lootrRegularChests = new ArrayList<>();
public final List<Block> lootrTrappedChests = new ArrayList<>();

@Override
public BlockEntityType<? extends ChestBlockEntity> chestTE() {
Expand Down Expand Up @@ -73,15 +66,4 @@ public void postRegister() {
Quark.ZETA.registry.register(trappedChestTEType, "lootr_variant_trapped_chest", Registries.BLOCK_ENTITY_TYPE);
}

@Override
@OnlyIn(Dist.CLIENT)
public void clientSetup() {
BlockEntityRenderers.register(chestTEType, ctx -> new LootrVariantChestRenderer<>(ctx, false));
BlockEntityRenderers.register(trappedChestTEType, ctx -> new LootrVariantChestRenderer<>(ctx, true));

for(Block b : lootrRegularChests)
QuarkClient.ZETA_CLIENT.setBlockEntityWithoutLevelRenderer(b.asItem(), new SimpleWithoutLevelRenderer(chestTEType, b.defaultBlockState()));
for(Block b : lootrTrappedChests)
QuarkClient.ZETA_CLIENT.setBlockEntityWithoutLevelRenderer(b.asItem(), new SimpleWithoutLevelRenderer(trappedChestTEType, b.defaultBlockState()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.violetmoon.quark.integration.lootr.client;

import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.world.level.block.Block;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.QuarkClient;
import org.violetmoon.quark.integration.lootr.LootrIntegration;
import org.violetmoon.zeta.client.SimpleWithoutLevelRenderer;
import org.violetmoon.zeta.client.event.load.ZClientSetup;

public class ClientLootrIntegration implements IClientLootrIntegration {

private final LootrIntegration real = (LootrIntegration) Quark.LOOTR_INTEGRATION;

@Override
public void clientSetup(ZClientSetup event) {
BlockEntityRenderers.register(real.chestTEType, ctx -> new LootrVariantChestRenderer<>(ctx, false));
BlockEntityRenderers.register(real.trappedChestTEType, ctx -> new LootrVariantChestRenderer<>(ctx, true));

for(Block b : real.lootrRegularChests)
QuarkClient.ZETA_CLIENT.setBlockEntityWithoutLevelRenderer(b.asItem(), new SimpleWithoutLevelRenderer(real.chestTEType, b.defaultBlockState()));
for(Block b : real.lootrTrappedChests)
QuarkClient.ZETA_CLIENT.setBlockEntityWithoutLevelRenderer(b.asItem(), new SimpleWithoutLevelRenderer(real.trappedChestTEType, b.defaultBlockState()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.violetmoon.quark.integration.lootr.client;

import org.violetmoon.zeta.client.event.load.ZClientSetup;

public interface IClientLootrIntegration {

default void clientSetup(ZClientSetup event) {

}

class Dummy implements IClientLootrIntegration { }

}

0 comments on commit 1eec7c0

Please sign in to comment.