Allow multiple mob effects at once when holding shift. Closes #23
This commit is contained in:
@@ -103,4 +103,15 @@ public class EffectInstance
|
||||
{
|
||||
return seconds + minutes * 60 + hours * 3600;
|
||||
}
|
||||
|
||||
public EffectInstance copyTo(EffectInstance effectInstance, float modifier)
|
||||
{
|
||||
effectInstance.setAmbient(this.isAmbient());
|
||||
effectInstance.setAmplifier(this.getAmplifier());
|
||||
effectInstance.setHours((int) (this.getHours() / modifier));
|
||||
effectInstance.setMinutes((int) (this.getMinutes() / modifier));
|
||||
effectInstance.setSeconds((int) (this.getSeconds() / modifier));
|
||||
effectInstance.setShowParticles(this.doShowParticles());
|
||||
return effectInstance;
|
||||
}
|
||||
}
|
||||
@@ -136,4 +136,9 @@ public abstract class Content implements IContent
|
||||
|
||||
return (T) this.persistence.computeIfAbsent(id, key -> supplier.get());
|
||||
}
|
||||
|
||||
public void resetPersistence()
|
||||
{
|
||||
this.persistence.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import exopandora.worldhandler.util.ActionHandler;
|
||||
import exopandora.worldhandler.util.ActionHelper;
|
||||
import exopandora.worldhandler.util.CommandHelper;
|
||||
import exopandora.worldhandler.util.TextUtils;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
@@ -89,15 +90,6 @@ public class ContentPotions extends ContentChild
|
||||
public void onClick(MobEffect effect)
|
||||
{
|
||||
ContentPotions.this.builderPotion.effect().set(effect);
|
||||
|
||||
for(MobEffect entry : ContentPotions.this.effects.getMobEffects())
|
||||
{
|
||||
if(!entry.equals(effect))
|
||||
{
|
||||
ContentPotions.this.effects.remove(entry);
|
||||
}
|
||||
}
|
||||
|
||||
container.initButtons();
|
||||
}
|
||||
|
||||
@@ -131,20 +123,29 @@ public class ContentPotions extends ContentChild
|
||||
|
||||
if(this.potionPage == 0)
|
||||
{
|
||||
container.add(new GuiButtonBase(x + 118, y + 12, 114, 20, Component.translatable("gui.worldhandler.potions.effect.give"), () ->
|
||||
container.add(new GuiButtonBase(x + 118, y, 114, 20, Component.translatable("gui.worldhandler.potions.effect.give"), () ->
|
||||
{
|
||||
this.next(container);
|
||||
}));
|
||||
container.add(new GuiButtonBase(x + 118, y + 36, 114, 20, Component.translatable("gui.worldhandler.potions.effect.remove"), () ->
|
||||
container.add(new GuiButtonBase(x + 118, y + 24, 114, 20, Component.translatable("gui.worldhandler.potions.effect.remove"), () ->
|
||||
{
|
||||
CommandHelper.sendCommand(container.getPlayer(), this.builderPotion, EffectCommandBuilder.Label.CLEAR_TARGETS_EFFECT);
|
||||
container.init();
|
||||
}));
|
||||
container.add(new GuiButtonBase(x + 118, y + 60, 114, 20, Component.translatable("gui.worldhandler.potions.effect.remove_all"), () ->
|
||||
container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, Component.translatable("gui.worldhandler.potions.effect.remove_all"), () ->
|
||||
{
|
||||
CommandHelper.sendCommand(container.getPlayer(), this.builderPotion, EffectCommandBuilder.Label.CLEAR);
|
||||
container.init();
|
||||
}));
|
||||
container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, Component.translatable("gui.worldhandler.actions.reset_all"), () ->
|
||||
{
|
||||
this.builderPotion.amplifier().set((byte) 1);
|
||||
this.builderPotion.seconds().set(0);
|
||||
this.builderPotion.hideParticles().set(false);
|
||||
this.effects.clear();
|
||||
this.resetPersistence();
|
||||
container.init();
|
||||
}));
|
||||
}
|
||||
else if(this.potionPage == 1)
|
||||
{
|
||||
@@ -197,27 +198,27 @@ public class ContentPotions extends ContentChild
|
||||
this.potionPage = 0;
|
||||
container.init();
|
||||
}));
|
||||
container.add(button2 = new GuiButtonBase(x + 118, y + 24, 56, 20, Component.translatable("gui.worldhandler.potions.effect.tipped_arrow"), () ->
|
||||
container.add(button2 = new GuiButtonTooltip(x + 118, y + 24, 56, 20, Component.translatable("gui.worldhandler.potions.effect.tipped_arrow"), Component.translatable("gui.worldhandler.potions.effect.hold_to_apply_all_effects_at_once"), () ->
|
||||
{
|
||||
this.giveItem(container.getPlayer(), Items.TIPPED_ARROW, 0.125F);
|
||||
this.giveItem(container.getPlayer(), Items.TIPPED_ARROW, 0.125F, Screen.hasShiftDown());
|
||||
this.potionPage = 0;
|
||||
container.init();
|
||||
}));
|
||||
container.add(button3 = new GuiButtonTooltip(x + 178, y + 24, 55, 20, Component.translatable("gui.worldhandler.potions.effect.bottle"), Component.translatable("gui.worldhandler.actions.place_command_block"), () ->
|
||||
container.add(button3 = new GuiButtonTooltip(x + 178, y + 24, 55, 20, Component.translatable("gui.worldhandler.potions.effect.bottle"), Component.translatable("gui.worldhandler.potions.effect.hold_to_apply_all_effects_at_once"), () ->
|
||||
{
|
||||
this.giveItem(container.getPlayer(), Items.POTION, 1.0F);
|
||||
this.giveItem(container.getPlayer(), Items.POTION, 1.0F, Screen.hasShiftDown());
|
||||
this.potionPage = 0;
|
||||
container.init();
|
||||
}));
|
||||
container.add(button4 = new GuiButtonTooltip(x + 118, y + 48, 56, 20, Component.translatable("gui.worldhandler.potions.effect.splash"), Component.translatable("gui.worldhandler.actions.place_command_block"), () ->
|
||||
container.add(button4 = new GuiButtonTooltip(x + 118, y + 48, 56, 20, Component.translatable("gui.worldhandler.potions.effect.splash"), Component.translatable("gui.worldhandler.potions.effect.hold_to_apply_all_effects_at_once"), () ->
|
||||
{
|
||||
this.giveItem(container.getPlayer(), Items.SPLASH_POTION, 1.0F);
|
||||
this.giveItem(container.getPlayer(), Items.SPLASH_POTION, 1.0F, Screen.hasShiftDown());
|
||||
this.potionPage = 0;
|
||||
container.init();
|
||||
}));
|
||||
container.add(button5 = new GuiButtonTooltip(x + 178, y + 48, 55, 20, Component.translatable("gui.worldhandler.potions.effect.lingering"), Component.translatable("gui.worldhandler.actions.place_command_block"), () ->
|
||||
container.add(button5 = new GuiButtonTooltip(x + 178, y + 48, 55, 20, Component.translatable("gui.worldhandler.potions.effect.lingering"), Component.translatable("gui.worldhandler.potions.effect.hold_to_apply_all_effects_at_once"), () ->
|
||||
{
|
||||
this.giveItem(container.getPlayer(), Items.LINGERING_POTION, 0.25F);
|
||||
this.giveItem(container.getPlayer(), Items.LINGERING_POTION, 0.25F, Screen.hasShiftDown());
|
||||
this.potionPage = 0;
|
||||
container.init();
|
||||
}));
|
||||
@@ -253,19 +254,27 @@ public class ContentPotions extends ContentChild
|
||||
container.init();
|
||||
}
|
||||
|
||||
private void giveItem(String player, Item item, float modifier)
|
||||
private void giveItem(String player, Item item, float modifier, boolean applyAllEffects)
|
||||
{
|
||||
CustomPotionEffectsTag effects = new CustomPotionEffectsTag();
|
||||
MobEffect effect = this.builderPotion.effect().getEffect();
|
||||
EffectInstance tag = effects.getOrCreate(effect);
|
||||
EffectInstance original = this.effects.getOrCreate(effect);
|
||||
|
||||
tag.setAmbient(original.isAmbient());
|
||||
tag.setAmplifier(original.getAmplifier());
|
||||
tag.setHours((int) (original.getHours() / modifier));
|
||||
tag.setMinutes((int) (original.getMinutes() / modifier));
|
||||
tag.setSeconds((int) (original.getSeconds() / modifier));
|
||||
tag.setShowParticles(original.doShowParticles());
|
||||
if(applyAllEffects)
|
||||
{
|
||||
for(MobEffect effect : this.effects.getMobEffects())
|
||||
{
|
||||
System.out.println(effect);
|
||||
EffectInstance source = this.effects.getOrCreate(effect);
|
||||
EffectInstance target = effects.getOrCreate(effect);
|
||||
source.copyTo(target, modifier);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MobEffect effect = this.builderPotion.effect().getEffect();
|
||||
EffectInstance source = this.effects.getOrCreate(effect);
|
||||
EffectInstance target = effects.getOrCreate(effect);
|
||||
source.copyTo(target, modifier);
|
||||
}
|
||||
|
||||
GiveCommandBuilder builder = new GiveCommandBuilder();
|
||||
builder.targets().setTarget(this.builderPotionItem.targets().getTarget());
|
||||
|
||||
@@ -162,6 +162,7 @@
|
||||
"gui.worldhandler.potions.effect.splash": "Wurftrank",
|
||||
"gui.worldhandler.potions.effect.lingering": "Verweil",
|
||||
"gui.worldhandler.potions.effect.tipped_arrow": "Pfeil",
|
||||
"gui.worldhandler.potions.effect.hold_shift_to_apply_all_effects_at_once": "Halte die Umschalttaste gedrückt, um alle Effekte auf einmal anzuwenden",
|
||||
|
||||
"gui.worldhandler.command_stack.insert_command": "Kommando Einfügen",
|
||||
"gui.worldhandler.command_stack.remove_command": "Kommando Entfernen",
|
||||
@@ -372,6 +373,7 @@
|
||||
"gui.worldhandler.actions.remove": "Entfernen",
|
||||
"gui.worldhandler.actions.set": "Setzen",
|
||||
"gui.worldhandler.actions.reset": "Zurücksetzen",
|
||||
"gui.worldhandler.actions.reset_all": "Alles Zurücksetzen",
|
||||
"gui.worldhandler.actions.set_to_0": "Auf 0 setzen",
|
||||
"gui.worldhandler.actions.perform": "Ausführen",
|
||||
"gui.worldhandler.actions.send": "Senden",
|
||||
|
||||
@@ -162,6 +162,7 @@
|
||||
"gui.worldhandler.potions.effect.splash": "Splash",
|
||||
"gui.worldhandler.potions.effect.lingering": "Lingering",
|
||||
"gui.worldhandler.potions.effect.tipped_arrow": "Arrow",
|
||||
"gui.worldhandler.potions.effect.hold_shift_to_apply_all_effects_at_once": "Hold Shift to apply all effects at once",
|
||||
|
||||
"gui.worldhandler.command_stack.insert_command": "Insert Command",
|
||||
"gui.worldhandler.command_stack.remove_command": "Remove Command",
|
||||
@@ -372,6 +373,7 @@
|
||||
"gui.worldhandler.actions.remove": "Remove",
|
||||
"gui.worldhandler.actions.set": "Set",
|
||||
"gui.worldhandler.actions.reset": "Reset",
|
||||
"gui.worldhandler.actions.reset_all": "Reset All",
|
||||
"gui.worldhandler.actions.set_to_0": "Set To 0",
|
||||
"gui.worldhandler.actions.perform": "Perform",
|
||||
"gui.worldhandler.actions.send": "Send",
|
||||
|
||||
@@ -162,6 +162,7 @@
|
||||
"gui.worldhandler.potions.effect.splash": "Jetable",
|
||||
"gui.worldhandler.potions.effect.lingering": "Persistant",
|
||||
"gui.worldhandler.potions.effect.tipped_arrow": "Flèche",
|
||||
"gui.worldhandler.potions.effect.hold_shift_to_apply_all_effects_at_once": "Hold Shift to apply all effects at once",
|
||||
|
||||
"gui.worldhandler.command_stack.insert_command": "Insérer la commande",
|
||||
"gui.worldhandler.command_stack.remove_command": "Supprimer la commande",
|
||||
@@ -373,6 +374,7 @@
|
||||
"gui.worldhandler.actions.remove": "Supprimer",
|
||||
"gui.worldhandler.actions.set": "Définir",
|
||||
"gui.worldhandler.actions.reset": "Réinitialiser",
|
||||
"gui.worldhandler.actions.reset_all": "Reset All",
|
||||
"gui.worldhandler.actions.set_to_0": "Définir sur 0",
|
||||
"gui.worldhandler.actions.perform": "Exécuter",
|
||||
"gui.worldhandler.actions.send": "Envoyer",
|
||||
|
||||
@@ -162,6 +162,7 @@
|
||||
"gui.worldhandler.potions.effect.splash": "Всплеск",
|
||||
"gui.worldhandler.potions.effect.lingering": "Длительный",
|
||||
"gui.worldhandler.potions.effect.tipped_arrow": "Стрела",
|
||||
"gui.worldhandler.potions.effect.hold_shift_to_apply_all_effects_at_once": "Hold Shift to apply all effects at once",
|
||||
|
||||
"gui.worldhandler.command_stack.insert_command": "Вставить команду",
|
||||
"gui.worldhandler.command_stack.remove_command": "Удалить команду",
|
||||
@@ -372,6 +373,7 @@
|
||||
"gui.worldhandler.actions.remove": "Удалить",
|
||||
"gui.worldhandler.actions.set": "Установить",
|
||||
"gui.worldhandler.actions.reset": "Сбросить",
|
||||
"gui.worldhandler.actions.reset_all": "Reset All",
|
||||
"gui.worldhandler.actions.set_to_0": "Установить на 0",
|
||||
"gui.worldhandler.actions.perform": "Выполнить",
|
||||
"gui.worldhandler.actions.send": "Отправить",
|
||||
|
||||
@@ -163,6 +163,7 @@
|
||||
"gui.worldhandler.potions.effect.splash": "喷溅",
|
||||
"gui.worldhandler.potions.effect.lingering": "滞留",
|
||||
"gui.worldhandler.potions.effect.tipped_arrow": "箭",
|
||||
"gui.worldhandler.potions.effect.hold_shift_to_apply_all_effects_at_once": "Hold Shift to apply all effects at once",
|
||||
|
||||
"gui.worldhandler.command_stack.insert_command": "Insert Command",
|
||||
"gui.worldhandler.command_stack.remove_command": "Remove Command",
|
||||
@@ -373,6 +374,7 @@
|
||||
"gui.worldhandler.actions.remove": "删除",
|
||||
"gui.worldhandler.actions.set": "固定",
|
||||
"gui.worldhandler.actions.reset": "重置",
|
||||
"gui.worldhandler.actions.reset_all": "Reset All",
|
||||
"gui.worldhandler.actions.set_to_0": "重置为 0",
|
||||
"gui.worldhandler.actions.perform": "执行",
|
||||
"gui.worldhandler.actions.send": "发送",
|
||||
|
||||
Reference in New Issue
Block a user