Skip to content

Commit

Permalink
fix NPE caused by calling markdirty() when chunk is being loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Mar 30, 2024
1 parent 47f63e1 commit d27e65f
Show file tree
Hide file tree
Showing 22 changed files with 1,628 additions and 53 deletions.
21 changes: 16 additions & 5 deletions src/main/java/reobf/proghatches/eucrafting/EUUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import appeng.tile.AEBaseTile;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
Expand Down Expand Up @@ -87,14 +88,24 @@ public static IGuiProvidingPart select(EntityPlayer player ,int x, int y, int z)
}public static final String key="proghatches.last.part.direction";

public static void open(EntityPlayer player, World world, int x, int y, int z,ForgeDirection dir) {
if (NetworkUtils.isClient()==false||player instanceof FakePlayer) {return;}
if (NetworkUtils.isClient()||player instanceof FakePlayer) {return;}
NBTTagCompound tag = player.getEntityData();
tag.setInteger(key,dir.ordinal());



MyMod.net.sendToServer(new OpenPartGuiMessage(x,y,z,dir));
MyMod.net.sendTo(new OpenPartGuiMessage(x,y,z,dir), (EntityPlayerMP) player);
EUUtil.PART_MODULAR_UI
.open(player, player.worldObj, x, y, z);
}
public static void open(EntityPlayer player, World world, int x, int y, int z,ForgeDirection dir,boolean isout) {
if (NetworkUtils.isClient()||player instanceof FakePlayer) {return;}
NBTTagCompound tag = player.getEntityData();
tag.setInteger(key,dir.ordinal());
tag.setBoolean("extraarg",isout);
MyMod.net.sendTo(new OpenPartGuiMessage(x,y,z,dir).mark(isout), (EntityPlayerMP) player);
EUUtil.PART_MODULAR_UI
.open(player, player.worldObj, x, y, z);
}



public static final UIInfo<?, ?> PART_MODULAR_UI = UIBuilder.of().container((player, world, x, y, z) -> {
return Optional.ofNullable(select(player, x, y, z)).map(part->{
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/reobf/proghatches/eucrafting/IEUSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public interface ISource{
public void refund(long amp);
public long providing();*/
}

public interface IDrain{
public default boolean isP2POut(){return false;}
public long getVoltage();

public default long inject(long a,long v){
Expand Down Expand Up @@ -61,7 +63,9 @@ public long inject(ISource s,long amp,long v){
if(amp==0){return 0;}
//long v=s.getVoltage(); //use actual voltage
long[] a=new long[]{amp};
cache.get(s.getVoltage()).stream().map(d->{
cache.get(s.getVoltage()).stream()
.filter(sx->!sx.isP2POut())
.map(d->{
long val=Math.min(a[0], d.expectedAmp());
return (a[0]-=d.inject( val,v));
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package reobf.proghatches.eucrafting;

import javax.annotation.Nullable;

import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.item.FCBaseItem;
import com.glodblock.github.common.item.ItemFluidExportBus;
import com.glodblock.github.common.parts.PartFluidExportBus;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.util.NameConst;

import appeng.api.AEApi;
import appeng.api.parts.IPartItem;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class ItemPartEUP2PInterface extends Item implements IPartItem {

public ItemPartEUP2PInterface() {
this.setMaxStackSize(64);
// this.setUnlocalizedName(NameConst.ITEM_PART_FLUID_EXPORT);
AEApi.instance().partHelper().setItemBusRenderer(this);
}

@Nullable
@Override
public PartEUP2PInterface createPartFromItemStack(ItemStack is) {
return new PartEUP2PInterface(is);
}

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side,
float xOffset, float yOffset, float zOffset) {
return AEApi.instance().partHelper().placeBus(player.getHeldItem(), x, y, z, side, player, world);
}

/*
public ItemPartEUSource register() {
//if (!Config.fluidIOBus) return null;
GameRegistry.registerItem(this, NameConst.ITEM_PART_FLUID_EXPORT, FluidCraft.MODID);
//setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
*/
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IIconRegister _iconRegister) {
//PartEUSource.registerIcons(_iconRegister);


}

@Override
@SideOnly(Side.CLIENT)
public int getSpriteNumber() {
return 0;
}


}
Loading

0 comments on commit d27e65f

Please sign in to comment.