Skip to content

Commit

Permalink
Implement detector covers (#214)
Browse files Browse the repository at this point in the history
* feat: add redstone output to cover behavior

* style: Reformat cover & cover item definitions

* fix: covers now output redstone to the correct side

* feat: add activity detector covers

* refactor: move workable out of DetectorCover base class

* feat: add IMaintenanceMachine capability

* feat: maintenance detector cover

* fix: don't use circuit in maintenance detector cover recipe

* fix: correctly handle UI covers in DetectorCover base class

* feat: energy detector covers

* feat: item detector covers

* feat: generate lang files for item detector covers

* feat: fluid detector covers

* style: make method order more consistent in detector covers

* chore: regenerate language files to include latest changes

* fix: add slight shadows on energy detector cover for better visibility

* fix: advanced detector cover UIs now align properly

* fix: display correct status when inverting a simple detector cover

* refactor: removed unused field from DetectorCover

* Revert "refactor: removed unused field from DetectorCover"

This reverts commit 6650832.

* refactor: explicit getter/setter for DetectorCover.isWorkingEnabled

In order to not make the field appear unused, the getter and setter has
been explicitly implemented (instead of Lombok annotations).

* refactor: use LangHandler for getting localized multiline strings

* refactor: remove managed field holder from ActivityDetectorCover

* refactor: remove unnecessary @DescSynced annotations in detector covers

* refactor: extract int- and long input widget into common base class

* fix: wrong values for energy detector when opening UI in EU mode

* fix sync issues + fix drop inner filters

---------

Co-authored-by: KilaBash <[email protected]>
  • Loading branch information
mikerooni and Yefancy authored Jul 29, 2023
1 parent 16a359c commit f88ff16
Show file tree
Hide file tree
Showing 52 changed files with 1,786 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,26 +248,17 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player

@Override
public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
if (getMachine(level, pos) instanceof IRedstoneSignalMachine redstoneSignalMachine) {
return redstoneSignalMachine.getOutputSignal(direction);
}
return super.getSignal(state, level, pos, direction);
return getMachine(level, pos).getOutputSignal(direction);
}

@Override
public int getDirectSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
if (getMachine(level, pos) instanceof IRedstoneSignalMachine redstoneSignalMachine) {
return redstoneSignalMachine.getOutputDirectSignal(direction);
}
return super.getDirectSignal(state, level, pos, direction);
return getMachine(level, pos).getOutputDirectSignal(direction);
}

@Override
public int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos) {
if (getMachine(level, pos) instanceof IRedstoneSignalMachine redstoneSignalMachine) {
return redstoneSignalMachine.getAnalogOutputSignal();
}
return super.getAnalogOutputSignal(state, level, pos);
return getMachine(level, pos).getAnalogOutputSignal();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.api.capability;

import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMaintenanceMachine;
import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -74,4 +75,10 @@ public static IPlatformEnergyStorage getPlatformEnergy(Level level, BlockPos pos
public static ICleanroomReceiver getCleanroomReceiver(Level level, BlockPos pos, @Nullable Direction side) {
throw new AssertionError();
}

@ExpectPlatform
@Nullable
public static IMaintenanceMachine getMaintenanceMachine(Level level, BlockPos pos, @Nullable Direction side) {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.gregtechceu.gtceu.api.cover;

import com.gregtechceu.gtceu.api.gui.factory.CoverUIFactory;
import com.gregtechceu.gtceu.api.capability.ICoverable;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.factory.CoverUIFactory;
import com.gregtechceu.gtceu.api.item.tool.GTToolType;
import com.gregtechceu.gtceu.api.item.tool.IToolGridHighLight;
import com.gregtechceu.gtceu.api.syncdata.EnhancedFieldManagedStorage;
Expand All @@ -25,8 +25,8 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;

import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -47,6 +47,8 @@ public abstract class CoverBehavior implements IEnhancedManaged, IToolGridHighLi
public final Direction attachedSide;
@Getter @Persisted @DescSynced
protected ItemStack attachItem = ItemStack.EMPTY;
@Getter @Persisted
protected int redstoneSignalOutput = 0;

public CoverBehavior(CoverDefinition definition, ICoverable coverHolder, Direction attachedSide) {
this.coverDefinition = definition;
Expand Down Expand Up @@ -125,6 +127,12 @@ public void onRemoved() {
public void onNeighborChanged(Block block, BlockPos fromPos, boolean isMoving) {
}

public void setRedstoneSignalOutput(int redstoneSignalOutput) {
this.redstoneSignalOutput = redstoneSignalOutput;
coverHolder.notifyBlockUpdate();
coverHolder.markDirty();
}

//////////////////////////////////////
//******* Interaction *******//
//////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
import com.lowdragmc.lowdraglib.side.fluid.FluidStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang3.NotImplementedException;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;

/**
Expand All @@ -21,4 +25,29 @@ static FluidFilter loadFilter(ItemStack itemStack) {
return FILTERS.get(itemStack.getItem()).apply(itemStack);
}

/**
* An empty fluid filter that allows all fluids.<br>
* ONLY TO BE USED FOR FLUID MATCHING! All other functionality will throw an exception.
*/
FluidFilter EMPTY = new FluidFilter() {
@Override
public boolean test(FluidStack fluidStack) {
return true;
}

@Override
public WidgetGroup openConfigurator(int x, int y) {
throw new NotImplementedException("Not available for empty fluid filter");
}

@Override
public CompoundTag saveFilter() {
throw new NotImplementedException("Not available for empty fluid filter");
}

@Override
public void setOnUpdated(Consumer<FluidFilter> onUpdated) {
throw new NotImplementedException("Not available for empty fluid filter");
}
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gregtechceu.gtceu.api.gui;

import com.gregtechceu.gtceu.api.GTValues;
import com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture;
import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture;
import lombok.val;
Expand Down Expand Up @@ -87,6 +86,9 @@ public class GuiTextures {
public static final ResourceTexture SWITCH_HORIZONTAL = new ResourceTexture("gtceu:textures/gui/widget/switch_horizontal.png");
public static final ResourceTexture VANILLA_BUTTON = ResourceBorderTexture.BUTTON_COMMON;

public static final ResourceTexture ENERGY_DETECTOR_COVER_MODE_BUTTON = new ResourceTexture("gtceu:textures/gui/widget/button_detector_cover_energy_mode.png");
public static final ResourceTexture INVERT_REDSTONE_BUTTON = new ResourceTexture("gtceu:textures/gui/widget/button_detector_cover_inverted.png");

//INDICATORS & ICONS
public static final ResourceTexture INDICATOR_NO_ENERGY = new ResourceTexture("gtceu:textures/gui/base/indicator_no_energy.png");
public static final SteamTexture INDICATOR_NO_STEAM = SteamTexture.fullImage("gtceu:textures/gui/base/indicator_no_steam_%s.png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
Expand All @@ -49,6 +50,7 @@ public class CoverContainerConfigurator extends WidgetGroup {
protected CoverBehavior coverBehavior;
@Nullable
protected Widget coverConfigurator;
private boolean needUpdate;

public CoverContainerConfigurator(ICoverable coverable) {
super(0, 0, 120, 80);
Expand Down Expand Up @@ -102,7 +104,7 @@ public void apply(boolean isTESR, RenderType layer) {
private void coverRemoved() {
if (getGui().entityPlayer instanceof ServerPlayer serverPlayer && side != null) {
var item = transfer.getStackInSlot(0);
if (item.isEmpty() && coverable.getCoverAtSide(side) != null) {
if (coverable.getCoverAtSide(side) != null) {
coverable.removeCover(false, side);
}
if (!item.isEmpty() && coverable.getCoverAtSide(side) == null) {
Expand All @@ -128,31 +130,46 @@ private void onSideSelected(BlockPos blockPos, Direction direction) {
}
}

public void checkCoverBehaviour() {
public boolean checkCoverBehaviour() {
if (side != null) {
var coverBehaviour = coverable.getCoverAtSide(side);
if (coverBehaviour != this.coverBehavior) {
this.coverBehavior = coverBehaviour;
var attachItem = coverBehaviour == null ? ItemStack.EMPTY : coverBehaviour.getAttachItem();
transfer.setStackInSlot(0, attachItem);
updateCoverConfigurator();
return true;
}
}
return false;
}

@Override
public void updateScreen() {
super.updateScreen();
if (side != null) {
checkCoverBehaviour();
if (checkCoverBehaviour()) {
writeClientAction(-2, buf -> {});
}
}
}

@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (side != null) {
checkCoverBehaviour();
if (side != null && needUpdate) {
if (checkCoverBehaviour()) {
needUpdate = false;
}
}
}

@Override
public void handleClientAction(int id, FriendlyByteBuf buffer) {
if (id == -2) {
needUpdate = true;
} else {
super.handleClientAction(id, buffer);
}
}

Expand Down
Loading

0 comments on commit f88ff16

Please sign in to comment.