Skip to content

Commit

Permalink
Merge branch 'zeta' of https://github.com/vazkiimods/quark into zeta
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Nov 10, 2023
2 parents 0ed76a0 + cf9327b commit cd2e0b8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;

public class VariantSelectorScreen extends Screen {

float timeIn = 0;
int slotSelected = -1;
private float timeIn = 0;
private int slotSelected = -1;

final Minecraft mc;
final ItemStack stack;
final KeyMapping key;
final String currentVariant;
final List<String> variants;
private final Minecraft mc;
private final ItemStack stack;
private final KeyMapping key;
private final String currentVariant;
private final List<String> variants;

final List<DrawStack> drawStacks = new ArrayList<>();
private final List<DrawStack> drawStacks = new ArrayList<>();

public VariantSelectorScreen(ItemStack stack, KeyMapping key, String currentVariant, List<String> variants) {
super(Component.empty());
Expand All @@ -45,7 +47,7 @@ public VariantSelectorScreen(ItemStack stack, KeyMapping key, String currentVari
}

@Override
public void render(PoseStack ms, int mx, int my, float delta) {
public void render(@Nonnull PoseStack ms, int mx, int my, float delta) {
super.render(ms, mx, my, delta);

timeIn += delta;
Expand Down Expand Up @@ -99,18 +101,25 @@ public void render(PoseStack ms, int mx, int my, float delta) {
if(mouseInSector || rightVariant)
radius *= 1.1f;

if(!variantExists)
radius *= 0.9f;

int gs = 0x39;
if(seg % 2 == 0)
gs += 0x29;

int r = gs;
int g = gs ;
int b = gs;
int a = 0x33;
int a = 0x44;

if(variantExists) {
g += 0x22;
a = 0x99;
} else {
r /= 4;
g /= 4;
b /= 4;
}

if(seg == 0)
Expand Down Expand Up @@ -151,9 +160,7 @@ else if(rightVariant) {
RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);

for(DrawStack ds : drawStacks) {
if(ds.stack().isEmpty())
mc.font.draw(ms, "?", ds.x() + 6, ds.y() + 3, 0x99FFFFFF);
else
if(!ds.stack().isEmpty())
mc.getItemRenderer().renderGuiItem(ds.stack(), ds.x(), ds.y());
}
RenderSystem.disableBlend();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,35 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;

public class BlockSuffixConfig implements IConfigType {
public class VariantsConfig implements IConfigType {

private static final VariantMap EMPTY_VARIANT_MAP = new VariantMap(new HashMap<>());

@Config(description = "The list of all variant types available for players to use. Values are treated as suffixes to block IDs for scanning.\n"
+ "Prefix any variant type with ! to make it show up for Manual Variants but not be automatically scanned for. (e.g. '!polish')")
private List<String> variantTypes;
private List<String> variantTypes = Arrays.asList("slab", "stairs", "wall", "fence", "fence_gate", "vertical_slab");

@Config(description = "By default, only a mod's namespace is scanned for variants for its items (e.g. if coolmod adds coolmod:fun_block, it'll search only for coolmod:fun_block_stairs).\n"
+ " Mods in this list are also scanned for variants if none are found in itself (e.g. if quark is in the list and coolmod:fun_block_stairs doesn't exist, it'll try to look for quark:fun_block_stairs next)")
private List<String> testedMods;
private List<String> testedMods = Arrays.asList("quark");

@Config
private boolean printVariantMapToLog = false;

@Config(description = "Format is 'alias=original' in each value (e.g. 'wall=fence' means that a failed search for, minecraft:cobblestone_fence will try cobblestone_wall next)")
private List<String> aliases;
private List<String> aliases = Arrays.asList("carpet=slab", "pane=fence");

@Config(description = "Ends of block IDs to try and remove when looking for variants. (e.g. minecraft:oak_planks goes into minecraft:oak_stairs, so we have to include '_planks' in this list for it to find them or else it'll only look for minecraft:oak_planks_stairs)")
private List<String> stripCandidates = Arrays.asList("_planks", "_wool", "s");
private List<String> stripCandidates = Arrays.asList("_planks", "_wool", "_block", "s");

@Config(description = "Add manual variant overrides here, the format is 'type,block,output' (e.g. polish,minecraft:stone_bricks,minecraft:chiseled_stone_bricks). The type must be listed in Variant Types")
private List<String> manualVariants = new ArrayList<>();

@Config
private List<String> blacklist = new ArrayList<>();

@Config(description = " A list of block IDs and mappings to be excluded from variant selection.\n"
+ "To exclude a block from being turned into other blocks, just include the block ID (e.g. minecraft:cobblestone).\n"
+ "To exclude a block from having other blocks turned into it, suffix it with = (e.g. =minecraft:cobblestone_stairs)\n"
+ "To exclude a specific block->variant combination, put = between the two (e.g. minecraft:cobblestone=minecraft:cobblestone_stairs)")
private List<String> blacklist = Arrays.asList("minecraft:snow", "minecraft:bamboo", "quark:bamboo_block");

private Map<Block, VariantMap> blockVariants = new HashMap<>();
private Map<Block, Block> originals = new HashMap<>();
Expand All @@ -57,11 +60,7 @@ public class BlockSuffixConfig implements IConfigType {
private List<String> visibleVariants = new ArrayList<>();
private List<String> sortedSuffixes;

public BlockSuffixConfig(List<String> variantTypes, List<String> testedMods, List<String> aliases) {
this.variantTypes = variantTypes;
this.testedMods = testedMods;
this.aliases = aliases;
}
public VariantsConfig() { }

@Override
public void onReload(ZetaModule module, ConfigFlagManager flagManager) {
Expand Down Expand Up @@ -153,11 +152,15 @@ public Collection<Block> getAllVariants(Block block) {
}

public Block getOriginalBlock(Block block) {
return originals.containsKey(block) ? originals.get(block) : block;
return originals.getOrDefault(block, block);
}

public boolean isOriginal(Block block) {
return originals.containsValue(block);
}

public boolean isVariant(Block block) {
return blockVariants.containsKey(block) && !blockVariants.get(block).isEmpty();
return originals.containsKey(block);
}

private VariantMap getVariants(Block block) {
Expand All @@ -166,13 +169,13 @@ private VariantMap getVariants(Block block) {

Map<String, Block> newVariants = new HashMap<>();

if(!isBlacklisted(block))
if(!isBlacklisted(block, null))
for(String s : sortedSuffixes) {
if(!variantTypes.contains(s))
continue; // this means its marked with ! so it won't be searched

Block suffixed = getSuffixedBlock(block, s);
if(suffixed != null && !isBlacklisted(block)) {
if(suffixed != null && !isBlacklisted(null, suffixed) && !isBlacklisted(block, suffixed)) {
newVariants.put(s, suffixed);
originals.put(suffixed, block);
}
Expand Down Expand Up @@ -236,8 +239,17 @@ private Block getSuffixedBlock(String namespace, String name, String suffix) {
return ret;
}

private boolean isBlacklisted(Block block) {
return !blacklist.isEmpty() && blacklist.contains(Registry.BLOCK.getKey(block).toString());
private boolean isBlacklisted(Block block, Block result) {
if(blacklist.isEmpty())
return false;

String search = "";
if(block != null)
search += Registry.BLOCK.getKey(block).toString();
if(result != null)
search += ("=" + Registry.BLOCK.getKey(result).toString());

return !search.isEmpty() && blacklist.contains(search);
}

public boolean isKnownVariant(String variant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,30 @@ public InteractionResult useOn(UseOnContext context) {
BlockPos pos = context.getClickedPos();
BlockState state = level.getBlockState(pos);
Block block = state.getBlock();

String variant = VariantSelectorModule.getSavedVariant(player);
Block variantBlock = VariantSelectorModule.getVariantOrOriginal(block, variant);
if(variantBlock != null) {
BlockPlaceContext bpc = new YungsBetterBlockPlaceContext(context);
BlockState place = variantBlock.getStateForPlacement(bpc);
place = LockRotationModule.fixBlockRotation(place, bpc);

if(!place.equals(state) && !level.isClientSide) {

if(player != null) {
String variant = VariantSelectorModule.getSavedVariant(player);
Block variantBlock = VariantSelectorModule.getVariantOrOriginal(block, variant);
if(variantBlock != null) {
level.removeBlock(pos, false);
level.setBlock(pos, place, 1 | 2);
player.swing(context.getHand());

level.playSound(null, pos, variantBlock.getSoundType(place).getPlaceSound(), SoundSource.BLOCKS, 1.0F, 1.0F);

BlockPlaceContext bpc = new YungsBetterBlockPlaceContext(context);
BlockState place = variantBlock.getStateForPlacement(bpc);

place = LockRotationModule.fixBlockRotation(place, bpc);

if(place != null && !place.equals(state) && !level.isClientSide) {
level.removeBlock(pos, false);
level.setBlock(pos, place, 1 | 2);
player.swing(context.getHand());

level.playSound(null, pos, place.getSoundType().getPlaceSound(), SoundSource.BLOCKS, 1.0F, 1.0F);
} else {
level.setBlock(pos, state, 0);
}

return InteractionResult.SUCCESS;
}

return InteractionResult.SUCCESS;
}

return InteractionResult.PASS;
Expand All @@ -66,10 +73,12 @@ public YungsBetterBlockPlaceContext(UseOnContext ctx) {
// vanilla BlockPlaceContext offsets the original clicked pos if replaceClicked is false
// so that the block is placed on the edge, but in this case we want to place it in the
// same blockpos that was clicked so we do this nonsense


@Nonnull
@Override
public BlockPos getClickedPos() {
boolean oldRepl = replaceClicked;

replaceClicked = true;
BlockPos pos = super.getClickedPos();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.violetmoon.quark.base.network.message.experimental.PlaceVariantUpdateMessage;
import org.violetmoon.quark.content.experimental.client.screen.VariantSelectorScreen;
import org.violetmoon.quark.content.experimental.client.tooltip.VariantsComponent;
import org.violetmoon.quark.content.experimental.config.BlockSuffixConfig;
import org.violetmoon.quark.content.experimental.config.VariantsConfig;
import org.violetmoon.quark.content.experimental.item.HammerItem;
import org.violetmoon.zeta.client.event.load.ZKeyMapping;
import org.violetmoon.zeta.client.event.load.ZTooltipComponents;
Expand Down Expand Up @@ -77,13 +77,11 @@ public class VariantSelectorModule extends ZetaModule {
@Config public static boolean showHud = true;
@Config public static boolean enableGreenTint = true;
@Config public static boolean overrideHeldItemRender = true;
@Config public static int hudOffsetX = 0;
@Config public static int hudOffsetY = 0;

@Config
public static BlockSuffixConfig variants = new BlockSuffixConfig(
Arrays.asList("slab", "stairs", "wall", "fence", "fence_gate", "vertical_slab"),
Arrays.asList("quark"),
Arrays.asList("carpet=slab")
);
public static VariantsConfig variants = new VariantsConfig();

public static Item hammer;

Expand Down Expand Up @@ -123,14 +121,13 @@ private static Block getMainHandVariantBlock(Player player, String variant) {
}

public static Block getVariantForBlock(Block block, String variant) {
Block variantBlock = variants.getBlockForVariant(block, variant);
if(variantBlock != null)
return variantBlock;

return null;
return variants.getBlockForVariant(block, variant);
}

public static Block getVariantOrOriginal(Block block, String variant) {
if(!variants.isVariant(block) && !variants.isOriginal(block))
return null;

block = variants.getOriginalBlock(block);

if(variant == null || variant.isEmpty())
Expand Down Expand Up @@ -313,10 +310,6 @@ public void onRender(ZRenderGuiOverlay.Crosshair.Pre event) {
int x = window.getGuiScaledWidth() / 2;
int y = window.getGuiScaledHeight() / 2 + 12;


showSimpleHud = true;
alignHudToHotbar = true;

if(alignHudToHotbar) {
HumanoidArm arm = mc.options.mainHand().get();
if(arm == HumanoidArm.RIGHT)
Expand All @@ -331,8 +324,8 @@ public void onRender(ZRenderGuiOverlay.Crosshair.Pre event) {

displayLeft.setCount(1);

int posX = x - offset - width;
int posY = y;
int posX = x - offset - width + hudOffsetX;
int posY = y + hudOffsetY;

if(!showSimpleHud) {
mc.getItemRenderer().renderAndDecorateItem(displayLeft, posX, posY);
Expand Down

0 comments on commit cd2e0b8

Please sign in to comment.