-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dane Strandboge
authored
Sep 16, 2021
1 parent
eb4eb2f
commit ca2f2a3
Showing
14 changed files
with
274 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/gregtech/api/capability/impl/NotifiableFluidTankFromList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package gregtech.api.capability.impl; | ||
|
||
import gregtech.api.capability.IMultipleTankHandler; | ||
import gregtech.api.metatileentity.MetaTileEntity; | ||
import net.minecraftforge.fluids.FluidStack; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public abstract class NotifiableFluidTankFromList extends NotifiableFluidTank { | ||
|
||
private final int index; | ||
|
||
public NotifiableFluidTankFromList(int capacity, MetaTileEntity entityToNotify, boolean isExport, int index) { | ||
super(capacity, entityToNotify, isExport); | ||
this.index = index; | ||
} | ||
|
||
public abstract Supplier<IMultipleTankHandler> getFluidTankList(); | ||
|
||
public int getIndex() { | ||
return index; | ||
} | ||
|
||
@Override | ||
public int fill(FluidStack resource, boolean doFill) { | ||
IMultipleTankHandler tanks = getFluidTankList().get(); | ||
if (!tanks.allowSameFluidFill()) { | ||
int fillIndex = tanks.getIndexOfFluid(resource); | ||
if (fillIndex != getIndex() && fillIndex != -1) return 0; | ||
} | ||
return super.fill(resource, doFill); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
...egtech/common/metatileentities/electric/multiblockpart/MetaTileEntityMultiFluidHatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package gregtech.common.metatileentities.electric.multiblockpart; | ||
|
||
import codechicken.lib.render.CCRenderState; | ||
import codechicken.lib.render.pipeline.IVertexOperation; | ||
import codechicken.lib.vec.Matrix4; | ||
import gregtech.api.capability.IMultipleTankHandler; | ||
import gregtech.api.capability.impl.FluidTankList; | ||
import gregtech.api.capability.impl.NotifiableFluidTank; | ||
import gregtech.api.capability.impl.NotifiableFluidTankFromList; | ||
import gregtech.api.gui.GuiTextures; | ||
import gregtech.api.gui.ModularUI; | ||
import gregtech.api.gui.widgets.TankWidget; | ||
import gregtech.api.metatileentity.MetaTileEntity; | ||
import gregtech.api.metatileentity.MetaTileEntityHolder; | ||
import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; | ||
import gregtech.api.metatileentity.multiblock.MultiblockAbility; | ||
import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; | ||
import gregtech.api.render.ICubeRenderer; | ||
import gregtech.api.render.SimpleOverlayRenderer; | ||
import gregtech.api.render.Textures; | ||
import net.minecraft.client.resources.I18n; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.fluids.FluidTank; | ||
import net.minecraftforge.fluids.IFluidTank; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
public class MetaTileEntityMultiFluidHatch extends MetaTileEntityMultiblockPart implements IMultiblockAbilityPart<IFluidTank> { | ||
|
||
private static final int TANK_SIZE = 16000; | ||
|
||
protected FluidTankList fluidTanks; | ||
private final boolean isExportHatch; | ||
|
||
public MetaTileEntityMultiFluidHatch(ResourceLocation metaTileEntityId, int tier, boolean isExportHatch) { | ||
super(metaTileEntityId, tier); | ||
this.isExportHatch = isExportHatch; | ||
initializeInventory(); | ||
} | ||
|
||
@Override | ||
public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder metaTileEntityHolder) { | ||
return new MetaTileEntityMultiFluidHatch(metaTileEntityId, this.getTier(), this.isExportHatch); | ||
} | ||
|
||
@Override | ||
protected void initializeInventory() { | ||
FluidTank[] fluidsHandlers = new FluidTank[(int) Math.pow(this.getTier(), 2)]; | ||
for (int i = 0; i <fluidsHandlers.length; i++) { | ||
fluidsHandlers[i] = new NotifiableFluidTankFromList(TANK_SIZE, this, isExportHatch, i) { | ||
@Override | ||
public Supplier<IMultipleTankHandler> getFluidTankList() { | ||
return () -> MetaTileEntityMultiFluidHatch.this.fluidTanks; | ||
} | ||
}; | ||
} | ||
this.fluidTanks = new FluidTankList(false, fluidsHandlers); | ||
this.fluidInventory = fluidTanks; | ||
super.initializeInventory(); | ||
} | ||
|
||
@Override | ||
public void update() { | ||
super.update(); | ||
if (!getWorld().isRemote) { | ||
if (isExportHatch) { | ||
pushFluidsIntoNearbyHandlers(getFrontFacing()); | ||
} else { | ||
pullFluidsFromNearbyHandlers(getFrontFacing()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { | ||
super.renderMetaTileEntity(renderState, translation, pipeline); | ||
if (shouldRenderOverlay()) { | ||
SimpleOverlayRenderer renderer = getTier() == 2 ? Textures.PIPE_4X_OVERLAY : Textures.PIPE_9X_OVERLAY; | ||
renderer.renderSided(getFrontFacing(), renderState, translation, pipeline); | ||
} | ||
} | ||
|
||
@Override | ||
public ICubeRenderer getBaseTexture() { | ||
MultiblockControllerBase controller = getController(); | ||
if (controller != null) { | ||
this.hatchTexture = controller.getBaseTexture(this); | ||
} | ||
if (controller == null && this.hatchTexture != null) { | ||
return this.hatchTexture; | ||
} | ||
if (controller == null) { | ||
this.setPaintingColor(DEFAULT_PAINTING_COLOR); | ||
return Textures.VOLTAGE_CASINGS[getTier() == 2 ? 3 : 5]; | ||
} | ||
this.setPaintingColor(0xFFFFFF); | ||
return controller.getBaseTexture(this); | ||
} | ||
|
||
@Override | ||
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) { | ||
super.addInformation(stack, player, tooltip, advanced); | ||
tooltip.add(I18n.format("gregtech.machine.multi_fluid_hatch_universal.tooltip.1")); | ||
tooltip.add(I18n.format("gregtech.machine.multi_fluid_hatch_universal.tooltip.2", (int) Math.pow(this.getTier(), 2))); | ||
} | ||
|
||
@Override | ||
protected FluidTankList createImportFluidHandler() { | ||
return isExportHatch ? new FluidTankList(false) : new FluidTankList(false, fluidTanks); | ||
} | ||
|
||
@Override | ||
protected FluidTankList createExportFluidHandler() { | ||
return new FluidTankList(false, fluidTanks); | ||
} | ||
|
||
@Override | ||
public MultiblockAbility<IFluidTank> getAbility() { | ||
return isExportHatch ? MultiblockAbility.EXPORT_FLUIDS : MultiblockAbility.IMPORT_FLUIDS; | ||
} | ||
|
||
@Override | ||
public void registerAbilities(List<IFluidTank> abilityList) { | ||
abilityList.addAll(isExportHatch ? this.exportFluids.getFluidTanks() : this.importFluids.getFluidTanks()); | ||
} | ||
|
||
@Override | ||
public void setupNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { | ||
FluidTankList handlers; | ||
if (isExportHatch) { | ||
handlers = getExportFluids(); | ||
} else { | ||
handlers = getImportFluids(); | ||
} | ||
if (handlers != null) { | ||
for (IFluidTank fluidTank : handlers) { | ||
if (fluidTank instanceof NotifiableFluidTank) { | ||
NotifiableFluidTank handler = (NotifiableFluidTank) fluidTank; | ||
handler.setNotifiableMetaTileEntity(metaTileEntity); | ||
handler.addToNotifiedList(this, handler, isExportHatch); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected ModularUI createUI(EntityPlayer entityPlayer) { | ||
int rowSize = getTier(); | ||
ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, | ||
18 + 18 * rowSize + 94) | ||
.label(10, 5, getMetaFullName()); | ||
|
||
for (int y = 0; y < rowSize; y++) { | ||
for (int x = 0; x < rowSize; x++) { | ||
int index = y * rowSize + x; | ||
builder.widget(new TankWidget(isExportHatch ? exportFluids.getTankAt(index) : importFluids.getTankAt(index), 89 - rowSize * 9 + x * 18, 18 + y * 18, 18, 18) | ||
.setBackgroundTexture(GuiTextures.FLUID_SLOT) | ||
.setContainerClicking(true, !isExportHatch) | ||
.setAlwaysShowFull(true)); | ||
} | ||
} | ||
builder.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 7, 18 + 18 * rowSize + 12); | ||
return builder.build(getHolder(), entityPlayer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.