Skip to content

Commit

Permalink
Fix Voiding Cover + Soft Mallet interaction (#2721)
Browse files Browse the repository at this point in the history
  • Loading branch information
krossgg authored Jan 12, 2025
1 parent ad7b8e0 commit ca36d7f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 50 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ public void clearInventory(IItemHandlerModifiable inventory) {
public boolean shouldRenderGrid(Player player, BlockPos pos, BlockState state, ItemStack held,
Set<GTToolType> toolTypes) {
if (toolTypes.contains(GTToolType.WRENCH)) return true;
if (toolTypes.contains(GTToolType.HARD_HAMMER) && this instanceof IMufflableMachine) return true;
if (toolTypes.contains(GTToolType.SCREWDRIVER) &&
(this instanceof IAutoOutputItem || this instanceof IAutoOutputFluid))
return true;
Expand All @@ -531,6 +530,12 @@ public boolean shouldRenderGrid(Player player, BlockPos pos, BlockState state, I
@Override
public ResourceTexture sideTips(Player player, BlockPos pos, BlockState state, Set<GTToolType> toolTypes,
Direction side) {
var cover = coverContainer.getCoverAtSide(side);
if (cover != null) {
var tips = cover.sideTips(player, pos, state, toolTypes, side);
if (tips != null) return tips;
}

if (toolTypes.contains(GTToolType.WRENCH)) {
if (player.isShiftKeyDown()) {
if (isFacingValid(side)) {
Expand All @@ -539,17 +544,13 @@ public ResourceTexture sideTips(Player player, BlockPos pos, BlockState state, S
}
} else if (toolTypes.contains(GTToolType.SOFT_MALLET)) {
if (this instanceof IControllable controllable) {
return controllable.isWorkingEnabled() ? GuiTextures.TOOL_PAUSE : GuiTextures.TOOL_START;
return controllable.isWorkingEnabled() ? GuiTextures.TOOL_START : GuiTextures.TOOL_PAUSE;
}
} else if (toolTypes.contains(GTToolType.HARD_HAMMER)) {
if (this instanceof IMufflableMachine mufflableMachine) {
return mufflableMachine.isMuffled() ? GuiTextures.TOOL_SOUND : GuiTextures.TOOL_MUTE;
}
}
var cover = coverContainer.getCoverAtSide(side);
if (cover != null) {
return cover.sideTips(player, pos, state, toolTypes, side);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class ConveyorCover extends CoverBehavior implements IUICover, IControlla
@Getter
protected ManualIOMode manualIOMode = ManualIOMode.DISABLED;
@Persisted
@DescSynced
@Getter
protected boolean isWorkingEnabled = true;
protected int itemsLeftToTransferLastSecond;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class PumpCover extends CoverBehavior implements IUICover, IControllable
protected ManualIOMode manualIOMode = ManualIOMode.DISABLED;

@Persisted
@DescSynced
@Getter
protected boolean isWorkingEnabled = true;
protected int mBLeftToTransferLastSecond;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,48 @@
import com.gregtechceu.gtceu.api.cover.CoverDefinition;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget;
import com.gregtechceu.gtceu.api.item.tool.GTToolType;
import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable;
import com.gregtechceu.gtceu.common.cover.PumpCover;

import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture;
import com.lowdragmc.lowdraglib.gui.widget.LabelWidget;
import com.lowdragmc.lowdraglib.gui.widget.Widget;
import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted;
import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.Set;

import javax.annotation.ParametersAreNonnullByDefault;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class FluidVoidingCover extends PumpCover {

@Persisted
@Getter
protected boolean isEnabled = false;

public FluidVoidingCover(CoverDefinition definition, ICoverable coverHolder, Direction attachedSide) {
super(definition, coverHolder, attachedSide, 0);
setWorkingEnabled(false);
}

@Override
protected boolean isSubscriptionActive() {
return isWorkingEnabled() && isEnabled();
return isWorkingEnabled();
}

//////////////////////////////////////////////
Expand Down Expand Up @@ -77,16 +83,6 @@ void voidAny(IFluidHandlerModifiable fluidHandler) {
}
}

public void setWorkingEnabled(boolean workingEnabled) {
isWorkingEnabled = workingEnabled;
subscriptionHandler.updateSubscription();
}

public void setEnabled(boolean enabled) {
isEnabled = enabled;
subscriptionHandler.updateSubscription();
}

//////////////////////////////////////
// *********** GUI ***********//
//////////////////////////////////////
Expand All @@ -97,7 +93,7 @@ public Widget createUIWidget() {
group.addWidget(new LabelWidget(10, 5, getUITitle()));

group.addWidget(new ToggleButtonWidget(10, 20, 20, 20,
GuiTextures.BUTTON_POWER, this::isEnabled, this::setEnabled));
GuiTextures.BUTTON_POWER, this::isWorkingEnabled, this::setWorkingEnabled));

// group.addWidget(filterHandler.createFilterSlotUI(36, 21));
group.addWidget(filterHandler.createFilterSlotUI(148, 91));
Expand All @@ -113,12 +109,31 @@ protected String getUITitle() {
return "cover.fluid.voiding.title";
}

protected void buildAdditionalUI(WidgetGroup group) {
// Do nothing in the base implementation. This is intended to be overridden by subclasses.
@Override
public InteractionResult onSoftMalletClick(Player playerIn, InteractionHand hand, BlockHitResult hitResult) {
if (!isRemote()) {
setWorkingEnabled(!isWorkingEnabled);
playerIn.sendSystemMessage(Component.translatable(isWorkingEnabled() ?
"cover.voiding.message.enabled" : "cover.voiding.message.disabled"));
}
playerIn.swing(hand);
return InteractionResult.CONSUME;
}

protected void configureFilter() {
// Do nothing in the base implementation. This is intended to be overridden by subclasses.
// TODO: Decide grid behavior
@Override
public boolean shouldRenderGrid(Player player, BlockPos pos, BlockState state, ItemStack held,
Set<GTToolType> toolTypes) {
return super.shouldRenderGrid(player, pos, state, held, toolTypes);
}

@Override
public ResourceTexture sideTips(Player player, BlockPos pos, BlockState state, Set<GTToolType> toolTypes,
Direction side) {
if (toolTypes.contains(GTToolType.SOFT_MALLET)) {
return isWorkingEnabled() ? GuiTextures.TOOL_START : GuiTextures.TOOL_PAUSE;
}
return super.sideTips(player, pos, state, toolTypes, side);
}

//////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,45 @@
import com.gregtechceu.gtceu.api.cover.filter.ItemFilter;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget;
import com.gregtechceu.gtceu.api.item.tool.GTToolType;
import com.gregtechceu.gtceu.common.cover.ConveyorCover;

import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture;
import com.lowdragmc.lowdraglib.gui.widget.LabelWidget;
import com.lowdragmc.lowdraglib.gui.widget.Widget;
import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted;
import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.items.IItemHandler;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.Set;

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ItemVoidingCover extends ConveyorCover implements IUICover, IControllable {

@Persisted
@Getter
protected boolean isEnabled = false;

public ItemVoidingCover(CoverDefinition definition, ICoverable coverHolder, Direction attachedSide) {
super(definition, coverHolder, attachedSide, 0);
setWorkingEnabled(false);
}

@Override
protected boolean isSubscriptionActive() {
return isWorkingEnabled() && isEnabled();
return isWorkingEnabled();
}

//////////////////////////////////////////////
Expand Down Expand Up @@ -75,16 +81,6 @@ void voidAny(IItemHandler handler) {
}
}

public void setWorkingEnabled(boolean workingEnabled) {
isWorkingEnabled = workingEnabled;
subscriptionHandler.updateSubscription();
}

public void setEnabled(boolean enabled) {
isEnabled = enabled;
subscriptionHandler.updateSubscription();
}

//////////////////////////////////////
// *********** GUI ***********//
//////////////////////////////////////
Expand All @@ -95,7 +91,7 @@ public Widget createUIWidget() {
group.addWidget(new LabelWidget(10, 5, getUITitle()));

group.addWidget(new ToggleButtonWidget(10, 20, 20, 20,
GuiTextures.BUTTON_POWER, this::isEnabled, this::setEnabled));
GuiTextures.BUTTON_POWER, this::isWorkingEnabled, this::setWorkingEnabled));

// group.addWidget(filterHandler.createFilterSlotUI(36, 21));
group.addWidget(filterHandler.createFilterSlotUI(148, 91));
Expand All @@ -111,12 +107,33 @@ protected String getUITitle() {
return "cover.item.voiding.title";
}

protected void buildAdditionalUI(WidgetGroup group) {
// Do nothing in the base implementation. This is intended to be overridden by subclasses.
@Override
public InteractionResult onSoftMalletClick(Player playerIn, InteractionHand hand, BlockHitResult hitResult) {
if (!isRemote()) {
setWorkingEnabled(!isWorkingEnabled);
playerIn.sendSystemMessage(Component.translatable(isWorkingEnabled() ?
"cover.voiding.message.enabled" : "cover.voiding.message.disabled"));
}
playerIn.swing(hand);
return InteractionResult.CONSUME;
}

protected void configureFilter() {
// Do nothing in the base implementation. This is intended to be overridden by subclasses.
// TODO: Decide grid behavior
@Override
public boolean shouldRenderGrid(Player player, BlockPos pos, BlockState state, ItemStack held,
Set<GTToolType> toolTypes) {
return super.shouldRenderGrid(player, pos, state, held, toolTypes);
}

@Override
public ResourceTexture sideTips(Player player, BlockPos pos, BlockState state, Set<GTToolType> toolTypes,
Direction side) {
var superTips = super.sideTips(player, pos, state, toolTypes, side);
if (superTips != null) return superTips;
if (toolTypes.contains(GTToolType.SOFT_MALLET)) {
return isWorkingEnabled() ? GuiTextures.TOOL_START : GuiTextures.TOOL_PAUSE;
}
return null;
}

//////////////////////////////////////
Expand Down

0 comments on commit ca36d7f

Please sign in to comment.