Skip to content

Commit

Permalink
DyeablesRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Oct 26, 2023
1 parent ba294a6 commit d6ad830
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 194 deletions.
161 changes: 0 additions & 161 deletions src/main/java/vazkii/quark/base/handler/DyeHandler.java

This file was deleted.

2 changes: 0 additions & 2 deletions src/main/java/vazkii/quark/base/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import vazkii.quark.base.client.handler.RequiredModTooltipHandler;
import vazkii.zeta.client.TopLayerTooltipHandler;
import vazkii.quark.base.handler.ContributorRewardHandler;
import vazkii.quark.base.handler.DyeHandler;
import vazkii.quark.base.handler.MiscUtil;
import vazkii.quark.base.handler.RenderLayerHandler;
import vazkii.quark.base.handler.WoodSetHandler;
Expand Down Expand Up @@ -59,7 +58,6 @@ public void start() {

Quark.ZETA.loadBus
.subscribe(ContributorRewardHandler.Client.class)
.subscribe(DyeHandler.Client.class)
.subscribe(RenderLayerHandler.Client.class)
.subscribe(WoodSetHandler.Client.class);

Expand Down
1 change: 0 additions & 1 deletion src/main/java/vazkii/quark/base/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public void start() {
.subscribe(BrewingHandler.class)
.subscribe(ContributorRewardHandler.class)
.subscribe(CreativeTabHandler.class)
.subscribe(DyeHandler.class)
.subscribe(ModuleLoader.INSTANCE)
.subscribe(QuarkNetwork.class)
.subscribe(QuarkSounds.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import vazkii.quark.base.handler.DyeHandler;
import vazkii.quark.base.Quark;
import vazkii.quark.content.tweaks.module.DyeableItemFramesModule;

public class DyedItemFrame extends ItemFrame {
Expand Down Expand Up @@ -94,7 +94,7 @@ public SoundEvent getRotateItemSound() {
@Override
protected ItemStack getFrameItemStack() {
ItemStack stack = new ItemStack(isGlow() ? Items.GLOW_ITEM_FRAME : Items.ITEM_FRAME);
DyeHandler.applyDye(stack, getColor());
Quark.ZETA.dyeables.applyDye(stack, getColor());

return stack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import vazkii.quark.base.Quark;
import vazkii.quark.base.handler.DyeHandler;
import vazkii.quark.base.module.LoadModule;
import vazkii.zeta.module.ZetaModule;
import vazkii.quark.base.module.hint.Hint;
Expand Down Expand Up @@ -56,10 +55,10 @@ public final void register(ZRegister event) {
.setShouldReceiveVelocityUpdates(false)
.setCustomClientFactory((spawnEntity, world) -> new DyedItemFrame(entityType, world))
.build("dyed_item_frame");
Quark.ZETA.registry.register(entityType, "dyed_item_frame", Registry.ENTITY_TYPE_REGISTRY);
event.getRegistry().register(entityType, "dyed_item_frame", Registry.ENTITY_TYPE_REGISTRY);

DyeHandler.addDyeable(Items.ITEM_FRAME, this);
DyeHandler.addDyeable(Items.GLOW_ITEM_FRAME, this);
Quark.ZETA.dyeables.register(Items.ITEM_FRAME, this);
Quark.ZETA.dyeables.register(Items.GLOW_ITEM_FRAME, this);
}

@LoadEvent
Expand All @@ -80,7 +79,7 @@ public void onUse(PlayerInteractEvent.RightClickBlock event) {
InteractionHand hand = event.getHand();
ItemStack stack = player.getItemInHand(hand);

if((stack.is(Items.ITEM_FRAME) || stack.is(Items.GLOW_ITEM_FRAME)) && DyeHandler.isDyed(stack)) {
if((stack.is(Items.ITEM_FRAME) || stack.is(Items.GLOW_ITEM_FRAME)) && Quark.ZETA.dyeables.isDyed(stack)) {
BlockHitResult blockhit = event.getHitVec();
UseOnContext context = new UseOnContext(player, hand, blockhit);

Expand Down Expand Up @@ -111,7 +110,7 @@ private InteractionResult useOn(UseOnContext context) {
return InteractionResult.FAIL;

Level level = context.getLevel();
HangingEntity hangingentity = new DyedItemFrame(level, blockpos1, direction, DyeHandler.getDye(itemstack), itemstack.is(Items.GLOW_ITEM_FRAME));
HangingEntity hangingentity = new DyedItemFrame(level, blockpos1, direction, Quark.ZETA.dyeables.getDye(itemstack), itemstack.is(Items.GLOW_ITEM_FRAME));

CompoundTag compoundtag = itemstack.getTag();
if(compoundtag != null)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/vazkii/zeta/Zeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import vazkii.zeta.module.ZetaCategory;
import vazkii.zeta.module.ZetaModuleManager;
import vazkii.zeta.network.ZetaNetworkHandler;
import vazkii.zeta.registry.DyeablesRegistry;
import vazkii.zeta.registry.ZetaRegistry;
import vazkii.zeta.util.ZetaSide;

Expand All @@ -34,6 +35,7 @@ public Zeta(String modid, Logger log) {
this.playBus = new ZetaEventBus<>(PlayEvent.class, IZetaPlayEvent.class, null);
this.modules = new ZetaModuleManager(this);
this.registry = createRegistry(modid);
this.dyeables = new DyeablesRegistry(this);

this.ticker_SHOULD_NOT_BE_HERE = new ClientTicker();
}
Expand All @@ -45,7 +47,9 @@ public Zeta(String modid, Logger log) {
public final ZetaEventBus<IZetaLoadEvent> loadBus;
public final ZetaEventBus<IZetaPlayEvent> playBus;
public final ZetaModuleManager modules;

public final ZetaRegistry registry;
public final DyeablesRegistry dyeables; //TODO: move into ZetaRegistry?

public WeirdConfigSingleton weirdConfigSingleton; //Should probably split this up into various parts
public IZetaConfigInternals configInternals;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/vazkii/zeta/client/ZetaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import vazkii.zeta.event.bus.IZetaLoadEvent;
import vazkii.zeta.event.bus.IZetaPlayEvent;
import vazkii.zeta.event.bus.ZetaEventBus;
import vazkii.zeta.registry.DyeablesRegistry;

public abstract class ZetaClient {
public ZetaClient(Zeta zeta) {
Expand All @@ -17,6 +18,7 @@ public ZetaClient(Zeta zeta) {
this.ticker = zeta.ticker_SHOULD_NOT_BE_HERE; //TODO, move ClientTicker into actual client code
this.clientConfigManager = new ClientConfigManager();
this.topLayerTooltipHandler = new TopLayerTooltipHandler();
this.clientDyeablesRegistry = zeta.dyeables.new Client(this);

playBus.subscribe(topLayerTooltipHandler);
}
Expand All @@ -30,6 +32,7 @@ public ZetaClient(Zeta zeta) {
public final ClientTicker ticker;
public final ClientConfigManager clientConfigManager;
public final TopLayerTooltipHandler topLayerTooltipHandler;
public final DyeablesRegistry.Client clientDyeablesRegistry;

public abstract void start();
}
12 changes: 12 additions & 0 deletions src/main/java/vazkii/zeta/event/ZRegister.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package vazkii.zeta.event;

import vazkii.zeta.event.bus.IZetaLoadEvent;
import vazkii.zeta.registry.ZetaRegistry;

@SuppressWarnings("ClassCanBeRecord")
public class ZRegister implements IZetaLoadEvent {
public final ZetaRegistry registry;

public ZRegister(ZetaRegistry registry) {
this.registry = registry;
}

public ZetaRegistry getRegistry() {
return registry;
}

public static class Post implements IZetaLoadEvent { }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package vazkii.quark.base.recipe;
package vazkii.zeta.recipe;

import java.util.List;

import com.google.common.collect.Lists;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.DyeItem;
Expand All @@ -13,26 +12,27 @@
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
import net.minecraft.world.level.Level;
import vazkii.quark.base.handler.DyeHandler;

// copy of ArmorDyeRecipe but tweaked for our system
public class DyeRecipe extends CustomRecipe {

public static final SimpleRecipeSerializer<?> SERIALIZER = new SimpleRecipeSerializer<>(DyeRecipe::new);

public DyeRecipe(ResourceLocation p_43757_) {
super(p_43757_);
import vazkii.zeta.registry.DyeablesRegistry;

// copy of ArmorDyeRecipe
public class ZetaDyeRecipe extends CustomRecipe {
protected final DyeablesRegistry dyeablesRegistry;
protected final SimpleRecipeSerializer<?> serializer;

public ZetaDyeRecipe(ResourceLocation id, DyeablesRegistry dyeablesRegistry) {
super(id);
this.dyeablesRegistry = dyeablesRegistry;
this.serializer = new SimpleRecipeSerializer<>(id_ -> new ZetaDyeRecipe(id_, dyeablesRegistry));
}

@Override
public boolean matches(CraftingContainer p_43769_, Level p_43770_) {
ItemStack itemstack = ItemStack.EMPTY;
List<ItemStack> list = Lists.newArrayList();

for(int i = 0; i < p_43769_.getContainerSize(); ++i) {
ItemStack itemstack1 = p_43769_.getItem(i);
if (!itemstack1.isEmpty()) {
if (DyeHandler.isDyeable(itemstack1)) { // <- changed
if (dyeablesRegistry.isDyeable(itemstack1)) { // <- changed
if (!itemstack.isEmpty()) {
return false;
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public ItemStack assemble(CraftingContainer p_43767_) {
ItemStack itemstack1 = p_43767_.getItem(i);
if (!itemstack1.isEmpty()) {
Item item = itemstack1.getItem();
if (DyeHandler.isDyeable(itemstack1)) {
if (dyeablesRegistry.isDyeable(itemstack1)) { // <- changed
if (!itemstack.isEmpty()) {
return ItemStack.EMPTY;
}
Expand All @@ -76,16 +76,18 @@ public ItemStack assemble(CraftingContainer p_43767_) {
}
}

return !itemstack.isEmpty() && !list.isEmpty() ? DyeHandler.dyeItem(itemstack, list) : ItemStack.EMPTY;
return !itemstack.isEmpty() && !list.isEmpty() ?
dyeablesRegistry.dyeItem(itemstack, list) : // <- changed
ItemStack.EMPTY;
}

@Override
public boolean canCraftInDimensions(int p_43759_, int p_43760_) {
return p_43759_ * p_43760_ >= 2;
public boolean canCraftInDimensions(int width, int height) {
return width * height >= 2;
}

@Override
public RecipeSerializer<?> getSerializer() {
return SERIALIZER;
return serializer;
}
}
Loading

0 comments on commit d6ad830

Please sign in to comment.