Make ResourceView implement Closeable

This commit is contained in:
shedaniel
2022-02-04 03:12:38 +08:00
parent a274b7c631
commit 5a9fca2207
8 changed files with 66 additions and 11 deletions

View File

@@ -133,17 +133,24 @@ public class FluidTransferImpl {
@NotNull
@Override
public net.minecraftforge.fluids.FluidStack getFluidInTank(int index) {
return FluidStackHooksForge.toForge(handler.getContent(index).getResource());
try (var resource = handler.getContent(index)) {
return FluidStackHooksForge.toForge(resource.getResource());
}
}
@Override
public int getTankCapacity(int index) {
return (int) handler.getContent(index).getCapacity();
try (var resource = handler.getContent(index)) {
return (int) resource.getCapacity();
}
}
@Override
public boolean isFluidValid(int index, @NotNull net.minecraftforge.fluids.FluidStack stack) {
FluidStack content = handler.getContent(index).getResource();
FluidStack content;
try (var resource = handler.getContent(index)) {
content = resource.getResource();
}
return content.getFluid() == stack.getFluid() && Objects.equals(content.getTag(), stack.getTag());
}
@@ -305,6 +312,10 @@ public class FluidTransferImpl {
public void loadState(Object state) {
throw new UnsupportedOperationException();
}
@Override
public void close() {
}
}
}

View File

@@ -106,12 +106,16 @@ public class ItemTransferImpl {
@NotNull
@Override
public ItemStack getStackInSlot(int index) {
return handler.getContent(index).getResource();
try (var resource = handler.getContent(index)) {
return resource.getResource();
}
}
@Override
public int getSlotLimit(int index) {
return (int) handler.getContent(index).getCapacity();
try (var resource = handler.getContent(index)) {
return (int) resource.getCapacity();
}
}
@NotNull
@@ -128,7 +132,11 @@ public class ItemTransferImpl {
@Override
public boolean isItemValid(int index, @NotNull ItemStack stack) {
ItemStack content = handler.getContent(index).getResource();
ItemStack content;
try (var resource = handler.getContent(index)) {
content = resource.getResource();
}
return content.getItem() == stack.getItem() && Objects.equals(content.getTag(), stack.getTag());
}
}
@@ -247,6 +255,10 @@ public class ItemTransferImpl {
public void loadState(Object state) {
throw new UnsupportedOperationException();
}
@Override
public void close() {
}
}
}
}