Skip to content

Commit

Permalink
add a mode to force check of classifying every tick
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Feb 17, 2024
1 parent efd08e9 commit 42a1d44
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.oredict.OreDictionary;

import com.google.common.collect.ImmutableList;
import com.gtnewhorizons.modularui.api.ModularUITextures;
Expand Down Expand Up @@ -66,7 +68,9 @@
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.GregTech_API;
import gregtech.api.enums.SoundResource;
import gregtech.api.enums.ToolDictNames;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
Expand All @@ -78,6 +82,7 @@
import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.util.GT_TooltipDataCache.TooltipData;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.extensions.ArrayExt;
import gregtech.common.tileentities.machines.IDualInputInventory;
Expand Down Expand Up @@ -162,6 +167,7 @@ public List<String> getExtraTooltip() {
public NBTTagCompound writeToNBT(ItemStack is, NBTTagCompound tag) {
is.writeToNBT(tag);
tag.setInteger("ICount", is.stackSize);

return tag;
}

Expand Down Expand Up @@ -634,14 +640,15 @@ public static class CallerCheck {
}
}
}
public boolean highEfficiencyMode(){return false;}
private boolean updateEveryTick;
public boolean updateEveryTick(){return updateEveryTick;}
public boolean prevdirty;
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);
if (aBaseMetaTileEntity.getWorld().isRemote) return;


dirty=dirty||updateEveryTick();
if(dirty){updateSlots();}
dirty=dirty||getBaseMetaTileEntity().hasInventoryBeenModified();
//System.out.println(dirty);
Expand Down Expand Up @@ -1100,6 +1107,7 @@ public void loadNBTData(NBTTagCompound aNBT) {
.fromTag((NBTTagCompound) aNBT.getTag("BUFFER_" + ii));
}
justHadNewItems = aNBT.getBoolean("justHadNewItems");
updateEveryTick= aNBT.getBoolean("updateEveryTick");
super.loadNBTData(aNBT);
}

Expand All @@ -1114,6 +1122,7 @@ public void saveNBTData(NBTTagCompound aNBT) {
.toTag());

aNBT.setBoolean("justHadNewItems", justHadNewItems);
aNBT.setBoolean("updateEveryTick",updateEveryTick);
super.saveNBTData(aNBT);
}

Expand Down Expand Up @@ -1194,8 +1203,9 @@ public boolean justUpdated() {

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Optional<IDualInputInventory> getFirstNonEmptyInventory() {
dirty=true;//IRecipeProcessingAwareHatch NOT working on dualhatch, so assume multi-te will consume items after calling this
public Optional</*? extends */IDualInputInventory> getFirstNonEmptyInventory() {
dirty=true;
//IRecipeProcessingAwareHatch NOT working on dualhatch, so assume multi-te will consume items after calling this
return (Optional) inv0.stream()
.filter(not(DualInvBuffer::isEmpty))
.findAny();
Expand Down Expand Up @@ -1341,5 +1351,56 @@ public void updateSlots() {
inv0.forEach(DualInvBuffer::updateSlots);
super.updateSlots();
}


@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
BaseMetaTileEntity tile = (BaseMetaTileEntity) this.getBaseMetaTileEntity();
if (tile.isServerSide()) {
if (!tile.privateAccess() || aPlayer.getDisplayName()
.equalsIgnoreCase(tile.getOwnerName())) {
final ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem();
if (tCurrentItem != null) {
boolean suc=false;
for(int id:OreDictionary.getOreIDs(tCurrentItem)){
if(OreDictionary.getOreName(id).equals(ToolDictNames.craftingToolFile.toString())){
suc=true;break;
};
}
if(suc){
GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer);
GT_Utility.sendSoundToPlayers(
tile.getWorld(),
SoundResource.IC2_TOOLS_WRENCH,
1.0F,
-1,
tile.getXCoord(),
tile.getYCoord(),
tile.getZCoord());
updateEveryTick=!updateEveryTick;


GT_Utility
.sendChatToPlayer(aPlayer,
"updateEveryTick:"+updateEveryTick
);
GT_Utility
.sendChatToPlayer(aPlayer,
StatCollector.translateToLocal("programmable_hatches.gt.updateEveryTick")
);



markDirty();
return true;
}


}
}
}



return super.onRightclick(aBaseMetaTileEntity, aPlayer);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/proghatches/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@ tile.proghatches.peripheral_station.tooltip.3=Can only establish one-to-one conn
tile.proghatches.peripheral_station.tooltip.4=Range:16 with no inter-dimension support
tile.proghatches.peripheral_station.tooltip.5=Require no component channel.
tile.proghatches.peripheral_station.tooltip=6
programmable_hatches.gt.updateEveryTick=This mode is intended to force the check every tick when the hatch fails to work properly. Do not enable when unnecessary, for better server performance.

2 changes: 2 additions & 0 deletions src/main/resources/assets/proghatches/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,5 @@ tile.proghatches.peripheral_station.tooltip.2=只能和无线外设桥接卡建
tile.proghatches.peripheral_station.tooltip.3=距离:16格 无法跨维度
tile.proghatches.peripheral_station.tooltip.4=不占用组件数量
tile.proghatches.peripheral_station.tooltip=5
programmable_hatches.gt.updateEveryTick=此模式用于每tick强制触发仓室的转移,以防(由于bug或某些corner case)转移过程未能正确触发 如果仓室工作正常,应该关闭此功能以优化服务器负载

0 comments on commit 42a1d44

Please sign in to comment.