generated from MrSphay/codex-agent-repository-kit
This commit is contained in:
@@ -1,495 +1,16 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.vinlanx.explosionoverhaul.client;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import com.vinlanx.explosionoverhaul.BlockIndexManager;
|
||||
import com.vinlanx.explosionoverhaul.ExplosionOverhaul;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.CycleButton;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.client.gui.components.Tooltip;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
public class BlacklistScreen
|
||||
extends Screen {
|
||||
private static final int NAV_WIDTH = 160;
|
||||
private static final int PADDING = 12;
|
||||
private static final int HEADER_HEIGHT = 48;
|
||||
private static final int FOOTER_HEIGHT = 64;
|
||||
private static final int SEARCH_WIDTH = 200;
|
||||
private static final int INPUT_WIDTH = 240;
|
||||
private static final int BUTTON_HEIGHT = 20;
|
||||
private static final int SPACING = 4;
|
||||
private final Screen parent;
|
||||
private BlacklistList widget;
|
||||
private EditBox inputField;
|
||||
private Button addButton;
|
||||
private EditBox searchField;
|
||||
private Button backButton;
|
||||
private Button resetButton;
|
||||
private Button infoButton;
|
||||
private CycleButton<Boolean> defaultToggle;
|
||||
private final LinkedHashSet<String> persistedEntries = new LinkedHashSet();
|
||||
private final Map<String, ExplosionOverhaul.ExplosionSourceMode> persistedSourceModes = new HashMap<String, ExplosionOverhaul.ExplosionSourceMode>();
|
||||
private final Set<String> defaultEntries = new LinkedHashSet<String>();
|
||||
private boolean showDefaults = false;
|
||||
private final EnumMap<BlacklistCategory, Button> categoryButtons = new EnumMap(BlacklistCategory.class);
|
||||
private BlacklistCategory currentCategory = BlacklistCategory.EXPLOSION;
|
||||
private List<String> suggestions = Collections.emptyList();
|
||||
private List<String> registryCache = new ArrayList<String>();
|
||||
|
||||
public class BlacklistScreen extends Screen {
|
||||
public BlacklistScreen(Screen parent) {
|
||||
super((Component)Component.translatable((String)"title.explosionoverhaul.blacklist"));
|
||||
this.parent = parent;
|
||||
super(Component.empty());
|
||||
}
|
||||
|
||||
protected void m_7856_() {
|
||||
this.categoryButtons.clear();
|
||||
this.setupLayout();
|
||||
this.addNavigation();
|
||||
this.addTopControls();
|
||||
this.addInputArea();
|
||||
this.updateCache();
|
||||
this.loadCurrentCategoryEntries();
|
||||
}
|
||||
|
||||
private void setupLayout() {
|
||||
int listTop = 48;
|
||||
int listBottom = this.f_96544_ - 64;
|
||||
int listWidth = this.f_96543_ - 160 - 24;
|
||||
int listLeft = 172;
|
||||
this.widget = new BlacklistList(this.f_96541_, listWidth, listBottom - listTop, listTop, listBottom, 24);
|
||||
this.widget.m_93507_(listLeft);
|
||||
this.m_142416_((GuiEventListener)this.widget);
|
||||
}
|
||||
|
||||
private void addNavigation() {
|
||||
int buttonY = 48;
|
||||
for (BlacklistCategory category : BlacklistCategory.values()) {
|
||||
Button button = Button.m_253074_((Component)this.formatCategoryLabel(category), b -> this.selectCategory(category)).m_252794_(12, buttonY).m_253046_(160, 20).m_257505_(Tooltip.m_257550_((Component)Component.translatable((String)category.getTooltipKey()))).m_253136_();
|
||||
this.categoryButtons.put(category, button);
|
||||
this.m_142416_((GuiEventListener)button);
|
||||
buttonY += 24;
|
||||
}
|
||||
}
|
||||
|
||||
private void addTopControls() {
|
||||
int listLeft = 172;
|
||||
this.backButton = Button.m_253074_((Component)Component.translatable((String)"gui.back"), b -> this.m_7379_()).m_252794_(12, 12).m_253046_(80, 20).m_253136_();
|
||||
this.m_142416_((GuiEventListener)this.backButton);
|
||||
this.searchField = new EditBox(this.f_96547_, listLeft, 26, 200, 18, (Component)Component.m_237119_());
|
||||
this.searchField.m_257771_((Component)Component.translatable((String)"option.explosionoverhaul.blacklist_search"));
|
||||
this.searchField.m_94151_(s -> this.refreshList());
|
||||
this.m_142416_((GuiEventListener)this.searchField);
|
||||
this.resetButton = Button.m_253074_((Component)Component.translatable((String)"option.explosionoverhaul.reset_list"), this::onResetClicked).m_252794_(this.f_96543_ - 250, 12).m_253046_(60, 20).m_257505_(Tooltip.m_257550_((Component)Component.translatable((String)"tooltip.explosionoverhaul.reset_list"))).m_253136_();
|
||||
this.m_142416_((GuiEventListener)this.resetButton);
|
||||
this.defaultToggle = CycleButton.m_168916_((boolean)this.showDefaults).m_232498_(value -> Tooltip.m_257550_((Component)Component.translatable((String)"tooltip.explosionoverhaul.show_defaults"))).m_168936_(this.f_96543_ - 180, 12, 168, 20, (Component)Component.translatable((String)"option.explosionoverhaul.show_defaults"), (btn, value) -> {
|
||||
this.showDefaults = value;
|
||||
this.refreshList();
|
||||
});
|
||||
this.m_142416_((GuiEventListener)this.defaultToggle);
|
||||
}
|
||||
|
||||
private void addInputArea() {
|
||||
int y = this.f_96544_ - 28;
|
||||
this.inputField = new EditBox(this.f_96547_, (this.f_96543_ - 240) / 2, y, 240, 18, (Component)Component.m_237119_());
|
||||
this.inputField.m_94199_(128);
|
||||
this.inputField.m_257771_((Component)Component.translatable((String)"option.explosionoverhaul.blacklist_input"));
|
||||
this.inputField.m_94151_(this::updateSuggestions);
|
||||
this.m_142416_((GuiEventListener)this.inputField);
|
||||
this.addButton = Button.m_253074_((Component)Component.translatable((String)"option.explosionoverhaul.blacklist_add"), b -> this.addCurrentInput()).m_252794_(this.inputField.m_252754_() + 240 + 8, this.inputField.m_252907_() - 1).m_253046_(80, 20).m_253136_();
|
||||
this.m_142416_((GuiEventListener)this.addButton);
|
||||
this.infoButton = Button.m_253074_((Component)Component.translatable((String)"option.explosionoverhaul.blacklist_info"), b -> {}).m_252794_(this.addButton.m_252754_() + 80 + 4, this.addButton.m_252907_()).m_253046_(40, 20).m_257505_(Tooltip.m_257550_((Component)Component.translatable((String)"tooltip.explosionoverhaul.blacklist_info"))).m_253136_();
|
||||
this.infoButton.f_93624_ = this.currentCategory == BlacklistCategory.SOURCES;
|
||||
this.m_142416_((GuiEventListener)this.infoButton);
|
||||
}
|
||||
|
||||
private void onResetClicked(Button b) {
|
||||
if (BlacklistScreen.m_96638_()) {
|
||||
List<String> defaults = this.currentCategory.loadDefaults();
|
||||
this.currentCategory.saveEntries(defaults);
|
||||
this.persistedEntries.clear();
|
||||
this.persistedEntries.addAll(defaults);
|
||||
if (this.currentCategory == BlacklistCategory.SOURCES) {
|
||||
this.persistedSourceModes.clear();
|
||||
this.save();
|
||||
}
|
||||
this.refreshList();
|
||||
this.displayStatus((Component)Component.translatable((String)"message.explosionoverhaul.list_reset"));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCache() {
|
||||
LinkedHashSet<String> uniqueRegistry = new LinkedHashSet<String>();
|
||||
if (this.currentCategory == BlacklistCategory.SOURCES) {
|
||||
uniqueRegistry.add("generic");
|
||||
BuiltInRegistries.ENTITY_TYPE.keySet().stream().map(ResourceLocation::toString).forEach(uniqueRegistry::add);
|
||||
BuiltInRegistries.BLOCK.keySet().stream().map(ResourceLocation::toString).forEach(uniqueRegistry::add);
|
||||
BuiltInRegistries.ITEM.keySet().stream().map(ResourceLocation::toString).forEach(uniqueRegistry::add);
|
||||
} else {
|
||||
BuiltInRegistries.BLOCK.keySet().stream().map(ResourceLocation::toString).forEach(uniqueRegistry::add);
|
||||
}
|
||||
this.registryCache = new ArrayList<String>(uniqueRegistry);
|
||||
}
|
||||
|
||||
private void loadCurrentCategoryEntries() {
|
||||
this.persistedEntries.clear();
|
||||
this.persistedEntries.addAll(this.currentCategory.loadEntries());
|
||||
if (this.currentCategory == BlacklistCategory.SOURCES) {
|
||||
this.persistedSourceModes.clear();
|
||||
this.persistedSourceModes.putAll(ExplosionOverhaul.getSourceModes());
|
||||
}
|
||||
this.defaultEntries.clear();
|
||||
this.defaultEntries.addAll(this.currentCategory.loadDefaults());
|
||||
this.refreshList();
|
||||
}
|
||||
|
||||
private void selectCategory(BlacklistCategory category) {
|
||||
if (this.currentCategory == category) {
|
||||
return;
|
||||
}
|
||||
this.currentCategory = category;
|
||||
this.updateCache();
|
||||
this.loadCurrentCategoryEntries();
|
||||
this.updateCategoryButtons();
|
||||
if (this.infoButton != null) {
|
||||
boolean bl = this.infoButton.f_93624_ = this.currentCategory == BlacklistCategory.SOURCES;
|
||||
}
|
||||
if (this.inputField != null) {
|
||||
this.inputField.m_94144_("");
|
||||
this.updateSuggestions("");
|
||||
this.inputField.m_257771_((Component)Component.translatable((String)(this.currentCategory == BlacklistCategory.SOURCES ? "option.explosionoverhaul.blacklist_input_entities" : "option.explosionoverhaul.blacklist_input")));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCategoryButtons() {
|
||||
this.categoryButtons.forEach((category, button) -> button.m_93666_(this.formatCategoryLabel((BlacklistCategory)((Object)category))));
|
||||
}
|
||||
|
||||
private Component formatCategoryLabel(BlacklistCategory category) {
|
||||
MutableComponent label = Component.translatable((String)category.getLabelKey());
|
||||
if (category == this.currentCategory) {
|
||||
return Component.literal((String)"\u25b6 ").m_7220_((Component)label);
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
private void refreshList() {
|
||||
String query = this.searchField == null ? "" : this.searchField.m_94155_().trim().toLowerCase(Locale.ROOT);
|
||||
boolean hasQuery = !query.isEmpty();
|
||||
ArrayList<BlacklistEntry> entries = new ArrayList<BlacklistEntry>();
|
||||
for (String id : this.persistedEntries) {
|
||||
boolean isDefault = this.defaultEntries.contains(id);
|
||||
if (!hasQuery && !this.showDefaults && isDefault || hasQuery && !id.toLowerCase(Locale.ROOT).contains(query)) continue;
|
||||
entries.add(new BlacklistEntry(id, isDefault));
|
||||
}
|
||||
this.widget.rebuild(entries);
|
||||
}
|
||||
|
||||
private void addCurrentInput() {
|
||||
String normalized;
|
||||
String raw = this.inputField.m_94155_().trim().toLowerCase(Locale.ROOT);
|
||||
if (raw.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (raw.equals("generic")) {
|
||||
normalized = "generic";
|
||||
} else {
|
||||
ResourceLocation id = ResourceLocation.m_135820_((String)(raw.contains(":") ? raw : "minecraft:" + raw));
|
||||
if (id == null) {
|
||||
this.displayStatus((Component)Component.translatable((String)"message.explosionoverhaul.invalid_id"));
|
||||
return;
|
||||
}
|
||||
normalized = id.toString();
|
||||
}
|
||||
if (!this.persistedEntries.add(normalized)) {
|
||||
this.displayStatus((Component)Component.translatable((String)"message.explosionoverhaul.duplicate_entry"));
|
||||
return;
|
||||
}
|
||||
if (this.currentCategory == BlacklistCategory.SOURCES) {
|
||||
this.persistedSourceModes.put(normalized, ExplosionOverhaul.ExplosionSourceMode.DEFAULT);
|
||||
}
|
||||
this.save();
|
||||
this.inputField.m_94144_("");
|
||||
this.updateSuggestions("");
|
||||
this.refreshList();
|
||||
}
|
||||
|
||||
private void removeEntry(String id) {
|
||||
if (this.persistedEntries.remove(id)) {
|
||||
if (this.currentCategory == BlacklistCategory.SOURCES) {
|
||||
this.persistedSourceModes.remove(id);
|
||||
}
|
||||
this.save();
|
||||
this.refreshList();
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
if (this.currentCategory == BlacklistCategory.SOURCES) {
|
||||
HashMap<String, ExplosionOverhaul.ExplosionSourceMode> toSave = new HashMap<String, ExplosionOverhaul.ExplosionSourceMode>();
|
||||
for (String id : this.persistedEntries) {
|
||||
toSave.put(id, this.persistedSourceModes.getOrDefault(id, ExplosionOverhaul.ExplosionSourceMode.DEFAULT));
|
||||
}
|
||||
ExplosionOverhaul.setSourceModes(toSave);
|
||||
} else {
|
||||
this.currentCategory.saveEntries(new ArrayList<String>(this.persistedEntries));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSuggestions(String current) {
|
||||
String query = current.trim().toLowerCase(Locale.ROOT);
|
||||
if (query.isEmpty()) {
|
||||
this.suggestions = Collections.emptyList();
|
||||
return;
|
||||
}
|
||||
this.suggestions = this.registryCache.stream().filter(name -> name.startsWith(query)).limit(12L).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void displayStatus(Component message) {
|
||||
if (this.f_96541_ != null && this.f_96541_.f_91065_ != null) {
|
||||
this.f_96541_.f_91065_.m_93063_(message, false);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean m_7933_(int keyCode, int scanCode, int modifiers) {
|
||||
if (this.inputField.m_93696_() && (keyCode == 257 || keyCode == 335)) {
|
||||
this.addCurrentInput();
|
||||
return true;
|
||||
}
|
||||
return super.m_7933_(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
public void m_88315_(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
|
||||
this.m_280273_(graphics);
|
||||
graphics.m_280614_(this.f_96547_, this.f_96539_, this.f_96543_ / 2 - this.f_96547_.m_92852_((FormattedText)this.f_96539_) / 2, 16, 0xFFFFFF, false);
|
||||
this.widget.m_88315_(graphics, mouseX, mouseY, delta);
|
||||
super.m_88315_(graphics, mouseX, mouseY, delta);
|
||||
this.inputField.m_88315_(graphics, mouseX, mouseY, delta);
|
||||
this.renderSuggestions(graphics, mouseX, mouseY);
|
||||
}
|
||||
|
||||
private void renderSuggestions(GuiGraphics graphics, int mouseX, int mouseY) {
|
||||
if (this.suggestions.isEmpty() || !this.inputField.m_93696_()) {
|
||||
return;
|
||||
}
|
||||
int x = this.inputField.m_252754_();
|
||||
int y = this.inputField.m_252907_() - this.suggestions.size() * 12 - 4;
|
||||
int width = this.inputField.m_5711_();
|
||||
int line = 0;
|
||||
for (String s : this.suggestions) {
|
||||
int yy = y + line * 12;
|
||||
graphics.fill(x, yy, x + width, yy + 12, -1442840576);
|
||||
graphics.m_280056_(this.f_96547_, s, x + 4, yy + 2, 0xE0E0E0, false);
|
||||
++line;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean m_6375_(double mouseX, double mouseY, int button) {
|
||||
if (this.inputField.m_93696_() && !this.suggestions.isEmpty()) {
|
||||
int x = this.inputField.m_252754_();
|
||||
int y = this.inputField.m_252907_() - this.suggestions.size() * 12 - 4;
|
||||
int width = this.inputField.m_5711_();
|
||||
for (int i = 0; i < this.suggestions.size(); ++i) {
|
||||
int yy = y + i * 12;
|
||||
if (!(mouseX >= (double)x) || !(mouseX <= (double)(x + width)) || !(mouseY >= (double)yy) || !(mouseY <= (double)(yy + 12))) continue;
|
||||
this.inputField.m_94144_(this.suggestions.get(i));
|
||||
this.inputField.m_94196_(this.inputField.m_94155_().length());
|
||||
this.updateSuggestions(this.inputField.m_94155_());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.m_6375_(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
public void m_7379_() {
|
||||
this.save();
|
||||
this.f_96541_.m_91152_(this.parent);
|
||||
}
|
||||
|
||||
private static enum BlacklistCategory {
|
||||
EXPLOSION("option.explosionoverhaul.blacklist_category_explosion", "tooltip.explosionoverhaul.blacklist_category_explosion", ExplosionOverhaul::getExplosionBlacklistList, ExplosionOverhaul::getDefaultExplosionBlacklist, ExplosionOverhaul::setExplosionBlacklistFromList),
|
||||
GLASS("option.explosionoverhaul.blacklist_category_glass", "tooltip.explosionoverhaul.blacklist_category_glass", BlockIndexManager::getReinforcedGlassBlacklist, BlockIndexManager::getDefaultReinforcedGlassBlacklist, BlockIndexManager::setReinforcedGlassBlacklistFromList),
|
||||
SOURCES("option.explosionoverhaul.blacklist_category_sources", "tooltip.explosionoverhaul.blacklist_category_sources", () -> new ArrayList<String>(ExplosionOverhaul.getSourceModes().keySet()), ArrayList::new, list -> {});
|
||||
|
||||
private final String labelKey;
|
||||
private final String tooltipKey;
|
||||
private final Supplier<List<String>> entriesSupplier;
|
||||
private final Supplier<List<String>> defaultsSupplier;
|
||||
private final Consumer<List<String>> saveAction;
|
||||
|
||||
private BlacklistCategory(String labelKey, String tooltipKey, Supplier<List<String>> entriesSupplier, Supplier<List<String>> defaultsSupplier, Consumer<List<String>> saveAction) {
|
||||
this.labelKey = labelKey;
|
||||
this.tooltipKey = tooltipKey;
|
||||
this.entriesSupplier = entriesSupplier;
|
||||
this.defaultsSupplier = defaultsSupplier;
|
||||
this.saveAction = saveAction;
|
||||
}
|
||||
|
||||
String getLabelKey() {
|
||||
return this.labelKey;
|
||||
}
|
||||
|
||||
String getTooltipKey() {
|
||||
return this.tooltipKey;
|
||||
}
|
||||
|
||||
List<String> loadEntries() {
|
||||
return this.entriesSupplier.get();
|
||||
}
|
||||
|
||||
List<String> loadDefaults() {
|
||||
return this.defaultsSupplier.get();
|
||||
}
|
||||
|
||||
void saveEntries(List<String> entries) {
|
||||
this.saveAction.accept(entries);
|
||||
}
|
||||
}
|
||||
|
||||
private class BlacklistList
|
||||
extends ObjectSelectionList<BlacklistEntry> {
|
||||
public BlacklistList(Minecraft mc, int width, int height, int top, int bottom, int itemHeight) {
|
||||
super(mc, width, height, top, bottom, itemHeight);
|
||||
}
|
||||
|
||||
void rebuild(List<BlacklistEntry> entries) {
|
||||
this.m_5988_(entries);
|
||||
}
|
||||
|
||||
public int m_5759_() {
|
||||
return this.f_93388_ - 12;
|
||||
}
|
||||
|
||||
protected int m_5756_() {
|
||||
return this.m_5747_() + this.m_5759_();
|
||||
}
|
||||
|
||||
public boolean m_7979_(double mouseX, double mouseY, int button, double dragX, double dragY) {
|
||||
return super.m_7979_(mouseX, mouseY, button, dragX, dragY);
|
||||
}
|
||||
}
|
||||
|
||||
private class BlacklistEntry
|
||||
extends ObjectSelectionList.Entry<BlacklistEntry> {
|
||||
private final String id;
|
||||
private final boolean isDefault;
|
||||
private final Button removeButton;
|
||||
private CycleButton<ExplosionOverhaul.ExplosionSourceMode> modeButton;
|
||||
private ItemStack icon;
|
||||
private int lastX;
|
||||
private int lastY;
|
||||
private int lastRowWidth;
|
||||
private int lastRowHeight;
|
||||
|
||||
BlacklistEntry(String id, boolean isDefault) {
|
||||
this.id = id;
|
||||
this.isDefault = isDefault;
|
||||
if (BlacklistScreen.this.currentCategory == BlacklistCategory.SOURCES) {
|
||||
if (id.equals("generic")) {
|
||||
this.icon = new ItemStack((ItemLike)Items.f_41996_);
|
||||
} else {
|
||||
ResourceLocation rl = ResourceLocation.m_135820_((String)id);
|
||||
ItemStack stack = ItemStack.f_41583_;
|
||||
if (rl != null) {
|
||||
Block b2;
|
||||
stack = new ItemStack((ItemLike)BuiltInRegistries.ITEM.getValue(rl));
|
||||
if (stack.m_41619_()) {
|
||||
stack = new ItemStack((ItemLike)BuiltInRegistries.ITEM.getValue(new ResourceLocation(rl.m_135827_(), rl.m_135815_() + "_spawn_egg")));
|
||||
}
|
||||
if (stack.m_41619_() && (b2 = (Block)BuiltInRegistries.BLOCK.getValue(rl)) != Blocks.f_50016_) {
|
||||
stack = new ItemStack((ItemLike)b2.m_5456_());
|
||||
}
|
||||
}
|
||||
this.icon = stack.m_41619_() ? new ItemStack((ItemLike)Items.f_41996_) : stack;
|
||||
}
|
||||
ExplosionOverhaul.ExplosionSourceMode currentMode = BlacklistScreen.this.persistedSourceModes.getOrDefault(id, ExplosionOverhaul.ExplosionSourceMode.DEFAULT);
|
||||
String entryId = id;
|
||||
this.modeButton = CycleButton.m_168894_(m -> Component.translatable((String)("option.explosionoverhaul.sourcemode_" + m.name().toLowerCase(Locale.ROOT)))).m_168961_((Object[])ExplosionOverhaul.ExplosionSourceMode.values()).m_168948_((Object)currentMode).m_232498_(m -> Tooltip.m_257550_((Component)Component.translatable((String)("tooltip.explosionoverhaul.sourcemode_" + m.name().toLowerCase(Locale.ROOT))))).m_168936_(0, 0, 150, 20, (Component)Component.m_237119_(), (btn, value) -> {
|
||||
BlacklistScreen.this.persistedSourceModes.put(entryId, (ExplosionOverhaul.ExplosionSourceMode)((Object)value));
|
||||
BlacklistScreen.this.save();
|
||||
});
|
||||
} else {
|
||||
ItemStack stack;
|
||||
Block block = (Block)BuiltInRegistries.BLOCK.getValue(ResourceLocation.m_135820_((String)id));
|
||||
ItemStack itemStack = stack = block == null || block == Blocks.f_50016_ ? ItemStack.f_41583_ : new ItemStack((ItemLike)block.m_5456_());
|
||||
if (stack.m_41619_()) {
|
||||
stack = new ItemStack((ItemLike)Items.f_42127_);
|
||||
}
|
||||
this.icon = stack;
|
||||
}
|
||||
this.removeButton = Button.m_253074_((Component)Component.literal((String)"\u2715"), b -> BlacklistScreen.this.removeEntry(this.id)).m_252794_(0, 0).m_253046_(20, 20).m_253136_();
|
||||
}
|
||||
|
||||
public Component m_142172_() {
|
||||
return Component.literal((String)this.id);
|
||||
}
|
||||
|
||||
public boolean m_6375_(double mouseX, double mouseY, int button) {
|
||||
if (this.modeButton != null && this.modeButton.m_6375_(mouseX, mouseY, button)) {
|
||||
return true;
|
||||
}
|
||||
int btnX = this.lastX + this.lastRowWidth - 26;
|
||||
int btnY = this.lastY + (this.lastRowHeight - 20) / 2;
|
||||
if (mouseX >= (double)btnX && mouseX <= (double)(btnX + 20) && mouseY >= (double)btnY && mouseY <= (double)(btnY + 20)) {
|
||||
BlacklistScreen.this.removeEntry(this.id);
|
||||
return true;
|
||||
}
|
||||
return super.m_6375_(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
public void m_6311_(GuiGraphics graphics, int index, int y, int x, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean hovered, float delta) {
|
||||
this.lastX = x;
|
||||
this.lastY = y;
|
||||
this.lastRowWidth = rowWidth;
|
||||
this.lastRowHeight = rowHeight;
|
||||
int iconX = x + 6;
|
||||
int iconY = y + (rowHeight - 16) / 2;
|
||||
try {
|
||||
graphics.m_280480_(this.icon, iconX, iconY);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
this.icon = new ItemStack((ItemLike)Items.f_42127_);
|
||||
graphics.m_280480_(this.icon, iconX, iconY);
|
||||
}
|
||||
int textX = iconX + 22;
|
||||
int color = this.isDefault ? -5197648 : -1;
|
||||
graphics.m_280056_(BlacklistScreen.this.f_96547_, this.id, textX, y + (rowHeight - 8) / 2, color, false);
|
||||
if (this.modeButton != null) {
|
||||
int modeX = x + rowWidth - 180;
|
||||
this.modeButton.m_264152_(modeX, y + (rowHeight - 20) / 2);
|
||||
this.modeButton.m_88315_(graphics, mouseX, mouseY, delta);
|
||||
}
|
||||
int btnX = x + rowWidth - 26;
|
||||
this.removeButton.m_264152_(btnX, y + (rowHeight - 20) / 2);
|
||||
this.removeButton.m_88315_(graphics, mouseX, mouseY, delta);
|
||||
}
|
||||
@Override
|
||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
|
||||
super.render(graphics, mouseX, mouseY, partialTick);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,262 +1,49 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.vinlanx.explosionoverhaul.client;
|
||||
|
||||
import com.mojang.blaze3d.pipeline.RenderTarget;
|
||||
import com.mojang.blaze3d.pipeline.TextureTarget;
|
||||
import com.mojang.blaze3d.shaders.Uniform;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.BufferUploader;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.vinlanx.explosionoverhaul.client.ConcussionAudioEffect;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(value=Dist.CLIENT)
|
||||
public class Blur {
|
||||
private static final int FADE_IN_TICKS = 40;
|
||||
private static final int FADE_OUT_TICKS = 100;
|
||||
private static Phase phase = Phase.IDLE;
|
||||
private static int holdTicks = 0;
|
||||
private static int ticksInPhase = 0;
|
||||
private static ShaderInstance shader;
|
||||
private static RenderTarget blurTarget;
|
||||
private static int lastWidth;
|
||||
private static int lastHeight;
|
||||
private static float currentIntensity;
|
||||
private static float targetIntensity;
|
||||
private static float currentDesaturation;
|
||||
public static boolean APPLY_TO_HUD;
|
||||
public static boolean APPLY_TO_HAND;
|
||||
|
||||
public static boolean isActive() {
|
||||
return phase != Phase.IDLE;
|
||||
}
|
||||
|
||||
public static float getCurrentIntensity() {
|
||||
return currentIntensity;
|
||||
}
|
||||
|
||||
public static void setShader(ShaderInstance instance) {
|
||||
shader = instance;
|
||||
}
|
||||
|
||||
public static void setDesaturation(float v) {
|
||||
currentDesaturation = Mth.m_14036_((float)v, (float)0.0f, (float)1.0f);
|
||||
public static void setShader(ShaderInstance shader) {
|
||||
}
|
||||
|
||||
public static void start(int seconds) {
|
||||
Blur.start(seconds, 1.0f);
|
||||
}
|
||||
|
||||
public static void start(int seconds, float intensity) {
|
||||
int newHoldTicks = Mth.m_14045_((int)seconds, (int)1, (int)100) * 20;
|
||||
float newIntensity = Mth.m_14036_((float)intensity, (float)0.0f, (float)1.0f);
|
||||
if (phase != Phase.IDLE) {
|
||||
targetIntensity = Mth.m_14036_((float)(targetIntensity + newIntensity), (float)0.0f, (float)1.0f);
|
||||
holdTicks = Math.min(2000, holdTicks + newHoldTicks);
|
||||
if (phase == Phase.FADE_OUT) {
|
||||
phase = Phase.HOLD;
|
||||
ticksInPhase = 0;
|
||||
}
|
||||
} else {
|
||||
holdTicks = newHoldTicks;
|
||||
ticksInPhase = 0;
|
||||
targetIntensity = newIntensity;
|
||||
phase = Phase.FADE_IN;
|
||||
currentIntensity = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
phase = Phase.IDLE;
|
||||
ticksInPhase = 0;
|
||||
holdTicks = 0;
|
||||
currentIntensity = 0.0f;
|
||||
targetIntensity = 0.0f;
|
||||
}
|
||||
|
||||
public static void onClientTick() {
|
||||
float intensity;
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.m_91104_() || phase == Phase.IDLE) {
|
||||
return;
|
||||
}
|
||||
++ticksInPhase;
|
||||
switch (phase) {
|
||||
case FADE_IN: {
|
||||
float t = Math.min(1.0f, (float)ticksInPhase / 40.0f);
|
||||
intensity = Blur.easeOutCubic(t) * targetIntensity;
|
||||
if (ticksInPhase < 40) break;
|
||||
phase = Phase.HOLD;
|
||||
ticksInPhase = 0;
|
||||
break;
|
||||
}
|
||||
case HOLD: {
|
||||
intensity = targetIntensity;
|
||||
if (ticksInPhase < holdTicks) break;
|
||||
phase = Phase.FADE_OUT;
|
||||
ticksInPhase = 0;
|
||||
break;
|
||||
}
|
||||
case FADE_OUT: {
|
||||
float t = Math.min(1.0f, (float)ticksInPhase / 100.0f);
|
||||
intensity = targetIntensity * (1.0f - Blur.easeInCubic(t));
|
||||
if (ticksInPhase < 100) break;
|
||||
currentIntensity = 0.0f;
|
||||
Blur.stop();
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
intensity = 0.0f;
|
||||
}
|
||||
}
|
||||
currentIntensity = intensity;
|
||||
if (mc.player != null) {
|
||||
ConcussionAudioEffect.updateHeartbeat(mc.player, currentIntensity);
|
||||
}
|
||||
|
||||
public static boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void render(RenderStage stage) {
|
||||
if (phase == Phase.IDLE || shader == null) {
|
||||
return;
|
||||
}
|
||||
if (!Blur.shouldRenderStage(stage)) {
|
||||
return;
|
||||
}
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null) {
|
||||
return;
|
||||
}
|
||||
RenderTarget mainTarget = mc.m_91385_();
|
||||
if (mainTarget == null) {
|
||||
return;
|
||||
}
|
||||
Blur.ensureTarget(mainTarget.f_83915_, mainTarget.f_83916_);
|
||||
if (blurTarget == null) {
|
||||
return;
|
||||
}
|
||||
RenderSystem.disableDepthTest();
|
||||
RenderSystem.depthMask((boolean)false);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.setShaderColor((float)1.0f, (float)1.0f, (float)1.0f, (float)1.0f);
|
||||
blurTarget.m_83947_(true);
|
||||
RenderSystem.viewport((int)0, (int)0, (int)Blur.blurTarget.f_83915_, (int)Blur.blurTarget.f_83916_);
|
||||
Blur.renderFullscreen(mainTarget.m_83975_(), currentIntensity, mainTarget.f_83915_, mainTarget.f_83916_);
|
||||
mainTarget.m_83947_(true);
|
||||
RenderSystem.viewport((int)0, (int)0, (int)mainTarget.f_83915_, (int)mainTarget.f_83916_);
|
||||
Blur.renderFullscreen(blurTarget.m_83975_(), 0.0f, mainTarget.f_83915_, mainTarget.f_83916_);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.depthMask((boolean)true);
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
private static boolean shouldRenderStage(RenderStage stage) {
|
||||
if (APPLY_TO_HUD) {
|
||||
return stage == RenderStage.HUD;
|
||||
}
|
||||
if (APPLY_TO_HAND && Blur.isFirstPerson()) {
|
||||
return stage == RenderStage.HAND;
|
||||
}
|
||||
return stage == RenderStage.WORLD;
|
||||
}
|
||||
|
||||
private static boolean isFirstPerson() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null) {
|
||||
public static boolean shouldRenderStage(RenderStage stage) {
|
||||
return false;
|
||||
}
|
||||
return mc.options.m_92176_().m_90612_();
|
||||
|
||||
public static boolean isFirstPerson() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void ensureTarget(int width, int height) {
|
||||
if (blurTarget == null || width != lastWidth || height != lastHeight) {
|
||||
if (blurTarget != null) {
|
||||
blurTarget.m_83930_();
|
||||
}
|
||||
blurTarget = new TextureTarget(width, height, false, Minecraft.f_91002_);
|
||||
lastWidth = width;
|
||||
lastHeight = height;
|
||||
}
|
||||
public static float easeOutCubic(float t) {
|
||||
return 1.0f - (float)Math.pow(1.0f - t, 3.0);
|
||||
}
|
||||
|
||||
private static void renderFullscreen(int textureId, float intensity, int width, int height) {
|
||||
Uniform desatUniform;
|
||||
Uniform vignetteUniform;
|
||||
Uniform heartbeatUniform;
|
||||
Uniform outSizeUniform;
|
||||
Uniform inSizeUniform;
|
||||
RenderSystem.setShader(() -> shader);
|
||||
RenderSystem.setShaderTexture((int)0, (int)textureId);
|
||||
shader.m_173350_("DiffuseSampler", (Object)textureId);
|
||||
float clamped = Mth.m_14036_((float)intensity, (float)0.0f, (float)1.0f);
|
||||
Uniform intensityUniform = shader.m_173348_("Intensity");
|
||||
if (intensityUniform != null) {
|
||||
intensityUniform.m_5985_(clamped);
|
||||
}
|
||||
if ((inSizeUniform = shader.m_173348_("InSize")) != null) {
|
||||
inSizeUniform.m_7971_((float)width, (float)height);
|
||||
}
|
||||
if ((outSizeUniform = shader.m_173348_("OutSize")) != null) {
|
||||
outSizeUniform.m_7971_((float)width, (float)height);
|
||||
}
|
||||
if ((heartbeatUniform = shader.m_173348_("Heartbeat")) != null) {
|
||||
heartbeatUniform.m_5985_(ConcussionAudioEffect.getCurrentHeartbeatVisual());
|
||||
}
|
||||
if ((vignetteUniform = shader.m_173348_("Vignette")) != null) {
|
||||
vignetteUniform.m_5985_(1.0E-5f);
|
||||
}
|
||||
if ((desatUniform = shader.m_173348_("Desaturation")) != null) {
|
||||
desatUniform.m_5985_(clamped);
|
||||
}
|
||||
BufferBuilder builder = Tesselator.m_85913_().m_85915_();
|
||||
builder.m_166779_(VertexFormat.Mode.QUADS, DefaultVertexFormat.f_85817_);
|
||||
builder.m_5483_(-1.0, -1.0, 0.0).m_7421_(0.0f, 1.0f).m_5752_();
|
||||
builder.m_5483_(1.0, -1.0, 0.0).m_7421_(1.0f, 1.0f).m_5752_();
|
||||
builder.m_5483_(1.0, 1.0, 0.0).m_7421_(1.0f, 0.0f).m_5752_();
|
||||
builder.m_5483_(-1.0, 1.0, 0.0).m_7421_(0.0f, 0.0f).m_5752_();
|
||||
BufferUploader.m_231202_((BufferBuilder.RenderedBuffer)builder.m_231175_());
|
||||
}
|
||||
|
||||
private static float easeOutCubic(float t) {
|
||||
float inv = 1.0f - t;
|
||||
return 1.0f - inv * inv * inv;
|
||||
}
|
||||
|
||||
private static float easeInCubic(float t) {
|
||||
public static float easeInCubic(float t) {
|
||||
return t * t * t;
|
||||
}
|
||||
|
||||
static {
|
||||
lastWidth = -1;
|
||||
lastHeight = -1;
|
||||
currentIntensity = 0.0f;
|
||||
targetIntensity = 1.0f;
|
||||
currentDesaturation = 0.0f;
|
||||
APPLY_TO_HUD = false;
|
||||
APPLY_TO_HAND = true;
|
||||
}
|
||||
|
||||
private static enum Phase {
|
||||
IDLE,
|
||||
FADE_IN,
|
||||
HOLD,
|
||||
FADE_OUT;
|
||||
|
||||
}
|
||||
|
||||
public static enum RenderStage {
|
||||
public enum RenderStage {
|
||||
WORLD,
|
||||
HAND,
|
||||
HUD;
|
||||
|
||||
HUD
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +1,12 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.vinlanx.explosionoverhaul.client;
|
||||
|
||||
import com.vinlanx.explosionoverhaul.ModSounds;
|
||||
import com.vinlanx.explosionoverhaul.client.Blur;
|
||||
import com.vinlanx.explosionoverhaul.client.DeafnessConcussionEffect;
|
||||
import com.vinlanx.explosionoverhaul.client.FadingMusicInstance;
|
||||
import com.vinlanx.explosionoverhaul.client.LowPassConcussionEffect;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.event.TickEvent;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
|
||||
@OnlyIn(value=Dist.CLIENT)
|
||||
@EventBusSubscriber(modid="explosionoverhaul", value={Dist.CLIENT})
|
||||
public class ConcussionSoundManager {
|
||||
private static FadingMusicInstance currentLowSound = null;
|
||||
public static void startLowSound(float volume) {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.END) {
|
||||
return;
|
||||
}
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.f_91073_ == null || mc.player == null) {
|
||||
if (currentLowSound != null) {
|
||||
mc.m_91106_().m_120399_((SoundInstance)currentLowSound);
|
||||
currentLowSound = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mc.m_91104_()) {
|
||||
return;
|
||||
}
|
||||
boolean deafness = DeafnessConcussionEffect.isActive();
|
||||
boolean lowpass = LowPassConcussionEffect.isActive();
|
||||
boolean blur = Blur.isActive();
|
||||
float targetVolume = 0.0f;
|
||||
if (blur) {
|
||||
if (deafness) {
|
||||
targetVolume = 1.0f;
|
||||
} else if (lowpass) {
|
||||
targetVolume = 0.4f;
|
||||
}
|
||||
}
|
||||
if (targetVolume > 0.0f) {
|
||||
if (currentLowSound == null || !mc.m_91106_().m_120403_((SoundInstance)currentLowSound)) {
|
||||
currentLowSound = new FadingMusicInstance((SoundEvent)ModSounds.LOW_SOUND.get(), 0.01f, SoundSource.MASTER);
|
||||
currentLowSound.fadeTo(targetVolume, 1.0f);
|
||||
mc.m_91106_().m_120367_((SoundInstance)currentLowSound);
|
||||
} else if (Math.abs(currentLowSound.getCurrentVolume() - targetVolume) > 0.01f && !currentLowSound.hasFinishedFading()) {
|
||||
currentLowSound.fadeTo(targetVolume, 0.5f);
|
||||
}
|
||||
} else if (currentLowSound != null && mc.m_91106_().m_120403_((SoundInstance)currentLowSound) && !currentLowSound.hasFinishedFading()) {
|
||||
currentLowSound.fadeOutAndStop(1.0f);
|
||||
public static void stopLowSound() {
|
||||
}
|
||||
|
||||
public static void tick() {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user