Skip to content

Commit

Permalink
Rework Voiding Covers (#1414)
Browse files Browse the repository at this point in the history
* add toggle button to all voiding covers
added lang

* remove TODOs
remove soft mallet function from voiding covers

* re-implement soft hammer functionality

* Fixed Soft Hammer not working with Voiding Covers on pipes
Fixed/Added swinging when using a Wrench on pipes

* Fix failing tests

* add lang

* remove override for onSoftMalletClick()

* notify player via message

* small oopsie

* get cover on actual side instead of using the grid
not sure how to do the same for pipes

* fix NPE

* remove logic for getting cover on actual side hit instead of GT grid

* improved lang

* remove commented out code

* use `determineGridSideHit()` instead of `traceCoverSide()`

* added soft mallet to `isCoverBehaviorItem()` in GTUtility
removed check for soft mallet in BlockPipe `hasPipeCollisionChangingItem()`

* re-organize `createUI()`
adjust widget positioning for Manual IO Button

* re-organize `createUI()` for advanced voiding covers
adjust widget positioning for Manual IO Button
move some logic in `createUI()` in CoverFluidVoidingAdvanced to it's own method, to match CoverItemVoidingAdvanced
also fixed the fluid filter's stupid positioning in CoverFluidVoidingAdvanced

* change funny magic number

* improve lang

* improve lang (forgor the lang file)

* fix GUI issue in `CoverFluidVoidingAdvanced`

* Revert "use `determineGridSideHit()` instead of `traceCoverSide()`"

This reverts commit 168a8f3aef7f97a625735c18500ba60c3f24ac26.

* change null check to `coverSide` instead of `coverBehavior`
move `coverBehavior` field initialization

* small adjustments
match #1464

* make warning hover tooltip stand out
  • Loading branch information
ghzdude authored Feb 9, 2023
1 parent 5be1672 commit 94d1d5c
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 35 deletions.
22 changes: 16 additions & 6 deletions src/main/java/gregtech/api/pipenet/block/BlockPipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import codechicken.lib.vec.Cuboid6;
import gregtech.api.GregTechAPI;
import gregtech.api.block.BuiltInRenderBlock;
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.capability.IControllable;
import gregtech.api.cover.CoverBehavior;
import gregtech.api.cover.ICoverable;
import gregtech.api.cover.ICoverable.CoverSideData;
Expand Down Expand Up @@ -45,17 +47,16 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import javax.tools.Tool;
import java.util.*;

import static gregtech.api.metatileentity.MetaTileEntity.FULL_CUBE_COLLISION;

Expand Down Expand Up @@ -331,7 +332,7 @@ public boolean onPipeActivated(World world, IBlockState state, BlockPos pos, Ent
}

if (!(hit.cuboid6.data instanceof CoverSideData)) {
switch (onPipeToolUsed(world, pos, itemStack, coverSide, pipeTile, entityPlayer)) {
switch (onPipeToolUsed(world, pos, itemStack, coverSide, pipeTile, entityPlayer, hand)) {
case SUCCESS:
return true;
case FAIL:
Expand All @@ -344,6 +345,14 @@ public boolean onPipeActivated(World world, IBlockState state, BlockPos pos, Ent
return activateFrame(world, state, pos, entityPlayer, hand, hit, pipeTile);
}

if (itemStack.getItem().getToolClasses(itemStack).contains(ToolClasses.SOFT_MALLET)) {
if (coverBehavior.onSoftMalletClick(entityPlayer, hand, hit) == EnumActionResult.SUCCESS) {
ToolHelper.damageItem(itemStack, entityPlayer);
ToolHelper.playToolSound(itemStack, entityPlayer);
return true;
}
}

if (itemStack.getItem().getToolClasses(itemStack).contains(ToolClasses.SCREWDRIVER)) {
if (coverBehavior.onScrewdriverClick(entityPlayer, hand, hit) == EnumActionResult.SUCCESS) {
ToolHelper.damageItem(itemStack, entityPlayer);
Expand Down Expand Up @@ -384,7 +393,7 @@ private boolean activateFrame(World world, IBlockState state, BlockPos pos, Enti
* @return 1 if successfully used tool, 0 if failed to use tool,
* -1 if ItemStack failed the capability check (no action done, continue checks).
*/
public EnumActionResult onPipeToolUsed(World world, BlockPos pos, ItemStack stack, EnumFacing coverSide, IPipeTile<PipeType, NodeDataType> pipeTile, EntityPlayer entityPlayer) {
public EnumActionResult onPipeToolUsed(World world, BlockPos pos, ItemStack stack, EnumFacing coverSide, IPipeTile<PipeType, NodeDataType> pipeTile, EntityPlayer entityPlayer, EnumHand hand) {
if (isPipeTool(stack)) {
if (!entityPlayer.world.isRemote) {
if (entityPlayer.isSneaking() && pipeTile.canHaveBlockedFaces()) {
Expand All @@ -401,6 +410,7 @@ public EnumActionResult onPipeToolUsed(World world, BlockPos pos, ItemStack stac
ToolHelper.damageItem(stack, entityPlayer);
return EnumActionResult.SUCCESS;
}
entityPlayer.swingArm(hand);
}
return EnumActionResult.PASS;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ public static boolean isCoverBehaviorItem(ItemStack itemStack, @Nullable Boolean
}
} else if (item.getToolClasses(itemStack).contains(ToolClasses.CROWBAR)) {
return hasCoverSupplier == null || hasCoverSupplier.getAsBoolean();
} else if (item.getToolClasses(itemStack).contains(ToolClasses.SOFT_MALLET)) {
return hasCoverSupplier == null || hasCoverSupplier.getAsBoolean();
}
return false;
}
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/gregtech/common/covers/CoverFluidVoiding.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import gregtech.api.cover.ICoverable;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.widgets.CycleButtonWidget;
import gregtech.api.gui.widgets.LabelWidget;
import gregtech.api.gui.widgets.ToggleButtonWidget;
import gregtech.api.gui.widgets.WidgetGroup;
import gregtech.api.util.GTTransferUtils;
import gregtech.client.renderer.texture.Textures;
Expand All @@ -19,6 +21,7 @@
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
Expand Down Expand Up @@ -63,9 +66,17 @@ public ModularUI createUI(EntityPlayer player) {

this.fluidFilter.initUI(20, primaryGroup::addWidget);

ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 100 + 82)
primaryGroup.addWidget(new CycleButtonWidget(10, 92, 80, 18, this::isWorkingEnabled, this::setWorkingEnabled,
"cover.voiding.label.disabled", "cover.voiding.label.enabled")
.setTooltipHoverString("cover.voiding.tooltip"));

primaryGroup.addWidget(new CycleButtonWidget(10, 112, 116, 18,
ManualImportExportMode.class, this::getManualImportExportMode, this::setManualImportExportMode)
.setTooltipHoverString("cover.universal.manual_import_export.mode.description"));

ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 100 + 82 + 16 + 24)
.widget(primaryGroup)
.bindPlayerInventory(player.inventory, GuiTextures.SLOT, 7, 100);
.bindPlayerInventory(player.inventory, GuiTextures.SLOT, 7, 100 + 16 + 24);
return builder.build(this, player);
}

Expand All @@ -77,6 +88,10 @@ public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexO
@Override
public EnumActionResult onSoftMalletClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) {
this.isWorkingAllowed = !this.isWorkingAllowed;
if (!playerIn.world.isRemote) {
playerIn.sendMessage(new TextComponentTranslation(isWorkingEnabled() ?
"cover.voiding.message.enabled" : "cover.voiding.message.disabled"));
}
return EnumActionResult.SUCCESS;
}

Expand Down
54 changes: 37 additions & 17 deletions src/main/java/gregtech/common/covers/CoverFluidVoidingAdvanced.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
package gregtech.common.covers;

import codechicken.lib.raytracer.CuboidRayTraceResult;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import gregtech.api.cover.ICoverable;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.Widget;
import gregtech.api.gui.widgets.*;
import gregtech.api.util.GTTransferUtils;
import gregtech.client.renderer.texture.Textures;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;

import java.util.function.Consumer;
import java.util.function.Predicate;

public class CoverFluidVoidingAdvanced extends CoverFluidVoiding {
Expand Down Expand Up @@ -132,28 +137,44 @@ public ModularUI createUI(EntityPlayer player) {
WidgetGroup primaryGroup = new WidgetGroup();
primaryGroup.addWidget(new LabelWidget(10, 5, getUITitle()));

primaryGroup.addWidget(new SlotWidget(fluidFilter.getFilterInventory(), 0, 10, 15)
.setBackgroundTexture(GuiTextures.SLOT, GuiTextures.FILTER_SLOT_OVERLAY));
this.fluidFilter.getFilterWrapper().initUI(20, primaryGroup::addWidget);
this.fluidFilter.getFilterWrapper().blacklistUI(32, primaryGroup::addWidget, () -> voidingMode != VoidingMode.VOID_OVERFLOW);

primaryGroup.addWidget(new CycleButtonWidget(92, 14, 75, 18,
primaryGroup.addWidget(new CycleButtonWidget(92, 15, 75, 18,
VoidingMode.class, this::getVoidingMode, this::setVoidingMode)
.setTooltipHoverString("cover.voiding.voiding_mode.description"));

this.initFilterUI(20, primaryGroup::addWidget);

primaryGroup.addWidget(new CycleButtonWidget(10, 92, 80, 18, this::isWorkingEnabled, this::setWorkingEnabled,
"cover.voiding.label.disabled", "cover.voiding.label.enabled")
.setTooltipHoverString("cover.voiding.tooltip"));

primaryGroup.addWidget(new CycleButtonWidget(10, 112, 116, 18,
ManualImportExportMode.class, this::getManualImportExportMode, this::setManualImportExportMode)
.setTooltipHoverString("cover.universal.manual_import_export.mode.description"));

ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 100 + 82 + 16 + 24)
.widget(primaryGroup)
.bindPlayerInventory(player.inventory, GuiTextures.SLOT, 7, 100 + 16 + 24);
return buildUI(builder, player);
}

public void initFilterUI(int y, Consumer<Widget> widgetGroup){
widgetGroup.accept(new LabelWidget(10, y, "cover.pump.fluid_filter.title"));
widgetGroup.accept(new SlotWidget(fluidFilter.getFilterInventory(), 0, 10, y + 15)
.setBackgroundTexture(GuiTextures.SLOT, GuiTextures.FILTER_SLOT_OVERLAY));

ServerWidgetGroup stackSizeGroup = new ServerWidgetGroup(this::shouldDisplayAmountSlider);
stackSizeGroup.addWidget(new ImageWidget(110, 72, 38, 18, GuiTextures.DISPLAY));
stackSizeGroup.addWidget(new ImageWidget(110, 34, 38, 18, GuiTextures.DISPLAY));

stackSizeGroup.addWidget(new IncrementButtonWidget(148, 72, 18, 18, 1, 10, 100, 1000, this::adjustTransferSize)
stackSizeGroup.addWidget(new IncrementButtonWidget(148, 34, 18, 18, 1, 10, 100, 1000, this::adjustTransferSize)
.setDefaultTooltip()
.setTextScale(0.7f)
.setShouldClientCallback(false));
stackSizeGroup.addWidget(new IncrementButtonWidget(92, 72, 18, 18, -1, -10, -100, -1000, this::adjustTransferSize)
stackSizeGroup.addWidget(new IncrementButtonWidget(92, 34, 18, 18, -1, -10, -100, -1000, this::adjustTransferSize)
.setDefaultTooltip()
.setTextScale(0.7f)
.setShouldClientCallback(false));

stackSizeGroup.addWidget(new TextFieldWidget2(111, 78, 36, 11, this::getTransferAmountString, val -> {
stackSizeGroup.addWidget(new TextFieldWidget2(111, 39, 37, 11, this::getTransferAmountString, val -> {
if (val != null && !val.isEmpty()) {
int amount = Integer.parseInt(val);
if (this.bucketMode == BucketMode.BUCKET) {
Expand All @@ -167,20 +188,19 @@ public ModularUI createUI(EntityPlayer player) {
.setMaxLength(10)
.setScale(0.6f));

stackSizeGroup.addWidget(new CycleButtonWidget(115, 35, 30, 20,
stackSizeGroup.addWidget(new SimpleTextWidget(129, 47, "", 0xFFFFFF, () -> bucketMode.localeName).setScale(0.6f));

stackSizeGroup.addWidget(new CycleButtonWidget(114, 53, 30, 20,
BucketMode.class, this::getBucketMode, mode -> {
if (mode != bucketMode) {
setBucketMode(mode);
}
}));

stackSizeGroup.addWidget(new SimpleTextWidget(129, 86, "", 0xFFFFFF, () -> bucketMode.localeName).setScale(0.6f));
widgetGroup.accept(stackSizeGroup);

ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 100 + 82)
.widget(primaryGroup)
.widget(stackSizeGroup)
.bindPlayerInventory(player.inventory, GuiTextures.SLOT, 7, 100);
return buildUI(builder, player);
this.fluidFilter.getFilterWrapper().initUI(y + 15, widgetGroup);
this.fluidFilter.getFilterWrapper().blacklistUI(y + 15, widgetGroup, () -> voidingMode != VoidingMode.VOID_OVERFLOW);
}

@Override
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/gregtech/common/covers/CoverItemVoiding.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import gregtech.api.cover.ICoverable;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.widgets.CycleButtonWidget;
import gregtech.api.gui.widgets.LabelWidget;
import gregtech.api.gui.widgets.WidgetGroup;
import gregtech.client.renderer.texture.Textures;
Expand All @@ -18,6 +19,7 @@
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
Expand Down Expand Up @@ -71,12 +73,19 @@ protected String getUITitle() {
public ModularUI createUI(EntityPlayer player) {
WidgetGroup primaryGroup = new WidgetGroup();
primaryGroup.addWidget(new LabelWidget(10, 5, getUITitle()));

this.itemFilterContainer.initUI(20, primaryGroup::addWidget);

ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 123 + 82)
primaryGroup.addWidget(new CycleButtonWidget(10, 92 + 23, 80, 18, this::isWorkingEnabled, this::setWorkingEnabled,
"cover.voiding.label.disabled", "cover.voiding.label.enabled")
.setTooltipHoverString("cover.voiding.tooltip"));

primaryGroup.addWidget(new CycleButtonWidget(10, 112 + 23, 116, 18,
ManualImportExportMode.class, this::getManualImportExportMode, this::setManualImportExportMode)
.setTooltipHoverString("cover.universal.manual_import_export.mode.description"));

ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 125 + 82 + 16 + 24)
.widget(primaryGroup)
.bindPlayerInventory(player.inventory, GuiTextures.SLOT, 7, 123);
.bindPlayerInventory(player.inventory, GuiTextures.SLOT, 7, 125 + 16 + 24);
return builder.build(this, player);
}

Expand All @@ -88,6 +97,10 @@ public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexO
@Override
public EnumActionResult onSoftMalletClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) {
this.isWorkingAllowed = !this.isWorkingAllowed;
if (!playerIn.world.isRemote) {
playerIn.sendMessage(new TextComponentTranslation(isWorkingEnabled() ?
"cover.voiding.message.enabled" : "cover.voiding.message.disabled"));
}
return EnumActionResult.SUCCESS;
}

Expand Down
23 changes: 16 additions & 7 deletions src/main/java/gregtech/common/covers/CoverItemVoidingAdvanced.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gregtech.common.covers;

import codechicken.lib.raytracer.CuboidRayTraceResult;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Cuboid6;
Expand All @@ -15,7 +16,9 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
Expand Down Expand Up @@ -92,17 +95,23 @@ public ModularUI createUI(EntityPlayer player) {
WidgetGroup primaryGroup = new WidgetGroup();
primaryGroup.addWidget(new LabelWidget(10, 5, getUITitle()));

this.initFilterUI(20, primaryGroup::addWidget);

WidgetGroup filterGroup = new WidgetGroup();
filterGroup.addWidget(new CycleButtonWidget(91, 14, 75, 20,
primaryGroup.addWidget(new CycleButtonWidget(91, 14, 75, 20,
VoidingMode.class, this::getVoidingMode, this::setVoidingMode)
.setTooltipHoverString("cover.voiding.voiding_mode.description"));

ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 125 + 82)
this.initFilterUI(20, primaryGroup::addWidget);

primaryGroup.addWidget(new CycleButtonWidget(10, 92 + 23, 80, 18, this::isWorkingEnabled, this::setWorkingEnabled,
"cover.voiding.label.disabled", "cover.voiding.label.enabled")
.setTooltipHoverString("cover.voiding.tooltip"));

primaryGroup.addWidget(new CycleButtonWidget(10, 112 + 23, 116, 18,
ManualImportExportMode.class, this::getManualImportExportMode, this::setManualImportExportMode)
.setTooltipHoverString("cover.universal.manual_import_export.mode.description"));

ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 125 + 82 + 16 + 24)
.widget(primaryGroup)
.widget(filterGroup)
.bindPlayerInventory(player.inventory, GuiTextures.SLOT, 7, 125);
.bindPlayerInventory(player.inventory, GuiTextures.SLOT, 7, 125 + 16 + 24);
return buildUI(builder, player);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,11 @@ cover.fluid.voiding.title=Fluid Voiding Settings
cover.fluid.voiding.advanced.title=Advanced Fluid Voiding Settings
cover.item.voiding.title=Item Voiding Settings
cover.item.voiding.advanced.title=Advanced Item Voiding Settings
cover.voiding.label.disabled=Disabled
cover.voiding.label.enabled=Enabled
cover.voiding.tooltip=§cWARNING!§7 Setting this to "Enabled" means that fluids or items WILL be voided.
cover.voiding.message.disabled=Voiding Cover Disabled
cover.voiding.message.enabled=Voiding Cover Enabled

cover.smart_item_filter.title=Smart Item Filter
cover.smart_item_filter.filtering_mode.electrolyzer=Electrolyzer
Expand Down

0 comments on commit 94d1d5c

Please sign in to comment.