Skip to content

Commit

Permalink
handle null capabilty issue and show that on the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed Nov 12, 2020
1 parent 8da6d7a commit bf1286d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/main/java/gregtech/common/covers/CoverConveyor.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class CoverConveyor extends CoverBehavior implements CoverWithUI, ITickab
protected int itemsLeftToTransferLastSecond;
private CoverableItemHandlerWrapper itemHandlerWrapper;
protected boolean isWorkingAllowed = true;
protected DiagnoseIssue diagnoseIssue;

public CoverConveyor(ICoverable coverable, EnumFacing attachedSide, int tier, int itemsPerSecond) {
super(coverable, attachedSide);
Expand All @@ -56,6 +57,7 @@ public CoverConveyor(ICoverable coverable, EnumFacing attachedSide, int tier, in
this.transferRate = maxItemTransferRate;
this.itemsLeftToTransferLastSecond = transferRate;
this.conveyorMode = ConveyorMode.EXPORT;
this.diagnoseIssue = DiagnoseIssue.IDLING;
this.itemFilterContainer = new ItemFilterContainer(this);
}

Expand Down Expand Up @@ -86,6 +88,14 @@ protected void setManualImportExportMode(ManualImportExportMode manualImportExpo
coverHolder.markDirty();
}

public DiagnoseIssue getDiagnoseIssue() {
return this.diagnoseIssue;
}

public void setDiagnoseIssue(DiagnoseIssue diagnoseIssue) {
this.diagnoseIssue = diagnoseIssue;
}

@Override
public void update() {
long timer = coverHolder.getTimer();
Expand All @@ -99,6 +109,12 @@ public void update() {
}
}
if (timer % 20 == 0) {
if (itemsLeftToTransferLastSecond < transferRate) {
setDiagnoseIssue(DiagnoseIssue.WORKING);
}
if (itemsLeftToTransferLastSecond == transferRate) {
setDiagnoseIssue(DiagnoseIssue.IDLING);
}
this.itemsLeftToTransferLastSecond = transferRate;
}
}
Expand Down Expand Up @@ -392,6 +408,10 @@ public EnumActionResult onScrewdriverClick(EntityPlayer playerIn, EnumHand hand,
@Override
public <T> T getCapability(Capability<T> capability, T defaultValue) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
if (defaultValue == null ) {
setDiagnoseIssue(DiagnoseIssue.EXPECTED_CAPABILITY_UNAVAILABLE);
return null;
}
IItemHandler delegate = (IItemHandler) defaultValue;
if (itemHandlerWrapper == null || itemHandlerWrapper.delegate != delegate) {
this.itemHandlerWrapper = new CoverableItemHandlerWrapper(delegate);
Expand Down Expand Up @@ -429,6 +449,8 @@ public ModularUI createUI(EntityPlayer player) {
ManualImportExportMode.class, this::getManualImportExportMode, this::setManualImportExportMode)
.setTooltipHoverString("cover.universal.manual_import_export.mode.description"));

primaryGroup.addWidget(new DiagnoseWidget(80,90,16,16,DiagnoseIssue.class,this::getDiagnoseIssue));

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

ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 190 + 82)
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/gregtech/common/covers/CoverPump.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class CoverPump extends CoverBehavior implements CoverWithUI, ITickable,
protected boolean isWorkingAllowed = true;
protected final FluidFilterContainer fluidFilter;
protected BucketMode bucketMode;
protected DiagnoseIssue diagnoseIssue;

public CoverPump(ICoverable coverHolder, EnumFacing attachedSide, int tier, int mbPerTick) {
super(coverHolder, attachedSide);
Expand All @@ -56,6 +57,7 @@ public CoverPump(ICoverable coverHolder, EnumFacing attachedSide, int tier, int
this.fluidLeftToTransferLastSecond = transferRate;
this.pumpMode = PumpMode.EXPORT;
this.bucketMode = BucketMode.MILLI_BUCKET;
this.diagnoseIssue = DiagnoseIssue.IDLING;
this.fluidFilter = new FluidFilterContainer(this);
}

Expand Down Expand Up @@ -98,13 +100,27 @@ protected void setManualImportExportMode(ManualImportExportMode manualImportExpo
coverHolder.markDirty();
}

public DiagnoseIssue getDiagnoseIssue() {
return this.diagnoseIssue;
}

public void setDiagnoseIssue(DiagnoseIssue diagnoseIssue) {
this.diagnoseIssue = diagnoseIssue;
}

@Override
public void update() {
long timer = coverHolder.getTimer();
if (isWorkingAllowed && fluidLeftToTransferLastSecond > 0) {
this.fluidLeftToTransferLastSecond -= doTransferFluids(fluidLeftToTransferLastSecond);
}
if (timer % 20 == 0) {
if (fluidLeftToTransferLastSecond < transferRate) {
setDiagnoseIssue(DiagnoseIssue.WORKING);
}
if (fluidLeftToTransferLastSecond == transferRate) {
setDiagnoseIssue(DiagnoseIssue.IDLING);
}
this.fluidLeftToTransferLastSecond = transferRate;
}
}
Expand Down Expand Up @@ -157,7 +173,9 @@ public ModularUI createUI(EntityPlayer player) {
primaryGroup.addWidget(new CycleButtonWidget(10, 160, 113, 20,
ManualImportExportMode.class, this::getManualImportExportMode, this::setManualImportExportMode)
.setTooltipHoverString("cover.universal.manual_import_export.mode.description"));


primaryGroup.addWidget(new DiagnoseWidget(80,84,16,16,DiagnoseIssue.class,this::getDiagnoseIssue));

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

return ModularUI.builder(GuiTextures.BACKGROUND, 176, 184 + 82)
Expand Down Expand Up @@ -201,6 +219,10 @@ public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexO
@Override
public <T> T getCapability(Capability<T> capability, T defaultValue) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
if (defaultValue == null ) {
setDiagnoseIssue(DiagnoseIssue.EXPECTED_CAPABILITY_UNAVAILABLE);
return null;
}
IFluidHandler delegate = (IFluidHandler) defaultValue;
if (fluidHandlerWrapper == null || fluidHandlerWrapper.delegate != delegate) {
this.fluidHandlerWrapper = new CoverableFluidHandlerWrapper(delegate);
Expand Down

0 comments on commit bf1286d

Please sign in to comment.