Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Oct 17, 2024
1 parent 2edf8c3 commit e0a9756
Show file tree
Hide file tree
Showing 19 changed files with 1,249 additions and 33 deletions.
133 changes: 133 additions & 0 deletions src/main/java/reobf/proghatches/ae/BlockStorageProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package reobf.proghatches.ae;

import java.util.List;

import com.gtnewhorizons.modularui.api.UIInfos;
import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils;

import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.items.tools.quartz.ToolQuartzCuttingKnife;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.common.blocks.GT_Material_Machines;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
import reobf.proghatches.block.INameAndTooltips;
import reobf.proghatches.block.TileIOHub;
import reobf.proghatches.lang.LangManager;

public class BlockStorageProxy extends BlockContainer implements INameAndTooltips {
private IIcon blockIconAlt;

public BlockStorageProxy() {

super(new GT_Material_Machines());

setHardness(1);
setHarvestLevel("pickaxe", 1);
setBlockName("proghatch.storageproxy");
}

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {

TileStorageProxy te=new TileStorageProxy();
if(meta==1)te.fluid=true;
return te;
}

@Override
@SideOnly(Side.CLIENT)
protected String getTextureName() {
return this.textureName = "proghatches:proxy_item";
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister reg)
{super.registerBlockIcons(reg);
this.blockIconAlt = reg.registerIcon("proghatches:proxy_fluid");
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta) {
if(meta==1)return blockIconAlt;
return super.getIcon(side, meta);
}

@Override
public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase placer, ItemStack itemIn) {

super.onBlockPlacedBy(worldIn, x, y, z, placer, itemIn);
try{
((TileStorageProxy)worldIn.getTileEntity(x, y, z)
).getProxy().setOwner((EntityPlayer) placer);
}catch(Exception e){e.printStackTrace();}
}
@Override
public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {


UIInfos.TILE_MODULAR_UI.open(player, worldIn, x, y, z);


return true;
}
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item itemIn, CreativeTabs tab, List list)
{
list.add(new ItemStack(itemIn, 1, 0));
list.add(new ItemStack(itemIn, 1, 1));
}

@Override
public void addInformation(ItemStack p_77624_1_, List l) {
int i = 0;


while (true) {

String k ="tile.proghatches.proxy.tooltip"+"."+p_77624_1_.getItemDamage();

if (LangManager.translateToLocal(k).equals(Integer.valueOf(i).toString())) {
break;
}
String key = k + "." + i;
String trans = LangManager.translateToLocal(key);

l.add(trans);
i++;

}


}
public int damageDropped(int meta)
{
return meta;
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) {
ItemStack is=super.getPickBlock(target, world, x, y, z, player);
is.setItemDamage(world.getBlockMetadata(x, y, z));

return is;
}
@Override
public String getName(ItemStack p_77624_1_) {

return super.getUnlocalizedName()+"."+p_77624_1_.getItemDamage();
}
}

25 changes: 17 additions & 8 deletions src/main/java/reobf/proghatches/ae/PatternCraftingJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public PatternCraftingJob(ICraftingPatternDetails a, IStorageGrid b){
}public boolean supportsCPUCluster(final ICraftingCPU cluster) {
return true;
}
int times;
ICraftingPatternDetails target;
@Override
public boolean isSimulation() {
Expand All @@ -54,7 +55,7 @@ public void populatePlan(IItemList<IAEItemStack> plan) {
@Override
public IAEItemStack getOutput() {
for(IAEItemStack is:target.getOutputs()){
if(is!=null)return is;
if(is!=null)return is.copy().setStackSize(times*is.getStackSize());
}
return null;
}
Expand All @@ -70,30 +71,38 @@ public Future<ICraftingJob> schedule() {

return CompletableFuture.completedFuture(this);
}
public boolean canBeDone(AENetworkProxy gg,MachineSource src){

public int canBeDone(AENetworkProxy gg,MachineSource src){
int max=Integer.MAX_VALUE;
try{
IStorageGrid g=gg.getStorage();
gg.getCrafting().getCraftingPatterns().containsValue(target);
for(IAEItemStack is:target.getCondensedInputs())
{
IAEItemStack ext = g.getItemInventory().extractItems(is, Actionable.SIMULATE,src);
if(ext==null){return false;}
if(ext.getStackSize()!=is.getStackSize()){return false;}
IAEItemStack ext = g.getItemInventory().extractItems(is.copy().setStackSize(Integer.MAX_VALUE)
, Actionable.SIMULATE,src);
if(ext==null){return 0;}
if(ext.getStackSize()>=is.getStackSize()){
max=Math.min((int) (ext.getStackSize()/is.getStackSize()),max);
}else return 0;

}
return true;
return max;
}catch(
GridAccessException E){return false;}
GridAccessException E){return 0;}
}
public final IStorageGrid context;
@Override
public void startCrafting(MECraftingInventory storage, ICraftingCPU craftingCPUCluster, BaseActionSource src) {
((CraftingCPUCluster) craftingCPUCluster).addCrafting(target, 1);
((CraftingCPUCluster) craftingCPUCluster).addCrafting(target, times);
IAEItemStack failing=null;
boolean success=true;
LinkedList<IAEItemStack> all=new LinkedList<>();
for(IAEItemStack is:target.getCondensedInputs())
{
is=is.copy().setStackSize(is.getStackSize()*times);


IAEItemStack ext = context.getItemInventory().extractItems(is, Actionable.MODULATE,src);
if(ext==null){success=false;failing=is;}
if(ext.getStackSize()!=is.getStackSize()){success=false;failing=is;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public int state(){
if(last!=null&&(!last.isCanceled())&&(!last.isDone()))return 2;
return 0;
}
boolean asManyAsPossible;
@Override
public void updateEntity() {
ticksSinceLoaded++;
Expand Down Expand Up @@ -300,7 +301,13 @@ public void updateEntity() {

if(pat==null)break end;
PatternCraftingJob job=new PatternCraftingJob(pat,getProxy().getStorage());
if(job.canBeDone(getProxy(), source)){


int howmany;
if((howmany=job.canBeDone(getProxy(), source))>0){
if(asManyAsPossible){
job.times=howmany;
}
last=getProxy().getCrafting().submitJob(job, this, null, true, source);

}submitfail=last==null;
Expand Down
Loading

0 comments on commit e0a9756

Please sign in to comment.