Skip to content

Commit

Permalink
Merge branch 'architectury-1.19.3' into architectury-1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Aug 29, 2023
2 parents 8370f26 + c107f8f commit 0f83b8d
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.unlikepaladin.pfm.config.option.AbstractConfigOption;
import com.unlikepaladin.pfm.config.option.Side;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
Expand Down Expand Up @@ -35,17 +36,36 @@ public PFMConfigScreen(MinecraftClient client, Screen parent) {
this.options = PaladinFurnitureMod.getPFMConfig().options;
}


@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == 256 && !optionListWidget.hasChanges.isEmpty()) {
client.setScreen(new ConfirmScreen(t -> {
if (t){
this.optionListWidget.save();
try {
PaladinFurnitureMod.getPFMConfig().save();
} catch (IOException e) {
PaladinFurnitureMod.GENERAL_LOGGER.error("Failed to save config options!");
throw new RuntimeException(e);
}
}
MinecraftClient.getInstance().setScreen(parent);
}, Text.translatable("gui.pfm.changesMightNotBeSaved").setStyle(Style.EMPTY.withColor(0xf77f34).withBold(true)), Text.translatable("gui.pfm.saveChanges")));
return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
public void close() {
this.optionListWidget.save();
MinecraftClient.getInstance().setScreen(parent);
try {
PaladinFurnitureMod.getPFMConfig().save();
} catch (IOException e) {
PaladinFurnitureMod.GENERAL_LOGGER.error("Failed to save config options!");
throw new RuntimeException(e);
}
this.client.setScreen(parent);
}

@Override
Expand All @@ -56,13 +76,24 @@ protected void init() {
this.resetButton = this.addDrawableChild(ButtonWidget.builder(Text.translatable("pfm.option.resetAll"), button -> {
options.forEach((title, option) -> {
if (option.getSide() == Side.CLIENT){
option.setValue(option.getDefaultValue());
if (option.getType() == Boolean.class) {
if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) {
this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true);
}
this.optionListWidget.newConfigValues.put(option, (Boolean) option.getDefaultValue());
}
} else if (!isOnServer && option.getSide() == Side.SERVER) {
option.setValue(option.getDefaultValue());
if (option.getType() == Boolean.class) {
if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) {
this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true);
}
this.optionListWidget.newConfigValues.put(option, (Boolean) option.getDefaultValue());
}
}
});
}).dimensions(this.width/2 - 155, this.height -29, 150, 20).build());
this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, button -> {
this.optionListWidget.save();
this.client.setScreen(this.parent);
try {
PaladinFurnitureMod.getPFMConfig().save();
Expand All @@ -80,8 +111,8 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {

drawCenteredTextWithShadow(matrices, this.textRenderer, TITLE.setStyle(Style.EMPTY.withColor(0xf77f34).withBold(true)), this.width / 2, 8, 0xFFFFFF);
boolean bl = false;
for (Map.Entry<String, AbstractConfigOption> optionEntry : options.entrySet()) {
if (optionEntry.getValue().isDefault()) continue;
for (Map.Entry<AbstractConfigOption, Boolean> optionEntry : optionListWidget.newConfigValues.entrySet()) {
if (optionEntry.getValue() == optionEntry.getKey().getDefaultValue()) continue;
bl = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class PFMOptionListWidget extends ElementListWidget<PFMOptionListWidget.Entry> {
final PFMConfigScreen parent;
int maxKeyNameLength;

public BitSet hasChanges;
public Map<AbstractConfigOption, Boolean> newConfigValues;
public Map<AbstractConfigOption, Integer> configOptionToIndexForHasChanges;
public PFMOptionListWidget(PFMConfigScreen parent, MinecraftClient client) {
super(client, parent.width + 125, parent.height, 43, parent.height - 32, 20);
this.parent = parent;
String string = null;
int index = 0;
hasChanges = new BitSet(PaladinFurnitureMod.getPFMConfig().options.size());
newConfigValues = new HashMap<>(PaladinFurnitureMod.getPFMConfig().options.size());
configOptionToIndexForHasChanges = new HashMap<>(PaladinFurnitureMod.getPFMConfig().options.size());
for(Map.Entry<String, AbstractConfigOption> configOptionEntry : PaladinFurnitureMod.getPFMConfig().options.entrySet()) {
Text text;
int i;
Expand All @@ -48,10 +52,13 @@ public PFMOptionListWidget(PFMConfigScreen parent, MinecraftClient client) {
this.maxKeyNameLength = i;
}
if (configOptionEntry.getValue().getType() == Boolean.class) {
this.addEntry(new BooleanEntry((BooleanConfigOption)configOptionEntry.getValue(), text));
PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), (Boolean) configOptionEntry.getValue().getValue());
this.addEntry(new BooleanEntry((BooleanConfigOption)configOptionEntry.getValue(), text, index));
} else {
PaladinFurnitureMod.GENERAL_LOGGER.warn("Unsupported Config Type!");
}
configOptionToIndexForHasChanges.put(configOptionEntry.getValue(), index);
index++;
}
this.addEntry(new CategoryEntry(Text.literal("")));
this.addEntry(new ButtonEntry(Side.CLIENT, Text.translatable("pfm.option.regenAssets"), Text.translatable("pfm.config.regen"), Text.translatable("pfm.option.regenAssets.tooltip"), button -> {
Expand All @@ -63,6 +70,13 @@ public PFMOptionListWidget(PFMConfigScreen parent, MinecraftClient client) {
}));
}

public void save() {
for (Map.Entry<AbstractConfigOption, Boolean> entry : newConfigValues.entrySet()) {
if (entry.getKey().getType() == Boolean.class)
entry.getKey().setValue(entry.getValue());
}
}

@Override
protected int getScrollbarPositionX() {
return super.getScrollbarPositionX() + 15;
Expand Down Expand Up @@ -124,22 +138,28 @@ public class BooleanEntry
private final ButtonWidget resetButton;

private final Supplier<MutableText> supplier;

BooleanEntry(final BooleanConfigOption configOption, final Text optionName) {
int index;
boolean hasChanges = false;
BooleanEntry(final BooleanConfigOption configOption, final Text optionName, int index) {
this.configOption = configOption;
this.optionName = optionName;
this.index = index;
this.supplier = () -> {
final MutableText sideText = configOption.getSide() == Side.CLIENT ? Text.translatable("pfm.option.client").setStyle(Style.EMPTY.withItalic(false).withBold(true).withColor(0xf77f34)) : Text.translatable("pfm.option.server").setStyle((Style.EMPTY.withItalic(false).withBold(true).withColor(0xf77f34)));
final MutableText styledTooltip = ((MutableText)configOption.getToolTip()).setStyle(Style.EMPTY.withItalic(true));
return sideText.append(Text.literal("\n")).append(styledTooltip);
};
this.valueButton = ButtonWidget.builder(optionName, button -> {
PFMOptionListWidget.this.parent.focusedConfigOption = configOption;
configOption.setValue(!configOption.getValue());
PFMOptionListWidget.this.newConfigValues.put(configOption, !PFMOptionListWidget.this.newConfigValues.get(configOption));
hasChanges = !hasChanges;
PFMOptionListWidget.this.hasChanges.set(index, hasChanges);
}).dimensions(0,0,75,20).narrationSupplier(textSupplier -> this.supplier.get()).build();

this.resetButton = ButtonWidget.builder(Text.translatable("controls.reset"), button -> {
configOption.setValue(configOption.getDefaultValue());
PFMOptionListWidget.this.newConfigValues.put(configOption, configOption.getDefaultValue());
hasChanges = true;
PFMOptionListWidget.this.hasChanges.set(index, true);
}).dimensions(0,0,50,20).narrationSupplier(textSupplier -> Text.translatable("narrator.controls.reset", optionName)).build();
}

Expand All @@ -148,11 +168,11 @@ public void render(MatrixStack matrices, int index, int y, int x, int entryWidth
PFMOptionListWidget.this.client.textRenderer.draw(matrices, this.optionName, (float)(x + 90 - PFMOptionListWidget.this.maxKeyNameLength), (float)(y + entryHeight / 2 - PFMOptionListWidget.this.client.textRenderer.fontHeight / 2), 0xFFFFFF);
this.resetButton.setX(x + 190);
this.resetButton.setY(y);
this.resetButton.active = this.configOption.getSide() == Side.SERVER ? !PFMConfigScreen.isOnServer && !this.configOption.isDefault() : !this.configOption.isDefault();;
this.resetButton.active = this.configOption.getSide() == Side.SERVER ? !PFMConfigScreen.isOnServer && !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption)) : !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption));;
this.resetButton.render(matrices, mouseX, mouseY, tickDelta);
this.valueButton.setX(x + 105);
this.valueButton.setY(y);
this.valueButton.setMessage(this.configOption.getValue() ? ScreenTexts.YES : ScreenTexts.NO);
this.valueButton.setMessage(PFMOptionListWidget.this.newConfigValues.get(configOption) ? ScreenTexts.YES : ScreenTexts.NO);
this.valueButton.active = this.configOption.getSide() != Side.SERVER || !PFMConfigScreen.isOnServer;
this.valueButton.render(matrices, mouseX, mouseY, tickDelta);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Optional<WoodVariant> geVariantFromBlock(Block baseBlock, Identifier bloc
}
String namespace = blockId.getNamespace();
if (name != null && !namespace.equals("securitycraft") &&
!namespace.equals("absentbydesign") && !(namespace.equals("terrestria") && path.contains("sakura")) && !(namespace.equals("betternether") && path.contains("nether_mushroom"))) {
!namespace.equals("absentbydesign") && !(namespace.equals("terrestria") && path.contains("sakura")) && !(namespace.equals("betternether") && path.contains("nether_mushroom")) && !namespace.equals("chipped")) {

BlockState state = baseBlock.getDefaultState();
//can't check if the block is a full one, so I do this. Adding some checks here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,13 @@ public void generateTranslationForLampBlock(BufferedWriter writer) {
}
public String getTranslatedVariantName(VariantBase<?> variant) {
AtomicReference<String> variantName = new AtomicReference<>(translate(variant.getSecondaryBlock().getTranslationKey()));
String oakVariantName = translate(variant != WoodVariantRegistry.getVariantFromVanillaWoodType(BoatEntity.Type.JUNGLE) ? WoodVariantRegistry.getVariantFromVanillaWoodType(BoatEntity.Type.JUNGLE).getSecondaryBlock().getTranslationKey() : WoodVariantRegistry.OAK.getSecondaryBlock().getTranslationKey());
List<String> common = findCommonWords(variantName.get(), oakVariantName);
String baseBlockName = translate(variant.getBaseBlock().getTranslationKey());
List<String> common = findCommonWords(variantName.get(), baseBlockName);
variantName.set("");
if (variant == WoodVariantRegistry.getVariantFromVanillaWoodType(BoatEntity.Type.BAMBOO)) {
variantName.set(variantName.get().replace("Block of", ""));
}
common.forEach(s -> variantName.set(variantName.get().replace(s, "").trim()));
common.forEach(s -> variantName.set(String.join(!variantName.get().isEmpty() ? variantName.get() + " " : variantName.get(), s)));
return variantName.get();
}

Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/pfm/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,8 @@
"pfm.option.regenAssets": "Recreate Assets",
"pfm.config.regen": "Recreate",
"pfm.option.regenAssets.tooltip": "Re-creates mod assets and triggers a resource reload, leaving and entering the world may be necessary for some changes to take effect.",
"gui.pfm.saveChanges": "Do you wish to save your changes?",
"gui.pfm.changesMightNotBeSaved": "Closing without Saving Changes!",

"block.type.stripped": "Stripped",
"block.type.raw": "Raw",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.PFMCookingForBlockHeadsCompat;
import com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.client.PFMCookingForBlockheadsClient;
import com.unlikepaladin.pfm.entity.render.StoveBlockEntityRenderer;
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
Expand All @@ -28,7 +29,7 @@ public static void registerModelLayer(EntityModelLayer entityType, TexturedModel

public static BlockEntityRendererFactory getStoveBlockEntityRenderer() {
if (PaladinFurnitureMod.getModList().contains("cookingforblockheads")) {
return PFMCookingForBlockHeadsCompat.getStoveRenderer();
return PFMCookingForBlockheadsClient.getStoveRenderer();
} else {
return StoveBlockEntityRenderer::new;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.client.screens.StoveScreen;
import com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.PFMCookingForBlockHeadsCompat;
import com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.client.PFMCookingForBlockheadsClient;
import com.unlikepaladin.pfm.menus.StoveScreenHandler;
import com.unlikepaladin.pfm.registry.TriFunc;
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
Expand All @@ -20,7 +21,7 @@ public static <T extends ScreenHandler, J extends Screen & ScreenHandlerProvider

public static <T extends ScreenHandler, J extends Screen & ScreenHandlerProvider<T>> TriFunc<T, PlayerInventory, Text, J> getStoveFactory() {
if (PaladinFurnitureMod.getModList().contains("cookingforblockheads")) {
return PFMCookingForBlockHeadsCompat.getStoveScreen();
return PFMCookingForBlockheadsClient.getStoveScreen();
} else {
return (t, playerInventory, text) -> (J) new StoveScreen((StoveScreenHandler) t, playerInventory, text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.unlikepaladin.pfm.blocks.KitchenWallCounterBlock;
import com.unlikepaladin.pfm.blocks.StoveBlock;
import com.unlikepaladin.pfm.blocks.fabric.StoveBlockImpl;
import com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.menu.StoveBlockEntityRendererBalm;
import com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.menu.StoveScreenBalm;
import com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.menu.StoveScreenHandlerBalm;
import com.unlikepaladin.pfm.registry.BlockEntities;
import com.unlikepaladin.pfm.registry.PaladinFurnitureModBlocksItems;
Expand All @@ -22,16 +20,12 @@
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
Expand All @@ -56,14 +50,6 @@ public static <T extends ScreenHandler> TriFunc<Integer, PlayerInventory, Packet
};
}

public static <T extends ScreenHandler, J extends Screen & ScreenHandlerProvider<T>> TriFunc<T, PlayerInventory, Text,J> getStoveScreen() {
return (t, playerInventory, text) -> (J) new StoveScreenBalm((StoveScreenHandlerBalm) t, playerInventory, text);
}

public static BlockEntityRendererFactory getStoveRenderer() {
return StoveBlockEntityRendererBalm::new;
}

public static void openMenuScreen(World world, BlockPos pos, PlayerEntity player) {
StoveBlockEntityBalm stove = (StoveBlockEntityBalm)world.getBlockEntity(pos);
if (!world.isClient) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.client;

import com.unlikepaladin.pfm.compat.PFMClientModCompatibility;
import com.unlikepaladin.pfm.compat.PFMModCompatibility;
import com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.menu.StoveBlockEntityRendererBalm;
import com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.menu.StoveScreenBalm;
import com.unlikepaladin.pfm.compat.cookingforblockheads.fabric.menu.StoveScreenHandlerBalm;
import com.unlikepaladin.pfm.registry.TriFunc;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;

public class PFMCookingForBlockheadsClient implements PFMClientModCompatibility {
private final PFMModCompatibility parent;

public PFMCookingForBlockheadsClient(PFMModCompatibility parent) {
this.parent = parent;
}

@Override
public PFMModCompatibility getCompatiblity() {
return parent;
}

public static <T extends ScreenHandler, J extends Screen & ScreenHandlerProvider<T>> TriFunc<T, PlayerInventory, Text,J> getStoveScreen() {
return (t, playerInventory, text) -> (J) new StoveScreenBalm((StoveScreenHandlerBalm) t, playerInventory, text);
}

public static BlockEntityRendererFactory getStoveRenderer() {
return StoveBlockEntityRendererBalm::new;
}

}
Loading

0 comments on commit 0f83b8d

Please sign in to comment.