Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Cleanroom #618

Merged
merged 46 commits into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
08d9ab4
cleanroom structure
TechLord22 Jan 28, 2022
90f72c4
cleanroom recipe property
TechLord22 Jan 28, 2022
435a254
expandable cleanroom structure
TechLord22 Jan 29, 2022
88d49c8
cleanroom workable
TechLord22 Jan 29, 2022
b17bbbf
move cleanroom checks into abstract logic
TechLord22 Jan 29, 2022
138e6ff
pass things through cleanroom walls
TechLord22 Jan 29, 2022
400eb54
cleanroom maintenance
TechLord22 Jan 29, 2022
0177dac
cleanroom config
TechLord22 Jan 29, 2022
f25e13d
CT compat
TechLord22 Jan 29, 2022
51cef7c
cleanroom requirements for recipes
TechLord22 Jan 30, 2022
272aaa4
config for clean multiblocks
TechLord22 Feb 2, 2022
e67f184
cleanroom tooltip
TechLord22 Feb 2, 2022
2d126e9
allow cleanrooms to provide multiple types and javadoc
TechLord22 Feb 5, 2022
629d558
cleanroom glass
TechLord22 Feb 5, 2022
482cf64
cleanroom recipes
TechLord22 Feb 5, 2022
6f2498b
change way machines are banned
TechLord22 Feb 5, 2022
1d94463
change data code number
TechLord22 Feb 5, 2022
880b590
proportional plascrete
TechLord22 Feb 5, 2022
829aa81
channels in hulls
Feb 24, 2022
0990d96
fix node being initialized too early
PrototypeTrousers Mar 6, 2022
95662fe
recipe fixes, ae2 lang, lower plascrete requirement
TechLord22 Mar 9, 2022
1cf3264
change plascrete requirement to walls only
TechLord22 Mar 9, 2022
a23fcdc
sterile cleanroom filters
TechLord22 Mar 21, 2022
4a85425
fix HT changes
TechLord22 Mar 21, 2022
8a18ea7
ban more machines, fix some circuit recipes
TechLord22 Mar 21, 2022
c0314e9
respect channels in cleanroom tooltip
TechLord22 Mar 21, 2022
0cf2d47
cleaning maintenance hatch
TechLord22 Mar 22, 2022
2388283
fix MTE refactor rebase issues
TechLord22 Mar 22, 2022
ae5954c
missing import
TechLord22 Mar 22, 2022
0b29d5f
cleanliness percentage system
TechLord22 May 8, 2022
0cc9fa7
recipe updates and some unification info
TechLord22 May 9, 2022
efbba4b
fix rebase compilation errors
TechLord22 May 9, 2022
80571d0
door textures for the future
TechLord22 May 9, 2022
e75f34d
review comments
TechLord22 May 29, 2022
2d99bfb
fix value save/sync, glass, blacklist central monitor
TechLord22 May 30, 2022
ff01ceb
fix cleanroom not replacing old cleanrooms on machines
TechLord22 Jun 1, 2022
c2a0d58
the most painful debug and fix of my entire lifetime - fixed crash wi…
TechLord22 Jun 2, 2022
8eaaa63
cleanroom duration increases with size, fix log spam
TechLord22 Jun 2, 2022
6384cea
fix failing test
TechLord22 Jun 2, 2022
829ac47
fix cleanliness not decreasing
TechLord22 Jun 8, 2022
3527547
Sever ICleanroomReceiver connections upon breaking cleanroom
bruberu Jun 19, 2022
f015620
Various small fixes to the cleanroom structure and to its recipes (#1…
xnossisx Jun 20, 2022
eaa80a9
passthrough hatch recipes
TechLord22 Jun 21, 2022
f968925
wip structure formation upgrade
TechLord22 Jun 30, 2022
4d9a14d
finish new structure checking
TechLord22 Jun 30, 2022
1d2dd6c
fix issues with glass in the structure
TechLord22 Jul 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/gregtech/api/block/machines/BlockMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import codechicken.lib.raytracer.IndexedCuboid6;
import codechicken.lib.raytracer.RayTracer;
import codechicken.lib.vec.Cuboid6;
import gregtech.api.GTValues;
import gregtech.api.GregTechAPI;
import gregtech.api.block.BlockCustomParticle;
import gregtech.api.block.UnlistedIntegerProperty;
Expand Down Expand Up @@ -55,6 +56,7 @@
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -251,6 +253,11 @@ public void onBlockPlacedBy(World worldIn, @Nonnull BlockPos pos, @Nonnull IBloc
} else {
metaTileEntity.setFrontFacing(placer.getHorizontalFacing().getOpposite());
}
if (Loader.isModLoaded(GTValues.MODID_APPENG)) {
if (metaTileEntity.getProxy() != null) {
metaTileEntity.getProxy().setOwner((EntityPlayer) placer);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class GregtechDataCodes {
public static final int IS_ROTOR_LOOPING = 200;
public static final int FRONT_FACE_FREE = 201;
public static final int UPDATE_ROTOR_COLOR = 201;
public static final int UPDATE_STRUCTURE_SIZE = 202;
public static final int STRUCTURE_FORMED = 400;
public static final int IS_TAPED = 550;
public static final int STORE_MAINTENANCE = 551;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import gregtech.api.capability.IWorkable;
import gregtech.api.metatileentity.MTETrait;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.multiblock.ParallelLogicType;
import gregtech.api.metatileentity.multiblock.*;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.recipes.logic.IParallelableRecipeLogic;
import gregtech.api.recipes.recipeproperties.CleanroomProperty;
import gregtech.api.recipes.recipeproperties.RecipePropertyStorage;
import gregtech.api.util.GTTransferUtils;
import gregtech.api.util.GTUtility;
Expand Down Expand Up @@ -244,7 +245,20 @@ protected void updateRecipeProgress() {
* @return {@code true} if the recipe can progress, else false
*/
protected boolean canProgressRecipe() {
return true;
if (previousRecipe == null)
return true;

CleanroomType requiredType = null;
if (previousRecipe.hasProperty(CleanroomProperty.getInstance())) {
requiredType = previousRecipe.getProperty(CleanroomProperty.getInstance(), null);
}

if (requiredType == null) return true;

ICleanroomProvider cleanroomProvider = ((ICleanroomReceiver) getMetaTileEntity()).getCleanroom();
if (cleanroomProvider == null) return false;

return cleanroomProvider.isClean() && cleanroomProvider.getTypes().contains(requiredType);
}

/**
Expand Down Expand Up @@ -294,8 +308,20 @@ protected boolean checkPreviousRecipe() {
* @param recipe the recipe to check
* @return true if the recipe is allowed to be used, else false
*/
protected boolean checkRecipe(Recipe recipe) {
return true;
protected boolean checkRecipe(@Nonnull Recipe recipe) {
CleanroomType requiredType = null;
if (recipe.hasProperty(CleanroomProperty.getInstance())) {
requiredType = recipe.getProperty(CleanroomProperty.getInstance(), null);
}

if (requiredType == null) return true;

if (getMetaTileEntity() instanceof MultiblockWithDisplayBase && ConfigHolder.machines.cleanMultiblocks) return true;

ICleanroomProvider cleanroomProvider = ((ICleanroomReceiver) getMetaTileEntity()).getCleanroom();
if (cleanroomProvider == null) return false;

return cleanroomProvider.isClean() && cleanroomProvider.getTypes().contains(requiredType);
}

/**
Expand Down
240 changes: 240 additions & 0 deletions src/main/java/gregtech/api/capability/impl/CleanroomLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
package gregtech.api.capability.impl;

import gregtech.api.capability.GregtechDataCodes;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.multiblock.ICleanroomProvider;
import gregtech.api.metatileentity.multiblock.IMaintenance;
import gregtech.common.ConfigHolder;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.world.World;

import javax.annotation.Nonnull;

public class CleanroomLogic {

public static final int BASE_CLEAN_AMOUNT = 5;

private int maxProgress = 0;
private int progressTime = 0;

private final int minEnergyTier;

private final MetaTileEntity metaTileEntity;
private final boolean hasMaintenance;

private boolean isActive;
private boolean isWorkingEnabled = true;
private boolean wasActiveAndNeedsUpdate;

private boolean hasNotEnoughEnergy;

public CleanroomLogic(MetaTileEntity metaTileEntity, int minEnergyTier) {
this.metaTileEntity = metaTileEntity;
this.minEnergyTier = minEnergyTier;
this.hasMaintenance = ConfigHolder.machines.enableMaintenance && ((IMaintenance) metaTileEntity).hasMaintenanceMechanics();
}

/**
* Performs the actual cleaning
* Call this method every tick in update
*/
public void updateLogic() {
// cleanrooms which cannot work do nothing
if (!this.isWorkingEnabled) return;

// all maintenance problems not fixed means the machine does not run
if (hasMaintenance && ((IMaintenance) metaTileEntity).getNumMaintenanceProblems() > 5) return;

// drain the energy
if (consumeEnergy(true)) {
consumeEnergy(false);
} else {
if (progressTime >= 2) {
if (ConfigHolder.machines.recipeProgressLowEnergy) this.progressTime = 1;
else this.progressTime = Math.max(1, progressTime - 2);
}
hasNotEnoughEnergy = true;

// the cleanroom does not have enough energy, so it looses cleanliness
if (metaTileEntity.getOffsetTimer() % maxProgress == 0) {
adjustCleanAmount(true);
}
return;
}

if (!this.isActive) setActive(true);

// increase progress
progressTime++;
if (progressTime % getMaxProgress() != 0) return;
progressTime = 0;

adjustCleanAmount(false);
}

protected void adjustCleanAmount(boolean shouldRemove) {
int amountToClean = BASE_CLEAN_AMOUNT * (getTierDifference() + 1);
if (shouldRemove) amountToClean *= -1;

// each maintenance problem lowers gain by 1
if (hasMaintenance) amountToClean -= ((IMaintenance) metaTileEntity).getNumMaintenanceProblems();
((ICleanroomProvider) metaTileEntity).adjustCleanAmount(amountToClean);
}

protected boolean consumeEnergy(boolean simulate) {
return ((ICleanroomProvider) metaTileEntity).drainEnergy(simulate);
}

public void invalidate() {
this.progressTime = 0;
this.maxProgress = 0;
setActive(false);
}

/**
* @return true if the cleanroom is active
*/
public boolean isActive() {
return this.isActive && isWorkingEnabled();
}

/**
* @param active the new state of the cleanroom's activity: true to change to active, else false
*/
public void setActive(boolean active) {
if (this.isActive != active) {
this.isActive = active;
this.metaTileEntity.markDirty();
World world = this.metaTileEntity.getWorld();
if (world != null && !world.isRemote) {
this.metaTileEntity.writeCustomData(GregtechDataCodes.WORKABLE_ACTIVE, buf -> buf.writeBoolean(active));
}
}
}

/**
* @param workingEnabled the new state of the cleanroom's ability to work: true to change to enabled, else false
*/
public void setWorkingEnabled(boolean workingEnabled) {
this.isWorkingEnabled = workingEnabled;
this.metaTileEntity.markDirty();
World world = this.metaTileEntity.getWorld();
if (world != null && !world.isRemote) {
this.metaTileEntity.writeCustomData(GregtechDataCodes.WORKING_ENABLED, buf -> buf.writeBoolean(workingEnabled));
}
}

/**
* @return whether working is enabled for the logic
*/
public boolean isWorkingEnabled() {
return isWorkingEnabled;
}

/**
* @return whether the cleanroom is currently working
*/
public boolean isWorking() {
return isActive && !hasNotEnoughEnergy && isWorkingEnabled;
}

/**
* @return the current progress towards completing one cycle of the cleanroom
*/
public int getProgressTime() {
return this.progressTime;
}

public void setMaxProgress(int maxProgress) {
this.maxProgress = maxProgress;
}

public int getMaxProgress() {
return this.maxProgress;
}

public int getProgressPercent() {
return (int) ((1.0F * getProgressTime() / getMaxProgress()) * 100);
}

protected int getTierDifference() {
return ((ICleanroomProvider) metaTileEntity).getEnergyTier() - minEnergyTier;
}

/**
* writes all needed values to NBT
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#writeToNBT(NBTTagCompound)} method
*/
public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound data) {
data.setBoolean("isActive", this.isActive);
data.setBoolean("isWorkingEnabled", this.isWorkingEnabled);
data.setBoolean("wasActiveAndNeedsUpdate", this.wasActiveAndNeedsUpdate);
data.setInteger("progressTime", progressTime);
data.setInteger("maxProgress", maxProgress);
return data;
}

/**
* reads all needed values from NBT
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#readFromNBT(NBTTagCompound)} method
*/
public void readFromNBT(@Nonnull NBTTagCompound data) {
this.isActive = data.getBoolean("isActive");
this.isWorkingEnabled = data.getBoolean("isWorkingEnabled");
this.wasActiveAndNeedsUpdate = data.getBoolean("wasActiveAndNeedsUpdate");
this.progressTime = data.getInteger("progressTime");
this.maxProgress = data.getInteger("maxProgress");
}

/**
* writes all needed values to InitialSyncData
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#writeInitialSyncData(PacketBuffer)} method
*/
public void writeInitialSyncData(@Nonnull PacketBuffer buf) {
buf.writeBoolean(this.isActive);
buf.writeBoolean(this.isWorkingEnabled);
buf.writeBoolean(this.wasActiveAndNeedsUpdate);
buf.writeInt(this.progressTime);
buf.writeInt(this.maxProgress);
}

/**
* reads all needed values from InitialSyncData
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#receiveInitialSyncData(PacketBuffer)} method
*/
public void receiveInitialSyncData(@Nonnull PacketBuffer buf) {
setActive(buf.readBoolean());
setWorkingEnabled(buf.readBoolean());
setWasActiveAndNeedsUpdate(buf.readBoolean());
this.progressTime = buf.readInt();
this.maxProgress = buf.readInt();
}

/**
* reads all needed values from CustomData
* This MUST be called and returned in the MetaTileEntity's {@link MetaTileEntity#receiveCustomData(int, PacketBuffer)} method
*/
public void receiveCustomData(int dataId, PacketBuffer buf) {
if (dataId == GregtechDataCodes.IS_WORKING) {
setActive(buf.readBoolean());
metaTileEntity.scheduleRenderUpdate();
}
}

/**
* @return whether the cleanroom was active and needs an update
*/
public boolean wasActiveAndNeedsUpdate() {
return this.wasActiveAndNeedsUpdate;
}

/**
* set whether the cleanroom was active and needs an update
*
* @param wasActiveAndNeedsUpdate the state to set
*/
public void setWasActiveAndNeedsUpdate(boolean wasActiveAndNeedsUpdate) {
this.wasActiveAndNeedsUpdate = wasActiveAndNeedsUpdate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.util.Tuple;
import net.minecraftforge.items.IItemHandlerModifiable;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -42,7 +43,7 @@ public void updateWorkable() {

@Override
protected boolean canProgressRecipe() {
return !((IMultiblockController) metaTileEntity).isStructureObstructed();
return super.canProgressRecipe() && !((IMultiblockController) metaTileEntity).isStructureObstructed();
}

/**
Expand Down Expand Up @@ -295,7 +296,7 @@ protected Tuple<Integer, Double> getMaintenanceValues() {
}

@Override
protected boolean checkRecipe(Recipe recipe) {
protected boolean checkRecipe(@Nonnull Recipe recipe) {
RecipeMapMultiblockController controller = (RecipeMapMultiblockController) metaTileEntity;
if (controller.checkRecipe(recipe, false)) {
controller.checkRecipe(recipe, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ protected long getMaxVoltage() {
return Math.max(energyContainer.get().getInputVoltage(),
energyContainer.get().getOutputVoltage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void update() {
}

@Override
protected boolean checkRecipe(Recipe recipe) {
protected boolean checkRecipe(@Nonnull Recipe recipe) {
return super.checkRecipe(recipe) && !this.needsVenting;
}

Expand Down
Loading