Add butcher presets

This commit is contained in:
Marcel Konrad
2020-07-28 20:20:10 +02:00
parent 354d201ea5
commit e3e4891d75
12 changed files with 154 additions and 40 deletions

View File

@@ -7,6 +7,7 @@ import java.util.function.Supplier;
import exopandora.worldhandler.Main; import exopandora.worldhandler.Main;
import exopandora.worldhandler.gui.content.impl.ContentAdvancements; import exopandora.worldhandler.gui.content.impl.ContentAdvancements;
import exopandora.worldhandler.gui.content.impl.ContentButcher; import exopandora.worldhandler.gui.content.impl.ContentButcher;
import exopandora.worldhandler.gui.content.impl.ContentButcherPresets;
import exopandora.worldhandler.gui.content.impl.ContentButcherSettings; import exopandora.worldhandler.gui.content.impl.ContentButcherSettings;
import exopandora.worldhandler.gui.content.impl.ContentChangeWorld; import exopandora.worldhandler.gui.content.impl.ContentChangeWorld;
import exopandora.worldhandler.gui.content.impl.ContentCommandStack; import exopandora.worldhandler.gui.content.impl.ContentCommandStack;
@@ -70,6 +71,9 @@ public abstract class Content extends ForgeRegistryEntry<Content> implements ICo
//ENTITIES //ENTITIES
RegistryHelper.register(event.getRegistry(), "summon", new ContentSummon()); RegistryHelper.register(event.getRegistry(), "summon", new ContentSummon());
RegistryHelper.register(event.getRegistry(), "butcher", new ContentButcher());
RegistryHelper.register(event.getRegistry(), "butcher_settings", new ContentButcherSettings());
RegistryHelper.register(event.getRegistry(), "butcher_presets", new ContentButcherPresets());
//ITEMS //ITEMS
RegistryHelper.register(event.getRegistry(), "custom_item", new ContentCustomItem()); RegistryHelper.register(event.getRegistry(), "custom_item", new ContentCustomItem());
@@ -102,8 +106,6 @@ public abstract class Content extends ForgeRegistryEntry<Content> implements ICo
//NO CATEGORY //NO CATEGORY
RegistryHelper.register(event.getRegistry(), "potions", new ContentPotions()); RegistryHelper.register(event.getRegistry(), "potions", new ContentPotions());
RegistryHelper.register(event.getRegistry(), "command_stack", new ContentCommandStack()); RegistryHelper.register(event.getRegistry(), "command_stack", new ContentCommandStack());
RegistryHelper.register(event.getRegistry(), "butcher", new ContentButcher());
RegistryHelper.register(event.getRegistry(), "butcher_settings", new ContentButcherSettings());
RegistryHelper.register(event.getRegistry(), "settings", new ContentSettings()); RegistryHelper.register(event.getRegistry(), "settings", new ContentSettings());
//USERCONTENT //USERCONTENT

View File

@@ -1,6 +1,7 @@
package exopandora.worldhandler.gui.content; package exopandora.worldhandler.gui.content;
import exopandora.worldhandler.Main; import exopandora.worldhandler.Main;
import exopandora.worldhandler.gui.content.impl.ContentButcherPresets;
import exopandora.worldhandler.gui.content.impl.ContentChild; import exopandora.worldhandler.gui.content.impl.ContentChild;
import exopandora.worldhandler.gui.content.impl.ContentContinue; import exopandora.worldhandler.gui.content.impl.ContentContinue;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@@ -15,6 +16,9 @@ public class Contents
public static final Content MULTIPLAYER = Contents.getRegisteredContent("multiplayer"); public static final Content MULTIPLAYER = Contents.getRegisteredContent("multiplayer");
public static final Content SUMMON = Contents.getRegisteredContent("summon"); public static final Content SUMMON = Contents.getRegisteredContent("summon");
public static final Content BUTCHER = Contents.getRegisteredContent("butcher");
public static final ContentChild BUTCHER_SETTINGS = (ContentChild) Contents.getRegisteredContent("butcher_settings");
public static final ContentButcherPresets BUTCHER_PRESETS = (ContentButcherPresets) Contents.getRegisteredContent("butcher_presets");
public static final Content CUSTOM_ITEM = Contents.getRegisteredContent("custom_item"); public static final Content CUSTOM_ITEM = Contents.getRegisteredContent("custom_item");
public static final Content ENCHANTMENT = Contents.getRegisteredContent("enchantment"); public static final Content ENCHANTMENT = Contents.getRegisteredContent("enchantment");
@@ -40,8 +44,6 @@ public class Contents
public static final ContentChild POTIONS = (ContentChild) Contents.getRegisteredContent("potions"); public static final ContentChild POTIONS = (ContentChild) Contents.getRegisteredContent("potions");
public static final ContentChild COMMAND_STACK = (ContentChild) Contents.getRegisteredContent("command_stack"); public static final ContentChild COMMAND_STACK = (ContentChild) Contents.getRegisteredContent("command_stack");
public static final Content BUTCHER = Contents.getRegisteredContent("butcher");
public static final ContentChild BUTCHER_SETTINGS = (ContentChild) Contents.getRegisteredContent("butcher_settings");
public static final ContentChild SETTINGS = (ContentChild) Contents.getRegisteredContent("settings"); public static final ContentChild SETTINGS = (ContentChild) Contents.getRegisteredContent("settings");
public static Content getRegisteredContent(String name) public static Content getRegisteredContent(String name)

View File

@@ -1,6 +1,8 @@
package exopandora.worldhandler.gui.content.impl; package exopandora.worldhandler.gui.content.impl;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
@@ -19,8 +21,8 @@ import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.ActionHelper;
import exopandora.worldhandler.util.CommandHelper; import exopandora.worldhandler.util.CommandHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.text.IFormattableTextComponent; import net.minecraft.util.text.IFormattableTextComponent;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
@@ -44,7 +46,7 @@ public class ContentButcher extends Content
@Override @Override
public void initGui(Container container, int x, int y) public void initGui(Container container, int x, int y)
{ {
this.radiusField = new GuiTextFieldTooltip(x + 116 / 2, y + 12, 116, 20, new TranslationTextComponent("gui.worldhandler.butcher.radius")); this.radiusField = new GuiTextFieldTooltip(x + 58, y, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.radius"));
this.radiusField.setValidator(string -> this.radiusField.setValidator(string ->
{ {
if(string == null) if(string == null)
@@ -93,32 +95,40 @@ public class ContentButcher extends Content
container.add(new GuiButtonBase(x + 118, y + 96, 114, 20, new TranslationTextComponent("gui.worldhandler.generic.backToGame"), ActionHelper::backToGame)); container.add(new GuiButtonBase(x + 118, y + 96, 114, 20, new TranslationTextComponent("gui.worldhandler.generic.backToGame"), ActionHelper::backToGame));
container.add(this.radiusField); container.add(this.radiusField);
container.add(new GuiButtonBase(x + 116 / 2, y + 36, 232 / 2, 20, new TranslationTextComponent("gui.worldhandler.butcher.configure"), () -> container.add(new GuiButtonBase(x + 58, y + 24, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.configure"), () ->
{ {
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.BUTCHER_SETTINGS.withParent(Contents.BUTCHER))); Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.BUTCHER_SETTINGS.withParent(Contents.BUTCHER)));
})); }));
container.add(slaughter = new GuiButtonBase(x + 116 / 2, y + 60, 232 / 2, 20, new TranslationTextComponent("gui.worldhandler.butcher.slaughter"), () -> boolean enabled = this.radius != null && !this.radius.isEmpty();
container.add(slaughter = new GuiButtonBase(x + 58, y + 48, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.slaughter"), () ->
{ {
AxisAlignedBB aabb = new AxisAlignedBB(Minecraft.getInstance().player.func_233580_cy_()).grow(Double.valueOf(this.radius)); ContentButcher.slaughter(Config.getButcher().getEntities().stream().map(ForgeRegistries.ENTITIES::getValue).filter(Predicates.notNull()).collect(Collectors.toList()), Integer.parseInt(this.radius));
for(ResourceLocation entry : Config.getButcher().getEntities())
{
EntityType<?> entity = ForgeRegistries.ENTITIES.getValue(entry);
if(entity != null)
{
List<?> entities = Minecraft.getInstance().world.getEntitiesWithinAABB(entity, aabb, Predicates.alwaysTrue());
if(!entities.isEmpty())
{
CommandHelper.sendCommand(new BuilderButcher(entry, Integer.valueOf(this.radius)));
}
}
}
})); }));
slaughter.field_230693_o_ = enabled && !Config.getButcher().getEntities().isEmpty();
slaughter.field_230693_o_ = this.radius != null && !this.radius.isEmpty() && !Config.CLIENT.getButcher().getEntities().isEmpty(); container.add(slaughter = new GuiButtonBase(x + 58, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.presets"), () ->
{
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.BUTCHER_PRESETS.withBuilder(this.builderButcher).withRadius(Integer.parseInt(this.radius)).withParent(Contents.BUTCHER)));
}));
slaughter.field_230693_o_ = enabled;
}
public static void slaughter(Collection<EntityType<?>> entities, int radius)
{
AxisAlignedBB aabb = new AxisAlignedBB(Minecraft.getInstance().player.func_233580_cy_()).grow(radius);
for(EntityType<?> entity : entities)
{
List<? extends Entity> targets = Minecraft.getInstance().world.getEntitiesWithinAABB(entity, aabb, Predicates.alwaysTrue());
targets.removeIf(target -> Minecraft.getInstance().player.equals(target));
if(!targets.isEmpty())
{
CommandHelper.sendCommand(new BuilderButcher(entity.getRegistryName(), radius));
}
}
} }
@Override @Override

View File

@@ -0,0 +1,72 @@
package exopandora.worldhandler.gui.content.impl;
import java.util.stream.Collectors;
import com.google.common.base.Predicates;
import exopandora.worldhandler.builder.ICommandBuilder;
import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
import exopandora.worldhandler.util.ActionHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.registries.ForgeRegistries;
@OnlyIn(Dist.CLIENT)
public class ContentButcherPresets extends ContentChild
{
private ICommandBuilder builder;
private int radius;
public ContentButcherPresets withBuilder(ICommandBuilder builder)
{
this.builder = builder;
return this;
}
public ContentButcherPresets withRadius(int radius)
{
this.radius = radius;
return this;
}
@Override
public ICommandBuilder getCommandBuilder()
{
return this.builder;
}
@Override
public void initButtons(Container container, int x, int y)
{
container.add(new GuiButtonBase(x, y + 96, 114, 20, new TranslationTextComponent("gui.worldhandler.generic.back"), () -> ActionHelper.back(this)));
container.add(new GuiButtonBase(x + 118, y + 96, 114, 20, new TranslationTextComponent("gui.worldhandler.generic.backToGame"), ActionHelper::backToGame));
container.add(new GuiButtonBase(x + 58, y, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.presets.passive_mobs"), () ->
{
ContentButcher.slaughter(Config.getButcher().getEntities().stream().map(ForgeRegistries.ENTITIES::getValue).filter(Predicates.notNull()).collect(Collectors.toList()), this.radius);
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(this.getParentContent()));
}));
container.add(new GuiButtonBase(x + 58, y + 24, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.presets.hostile_mobs"), () ->
{
ContentButcher.slaughter(ForgeRegistries.ENTITIES.getValues().stream().filter(entity -> !EntityClassification.MISC.equals(entity.getClassification()) && !EntityType.PLAYER.equals(entity)).collect(Collectors.toList()), this.radius);
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(this.getParentContent()));
}));
container.add(new GuiButtonBase(x + 58, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.presets.entities"), () ->
{
ContentButcher.slaughter(ForgeRegistries.ENTITIES.getValues().stream().filter(entity -> EntityClassification.MISC.equals(entity.getClassification()) && !EntityType.PLAYER.equals(entity)).collect(Collectors.toList()), this.radius);
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(this.getParentContent()));
}));
container.add(new GuiButtonBase(x + 58, y + 48, 114, 20, new TranslationTextComponent("gui.worldhandler.butcher.presets.players"), () ->
{
ContentButcher.slaughter(ForgeRegistries.ENTITIES.getValues().stream().filter(entity -> EntityType.PLAYER.equals(entity)).collect(Collectors.toList()), this.radius);
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(this.getParentContent()));
}));
}
}

View File

@@ -92,10 +92,4 @@ public class ContentButcherSettings extends ContentChild
button1.field_230693_o_ = !contains; button1.field_230693_o_ = !contains;
button2.field_230693_o_ = contains; button2.field_230693_o_ = contains;
} }
@Override
public IFormattableTextComponent getTitle()
{
return this.getParentContent().getTitle();
}
} }

View File

@@ -29,6 +29,17 @@ public abstract class ContentChild extends Content
return Contents.MAIN.getCategory(); return Contents.MAIN.getCategory();
} }
@Override
public IFormattableTextComponent getTitle()
{
if(this.parent != null)
{
return this.parent.getTitle();
}
return null;
}
@Override @Override
public IFormattableTextComponent getTabTitle() public IFormattableTextComponent getTabTitle()
{ {

View File

@@ -11,7 +11,6 @@ import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.ActionHelper;
import exopandora.worldhandler.util.CommandHelper; import exopandora.worldhandler.util.CommandHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.util.text.IFormattableTextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
@@ -81,10 +80,4 @@ public class ContentContinue extends ContentChild
{ {
this.commandField.func_230431_b_(matrix, mouseX, mouseY, partialTicks); //renderButton this.commandField.func_230431_b_(matrix, mouseX, mouseY, partialTicks); //renderButton
} }
@Override
public IFormattableTextComponent getTitle()
{
return this.getParentContent().getTitle();
}
} }

View File

@@ -124,6 +124,12 @@
"gui.worldhandler.butcher.radius": "Radius", "gui.worldhandler.butcher.radius": "Radius",
"gui.worldhandler.butcher.configure": "Konfigurieren", "gui.worldhandler.butcher.configure": "Konfigurieren",
"gui.worldhandler.butcher.slaughter": "Metzeln", "gui.worldhandler.butcher.slaughter": "Metzeln",
"gui.worldhandler.butcher.presets": "Vorlagen",
"gui.worldhandler.butcher.presets.passive_mobs": "Passive Mobs",
"gui.worldhandler.butcher.presets.hostile_mobs": "Feindliche Mobs",
"gui.worldhandler.butcher.presets.entities": "Objekte",
"gui.worldhandler.butcher.presets.players": "Spieler",
"gui.worldhandler.multiplayer.kick": "Kicken", "gui.worldhandler.multiplayer.kick": "Kicken",
"gui.worldhandler.multiplayer.ban": "Bannen", "gui.worldhandler.multiplayer.ban": "Bannen",

View File

@@ -124,6 +124,12 @@
"gui.worldhandler.butcher.radius": "Radius", "gui.worldhandler.butcher.radius": "Radius",
"gui.worldhandler.butcher.configure": "Configure", "gui.worldhandler.butcher.configure": "Configure",
"gui.worldhandler.butcher.slaughter": "Slaughter", "gui.worldhandler.butcher.slaughter": "Slaughter",
"gui.worldhandler.butcher.presets": "Presets",
"gui.worldhandler.butcher.presets.passive_mobs": "Passive Mobs",
"gui.worldhandler.butcher.presets.hostile_mobs": "Hostile Mobs",
"gui.worldhandler.butcher.presets.entities": "Entities",
"gui.worldhandler.butcher.presets.players": "Players",
"gui.worldhandler.multiplayer.kick": "Kick", "gui.worldhandler.multiplayer.kick": "Kick",
"gui.worldhandler.multiplayer.ban": "Ban", "gui.worldhandler.multiplayer.ban": "Ban",

View File

@@ -124,6 +124,12 @@
"gui.worldhandler.butcher.radius": "Rayon", "gui.worldhandler.butcher.radius": "Rayon",
"gui.worldhandler.butcher.configure": "Configurer", "gui.worldhandler.butcher.configure": "Configurer",
"gui.worldhandler.butcher.slaughter": "Massacrer", "gui.worldhandler.butcher.slaughter": "Massacrer",
"gui.worldhandler.butcher.presets": "Presets",
"gui.worldhandler.butcher.presets.passive_mobs": "Passive Mobs",
"gui.worldhandler.butcher.presets.hostile_mobs": "Hostile Mobs",
"gui.worldhandler.butcher.presets.entities": "Entities",
"gui.worldhandler.butcher.presets.players": "Players",
"gui.worldhandler.multiplayer.kick": "Expulser", "gui.worldhandler.multiplayer.kick": "Expulser",
"gui.worldhandler.multiplayer.ban": "Bannir", "gui.worldhandler.multiplayer.ban": "Bannir",

View File

@@ -124,6 +124,12 @@
"gui.worldhandler.butcher.radius": "Радиус", "gui.worldhandler.butcher.radius": "Радиус",
"gui.worldhandler.butcher.configure": "Настроить", "gui.worldhandler.butcher.configure": "Настроить",
"gui.worldhandler.butcher.slaughter": "Резать", "gui.worldhandler.butcher.slaughter": "Резать",
"gui.worldhandler.butcher.presets": "Presets",
"gui.worldhandler.butcher.presets.passive_mobs": "Passive Mobs",
"gui.worldhandler.butcher.presets.hostile_mobs": "Hostile Mobs",
"gui.worldhandler.butcher.presets.entities": "Entities",
"gui.worldhandler.butcher.presets.players": "Players",
"gui.worldhandler.multiplayer.kick": "Выгнать", "gui.worldhandler.multiplayer.kick": "Выгнать",
"gui.worldhandler.multiplayer.ban": "Забанить", "gui.worldhandler.multiplayer.ban": "Забанить",

View File

@@ -125,6 +125,12 @@
"gui.worldhandler.butcher.radius": "范围", "gui.worldhandler.butcher.radius": "范围",
"gui.worldhandler.butcher.configure": "配置", "gui.worldhandler.butcher.configure": "配置",
"gui.worldhandler.butcher.slaughter": "屠杀", "gui.worldhandler.butcher.slaughter": "屠杀",
"gui.worldhandler.butcher.presets": "Presets",
"gui.worldhandler.butcher.presets.passive_mobs": "Passive Mobs",
"gui.worldhandler.butcher.presets.hostile_mobs": "Hostile Mobs",
"gui.worldhandler.butcher.presets.entities": "Entities",
"gui.worldhandler.butcher.presets.players": "Players",
"gui.worldhandler.multiplayer.kick": "踢出", "gui.worldhandler.multiplayer.kick": "踢出",
"gui.worldhandler.multiplayer.ban": "封禁", "gui.worldhandler.multiplayer.ban": "封禁",