Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Jul 28, 2024
1 parent 3028d95 commit 80457c6
Show file tree
Hide file tree
Showing 18 changed files with 577 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ catch (Exception ignored) {

// Pulls version first from the VERSION env and then git tag
String identifiedVersion = null
String versionOverride = '0.0.17p15'
String versionOverride = '0.0.17p16'
try {
// Produce a version based on the tag, or for branches something like 0.2.2-configurable-maven-and-extras.38+43090270b6-dirty
if (versionOverride == null) {
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/reobf/proghatches/block/BlockAnchorAlert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package reobf.proghatches.block;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;

public class BlockAnchorAlert extends BlockContainer{

public BlockAnchorAlert(Material p_i45386_1_) {
super(p_i45386_1_);

setHardness(1);
setHarvestLevel("pickaxe", 1);
setBlockName("proghatch.chunk_loading_alert");
}
@Override
public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase placer, ItemStack itemIn) {

super.onBlockPlacedBy(worldIn, x, y, z, placer, itemIn);

if(placer instanceof EntityPlayer){
if(!(placer instanceof FakePlayer))
((TileAnchorAlert)worldIn.getTileEntity(x, y, z)).mark((EntityPlayer) placer);
}


}@Override
public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
if(worldIn.isRemote)return true;
TileAnchorAlert a=((TileAnchorAlert)worldIn.getTileEntity(x, y, z));

if(player.getUniqueID().equals(a.owner)==false){
player.addChatComponentMessage(new ChatComponentTranslation("proghatch.chunk_loading_alert.owner"));
return false;}
a.mode++;
if(a.mode>3)a.mode=0;
a.markDirty();
player.addChatComponentMessage(new ChatComponentTranslation("proghatch.chunk_loading_alert.mode."+a.mode));




return true;
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {

return new TileAnchorAlert();
}

@SideOnly(value=Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta) {

if(side<=1)return top;

return this.side;
}
@SideOnly(value=Side.CLIENT)
IIcon side;
@SideOnly(value=Side.CLIENT)
IIcon top;
@SideOnly(value=Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister reg) {
side=reg.registerIcon("proghatches:speech_box_front");
top=reg.registerIcon("proghatches:BlockSpatialPylon_dim");

super.registerBlockIcons(reg);
}

}
214 changes: 214 additions & 0 deletions src/main/java/reobf/proghatches/block/ChunkTrackingGridCahce.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
package reobf.proghatches.block;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;

import appeng.api.networking.IGrid;
import appeng.api.networking.IGridBlock;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.IGridStorage;
import appeng.api.util.DimensionalCoord;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;

public class ChunkTrackingGridCahce implements IChunkTrackingGridCahce{
public ChunkTrackingGridCahce(final IGrid g) {
this.myGrid = g;
callbacks.put(this, null);
}
private final IGrid myGrid;

public static WeakHashMap<ChunkTrackingGridCahce,Object> callbacks=new WeakHashMap<>();



static class ChunkInfo implements Cloneable{

public String toString() {

return chunkx+" "+ chunky+" "+dim;

};
ChunkInfo(int worldx,int worldy,World w){
this.chunkx=worldx>>4;
this.chunky=worldy>>4;
this.dim=w.provider.dimensionId;
}
final int chunkx,chunky;
final int dim;
@Override
public boolean equals(Object obj) {
if(obj==null)return false;
if(!(obj instanceof ChunkInfo))return false;
ChunkInfo other=(ChunkInfo)obj;
return chunkx==other.chunkx&&
chunky==other.chunky&&
dim==other.dim;
}
@Override
public int hashCode() {
return chunkx^chunky^dim;
}


}


public HashMap<ChunkInfo,Integer> track=new HashMap<>();


@Override
public void onUpdateTick() {
// System.out.println(this.hashCode()+" "+track);
;
}

@Override
public void removeNode(IGridNode gridNode, IGridHost machine) {
if(machine instanceof TileAnchorAlert){
terminals.remove((TileAnchorAlert) machine);
}
IGridBlock gb = gridNode.getGridBlock();

if(gb.isWorldAccessible()){
DimensionalCoord loc = gb.getLocation();
World w= loc.getWorld();
if(w==null){
return;//?
}

Integer ret=track.merge(new ChunkInfo(loc.x, loc.z,w), -1, (a,b)->{
int retu=a+b;
return retu==0?null:retu;
});


}

}
LinkedList<TileAnchorAlert> terminals=new LinkedList<>();
@Override
public void addNode(IGridNode gridNode, IGridHost machine) {
if(machine instanceof TileAnchorAlert){
terminals.add((TileAnchorAlert) machine);
}
IGridBlock gb = gridNode.getGridBlock();

if(gb.isWorldAccessible()){
DimensionalCoord loc = gb.getLocation();
World w= loc.getWorld();
if(w==null){
return;//?
}

track.merge(new ChunkInfo(loc.x, loc.z,w), 1, (a,b)->a+b);
}
}

@Override
public void onSplit(IGridStorage destinationStorage) {


}

@Override
public void onJoin(IGridStorage sourceStorage) {


}

@Override
public void populateGridStorage(IGridStorage destinationStorage) {


}


@SuppressWarnings("rawtypes")
public void warn(ChunkInfo info,int i){


HashSet<UUID> playersUUIDToInform=new HashSet<>();
HashSet<World> dimensionsToInform=new HashSet<>();
boolean[] informAll=new boolean[1];

terminals.forEach(s->{
if(s.mode==s.ALL){informAll[0]=true;}
if(s.mode==s.DIM){dimensionsToInform.add(s.getWorldObj());}
if(s.mode==s.OWNER){playersUUIDToInform.add(s.owner);}
});
HashSet<EntityPlayer> playersToInform=new HashSet<>();
if(informAll[0]==false)
if(playersUUIDToInform.isEmpty()==false){
List l=MinecraftServer.getServer().getConfigurationManager().playerEntityList;
List<EntityPlayer> player=l;
for(EntityPlayer p:player){
if(playersUUIDToInform.contains(p.getUniqueID())){
playersToInform.add(p);
}
}
}
if(informAll[0]==false)
dimensionsToInform.forEach(s->{
playersToInform.addAll(s.playerEntities);
});

if(informAll[0]){
playersToInform.addAll(MinecraftServer.getServer().getConfigurationManager().playerEntityList);
}





for(Object o:playersToInform){
if(((EntityPlayer)o).getEntityWorld().provider.dimensionId==info.dim)
((EntityPlayer)o).addChatMessage(new ChatComponentTranslation(
"proghatch.chunk_loading_alert.alert",

"X:"+info.chunkx+",Z:"+info.chunky+" "+
"Center:"+((info.chunkx<<4)+8)+","+((info.chunky<<4)+8)


,i

));;
}


System.out.println("Unload chunk:"+info+" with "+i+" Node(s) inside.");

}


public void unload(Chunk o) {ChunkInfo info;
Integer tck = track.get(info=new ChunkInfo(o.xPosition<<4, o.zPosition<<4, o.worldObj));
if(tck!=null){
warn(info,tck);
}
}
public void unload(World o) {
track.forEach((a,b)->{
if(a.dim==o.provider.dimensionId){
if(b!=null)
warn(a,b);
}
});
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package reobf.proghatches.block;

import appeng.api.networking.IGridCache;

public interface IChunkTrackingGridCahce extends IGridCache{

}
44 changes: 44 additions & 0 deletions src/main/java/reobf/proghatches/block/ItemBlockAnchorAlert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package reobf.proghatches.block;

import java.util.List;

import com.gtnewhorizons.modularui.api.KeyboardUtil;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import reobf.proghatches.lang.LangManager;

public class ItemBlockAnchorAlert extends ItemBlock {



public ItemBlockAnchorAlert(Block p_i45328_1_) {
super(p_i45328_1_);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) {
int i = 0;
while (true) {
String k = "tile.chunk_loading_alert.tooltip";

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

p_77624_3_.add(trans);
i++;

}
super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_);
}

}
Loading

0 comments on commit 80457c6

Please sign in to comment.