Skip to content

Commit

Permalink
Merge IQuarkBlock and IQuarkItem
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Oct 29, 2023
1 parent 302be41 commit b4a5dc5
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 100 deletions.
15 changes: 13 additions & 2 deletions src/main/java/vazkii/quark/addons/oddities/item/BackpackItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@
import vazkii.quark.base.client.handler.ModelHandler;
import vazkii.quark.base.client.handler.RequiredModTooltipHandler;
import vazkii.quark.base.handler.ProxiedItemStackHandler;
import vazkii.quark.base.item.IQuarkItem;
import vazkii.zeta.item.IZetaItem;
import vazkii.zeta.module.ZetaModule;
import vazkii.zeta.registry.IZetaItemColorProvider_OLD;

import javax.annotation.Nonnull;
import java.util.Map;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;

public class BackpackItem extends DyeableArmorItem implements IQuarkItem, MenuProvider, IZetaItemColorProvider_OLD {
public class BackpackItem extends DyeableArmorItem implements IZetaItem, MenuProvider, IZetaItemColorProvider_OLD {

private static final String WORN_TEXTURE = Quark.MOD_ID + ":textures/misc/backpack_worn.png";
private static final String WORN_OVERLAY_TEXTURE = Quark.MOD_ID + ":textures/misc/backpack_worn_overlay.png";
Expand Down Expand Up @@ -82,6 +83,16 @@ public ZetaModule getModule() {
return module;
}

@Override
public IZetaItem setCondition(BooleanSupplier condition) {
return this;
}

@Override
public boolean doesConditionApply() {
return true;
}

public static boolean doesBackpackHaveItems(ItemStack stack) {
LazyOptional<IItemHandler> handlerOpt = stack.getCapability(ForgeCapabilities.ITEM_HANDLER, null);

Expand Down
18 changes: 2 additions & 16 deletions src/main/java/vazkii/quark/base/block/IQuarkBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,20 @@
import net.minecraft.world.level.material.Material;
import net.minecraftforge.common.extensions.IForgeBlock;
import vazkii.quark.base.Quark;
import vazkii.zeta.module.ZetaModule;
import vazkii.zeta.module.IDisableable;

import javax.annotation.Nullable;
import java.util.function.BooleanSupplier;
import java.util.function.Function;

/**
* @author WireSegal
* Created at 1:14 PM on 9/19/19.
*/
public interface IQuarkBlock extends IForgeBlock {

@Nullable
ZetaModule getModule();

IQuarkBlock setCondition(BooleanSupplier condition);

boolean doesConditionApply();
public interface IQuarkBlock extends IForgeBlock, IDisableable<IQuarkBlock> {

default Block getBlock() {
return (Block) this;
}

default boolean isEnabled() {
ZetaModule module = getModule();
return module != null && module.enabled && !module.disabledByOverlap && doesConditionApply();
}

@Override
default int getFlammability(BlockState state, BlockGetter world, BlockPos pos, Direction face) {
if (state.getValues().containsKey(BlockStateProperties.WATERLOGGED) && state.getValue(BlockStateProperties.WATERLOGGED))
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/vazkii/quark/base/item/IQuarkItem.java

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/java/vazkii/quark/base/item/QuarkArrowItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import vazkii.quark.base.Quark;
import vazkii.zeta.item.IZetaItem;
import vazkii.zeta.module.ZetaModule;

public abstract class QuarkArrowItem extends ArrowItem implements IQuarkItem {
public abstract class QuarkArrowItem extends ArrowItem implements IZetaItem {

private final ZetaModule module;
private BooleanSupplier enabledSupplier = () -> true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import net.minecraft.world.item.DoubleHighBlockItem;
import net.minecraft.world.item.ItemStack;
import vazkii.quark.base.block.IQuarkBlock;
import vazkii.zeta.item.IZetaItem;
import vazkii.zeta.module.ZetaModule;

import javax.annotation.Nonnull;
import java.util.function.BooleanSupplier;

public class QuarkDoubleHighBlockItem extends DoubleHighBlockItem implements IQuarkItem {
public class QuarkDoubleHighBlockItem extends DoubleHighBlockItem implements IZetaItem {

private final ZetaModule module;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/vazkii/quark/base/item/QuarkItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import net.minecraft.world.item.ItemStack;
import vazkii.quark.base.Quark;
import vazkii.quark.base.client.handler.RequiredModTooltipHandler;
import vazkii.zeta.item.IZetaItem;
import vazkii.zeta.module.ZetaModule;

import javax.annotation.Nonnull;
import java.util.function.BooleanSupplier;

public class QuarkItem extends Item implements IQuarkItem {
public class QuarkItem extends Item implements IZetaItem {

private final ZetaModule module;
private BooleanSupplier enabledSupplier = () -> true;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/vazkii/quark/base/item/QuarkMobBucketItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import net.minecraft.world.item.MobBucketItem;
import net.minecraft.world.level.material.Fluid;
import vazkii.quark.base.Quark;
import vazkii.zeta.item.IZetaItem;
import vazkii.zeta.module.ZetaModule;

import javax.annotation.Nonnull;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;

public class QuarkMobBucketItem extends MobBucketItem implements IQuarkItem {
public class QuarkMobBucketItem extends MobBucketItem implements IZetaItem {

private final ZetaModule module;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/vazkii/quark/base/item/QuarkMusicDiscItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
import net.minecraftforge.api.distmarker.OnlyIn;
import vazkii.quark.base.Quark;
import vazkii.quark.content.tools.module.AmbientDiscsModule;
import vazkii.zeta.item.IZetaItem;
import vazkii.zeta.module.ZetaModule;

import javax.annotation.Nonnull;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;

public class QuarkMusicDiscItem extends RecordItem implements IQuarkItem {
public class QuarkMusicDiscItem extends RecordItem implements IZetaItem {

private final ZetaModule module;
private final boolean isAmbient;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/vazkii/quark/base/item/QuarkSignItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import net.minecraft.world.level.block.Block;
import vazkii.quark.base.Quark;
import vazkii.quark.base.block.IQuarkBlock;
import vazkii.zeta.item.IZetaItem;
import vazkii.zeta.module.ZetaModule;

public class QuarkSignItem extends SignItem implements IQuarkItem {
public class QuarkSignItem extends SignItem implements IZetaItem {

private final ZetaModule module;
private BooleanSupplier enabledSupplier = () -> true;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/vazkii/quark/base/item/QuarkSpawnEggItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.ForgeSpawnEggItem;
import vazkii.quark.base.Quark;
import vazkii.zeta.item.IZetaItem;
import vazkii.zeta.module.ZetaModule;

import javax.annotation.Nonnull;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;

public class QuarkSpawnEggItem extends ForgeSpawnEggItem implements IQuarkItem {
public class QuarkSpawnEggItem extends ForgeSpawnEggItem implements IZetaItem {

private final ZetaModule module;
private BooleanSupplier enabledSupplier = () -> true;
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/vazkii/quark/base/module/ModuleLoader.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package vazkii.quark.base.module;

import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import vazkii.quark.base.Quark;
import vazkii.quark.base.block.IQuarkBlock;
import vazkii.quark.base.item.IQuarkItem;
import vazkii.zeta.module.ZetaModule;

//TODO ZETA: im in the process of stripping this class for parts
Expand All @@ -31,19 +26,4 @@ public boolean isModuleEnabledOrOverlapping(Class<? extends ZetaModule> moduleCl
return module != null && (module.enabled || module.disabledByOverlap);
}

//and this
public boolean isItemEnabled(Item i) {
if(i instanceof IQuarkItem qi) {
return qi.isEnabled();
}
else if(i instanceof BlockItem bi) {
Block b = bi.getBlock();
if(b instanceof IQuarkBlock qb) {
return qb.isEnabled();
}
}

return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import vazkii.quark.base.handler.StructureBlockReplacementHandler.StructureHolder;
import vazkii.quark.base.module.LoadModule;
import vazkii.quark.base.module.ModuleLoader;
import vazkii.zeta.module.IDisableable;
import vazkii.zeta.module.ZetaModule;
import vazkii.quark.base.module.config.Config;
import vazkii.quark.base.util.VanillaWoods;
Expand Down Expand Up @@ -229,8 +230,8 @@ public static <T extends BlockEntity> BlockEntityType<T> registerChests(BlockEnt
compatType.createChest(it.type, it.mod, it.module, tileType, it.props.get()) :
chestType.createChest(it.type, it.module, tileType, it.props.get());

if (it.condition != null && block instanceof IQuarkBlock quarkBlock)
quarkBlock.setCondition(it.condition);
if (it.condition != null && block instanceof IDisableable<?> disableable)
disableable.setCondition(it.condition);

if (structureMappings != null) {
TagKey<Structure> tag = structureTags.computeIfAbsent(it, (info) -> TagKey.create(Registry.STRUCTURE_REGISTRY, new ResourceLocation(Quark.MOD_ID, info.type + "_chest_structures")));
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/vazkii/quark/content/mobs/item/ForgottenHatItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
import net.minecraftforge.common.ForgeMod;
import vazkii.quark.base.Quark;
import vazkii.quark.base.client.handler.ModelHandler;
import vazkii.quark.base.item.IQuarkItem;
import vazkii.zeta.item.IZetaItem;
import vazkii.zeta.module.ZetaModule;

import javax.annotation.Nonnull;
import java.util.UUID;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;

public class ForgottenHatItem extends ArmorItem implements IQuarkItem {
public class ForgottenHatItem extends ArmorItem implements IZetaItem {

private static final String TEXTURE = Quark.MOD_ID + ":textures/misc/forgotten_hat_worn.png";

Expand All @@ -49,6 +50,16 @@ public ZetaModule getModule() {
return module;
}

@Override
public IZetaItem setCondition(BooleanSupplier condition) {
return this;
}

@Override
public boolean doesConditionApply() {
return true;
}

@Override
public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) {
return TEXTURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.apache.commons.lang3.tuple.Pair;
import vazkii.zeta.module.IDisableable;
import vazkii.zeta.util.ItemNBTHelper;
import vazkii.quark.api.ITrowelable;
import vazkii.quark.api.IUsageTickerOverride;
Expand Down Expand Up @@ -307,7 +308,7 @@ public void fillItemCategory(@Nonnull CreativeModeTab group, @Nonnull NonNullLis
}

for(Item i : tagItems) {
if(!ModuleLoader.INSTANCE.isItemEnabled(i))
if(!IDisableable.isEnabled(i))
continue;

ItemStack stack = new ItemStack(this);
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/vazkii/quark/integration/jei/QuarkJeiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import vazkii.zeta.event.ZGatherHints;
import vazkii.zeta.module.IDisableable;
import vazkii.zeta.util.ItemNBTHelper;
import vazkii.quark.addons.oddities.block.be.MatrixEnchantingTableBlockEntity;
import vazkii.quark.addons.oddities.client.screen.BackpackInventoryScreen;
import vazkii.quark.addons.oddities.client.screen.CrateScreen;
import vazkii.quark.addons.oddities.module.MatrixEnchantingModule;
import vazkii.quark.addons.oddities.util.Influence;
import vazkii.quark.base.Quark;
import vazkii.quark.base.block.IQuarkBlock;
import vazkii.quark.base.client.handler.RequiredModTooltipHandler;
import vazkii.quark.base.handler.GeneralConfig;
import vazkii.quark.base.handler.MiscUtil;
import vazkii.quark.base.item.IQuarkItem;
import vazkii.quark.base.item.QuarkItem;
import vazkii.quark.base.module.ModuleLoader;
import vazkii.quark.content.building.module.VariantFurnacesModule;
Expand Down Expand Up @@ -86,7 +85,7 @@ public void onRuntimeAvailable(@Nonnull final IJeiRuntime jeiRuntime) {
if (!disabledItems.isEmpty())
jeiRuntime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, disabledItems);

Quark.ZETA.configManager.setJeiReloadListener(z -> {
Quark.ZETA.configManager.setJeiReloadListener(configInternals -> {
if(ModuleLoader.INSTANCE.isModuleEnabled(DiamondRepairModule.class))
Minecraft.getInstance().submitAsync(() -> hideAnvilRepairRecipes(jeiRuntime.getRecipeManager()));

Expand All @@ -103,25 +102,24 @@ public void onRuntimeAvailable(@Nonnull final IJeiRuntime jeiRuntime) {
}
}

NonNullList<ItemStack> stacks = NonNullList.create();
NonNullList<ItemStack> stacksToHide = NonNullList.create();
for (Item item : Registry.ITEM) {
ResourceLocation loc = Registry.ITEM.getKey(item);
if (loc != null && loc.getNamespace().equals("quark")) {
if ((item instanceof IQuarkItem quarkItem && !quarkItem.isEnabled()) ||
(item instanceof BlockItem blockItem && blockItem.getBlock() instanceof IQuarkBlock quarkBlock && !quarkBlock.isEnabled())) {
item.fillItemCategory(CreativeModeTab.TAB_SEARCH, stacks);
}
Quark.LOG.info("examingin item {} for DELETE", loc);
if (loc.getNamespace().equals("quark") && !IDisableable.isEnabled(item)) {
Quark.LOG.info("DELETE THAT SHIT!!!!!!!! {}", loc);
item.fillItemCategory(CreativeModeTab.TAB_SEARCH, stacksToHide);
}

if (item instanceof PotionItem || item instanceof TippedArrowItem) {
NonNullList<ItemStack> potionStacks = NonNullList.create();
item.fillItemCategory(CreativeModeTab.TAB_SEARCH, potionStacks);
potionStacks.stream().filter(it -> hidePotions.contains(PotionUtils.getPotion(it))).forEach(stacks::add);
potionStacks.stream().filter(it -> hidePotions.contains(PotionUtils.getPotion(it))).forEach(stacksToHide::add);
}
}

if (!stacks.isEmpty())
Minecraft.getInstance().submitAsync(() -> jeiRuntime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, stacks));
if (!stacksToHide.isEmpty())
Minecraft.getInstance().submitAsync(() -> jeiRuntime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, stacksToHide));
});
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/vazkii/zeta/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,6 @@ public void onReload() {

public void setJeiReloadListener(Consumer<IZetaConfigInternals> consumer) {
this.onConfigReloadJEI = consumer;
consumer.accept(z.configInternals); //run it now as well
}
}
12 changes: 12 additions & 0 deletions src/main/java/vazkii/zeta/item/IZetaItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package vazkii.zeta.item;

import net.minecraft.world.item.Item;
import vazkii.zeta.module.IDisableable;

public interface IZetaItem extends IDisableable<IZetaItem> {

default Item getItem() {
return (Item) this;
}

}
Loading

0 comments on commit b4a5dc5

Please sign in to comment.