Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

my code is :

     

   

if(utils.getModularItemInInventory(player, "Power Fist") != null){ // get MPS power fist from player's inv
		ItemStack stack = utils.getModularItemInInventory(player, "Power Fist"); //get MPS power fist from player's inv
		if(utils.isKeyPressed(player.username) && utils.whatKeyIsPressed(player.username).contains("Z")){ // if key is pressed (server side remake)
			if(stack != null && stack.getItem().equals(ModularPowersuits.powerTool)){//more check,actually not needed
				if(stack.stackTagCompound != null){ //more check,actually not needed
					if(stack.stackTagCompound.hasKey("PeripheralPassword")){
						utils.chat(player, "has key");
						String ind = stack.stackTagCompound.getString("PeripheralPassword");
						ChairTile p = utils.getChairTileWithEniqueIndentifier(player.worldObj, player.username, ind,player); //my code for getting peripheral by username and enique id
						if(p != null){
							utils.chat(player, "p ! null");
							if(p.pc != null){ // it's actually the computercraft peripheral
								utils.chat(player, "p.pc ! null");
								PacketHandler.ssGui1.put(player.username, player);
								PacketHandler.ssGui2.put(player, p.pc);
								SimplePacket sp = new SimplePacket("ssGui",player.username);
								sp.sendPacketTo(Where.PLAYER, player);
                                                                        //what i need here is to send packet to client to tell it to open guiscreen
                                                                        //But that doesn't work (i use Modloader.openGUI(EntityPlayer,GuiScreen))
                                                                        //is there anyway to open it on server ?
                                                                        //if no is IPacketHandler used for both client and server packets ?
                                                                        //how to corretly use it as client packethandler
							}
						}
					}
				}
			}


		}
	}

  • Author

EntityPlayer.openGui doesn't work for me . One more thing . Its just GuiScreen not GuiContainer . So what should i return in getServerGuiElement ? if null that doesn't work .

  • Author

GuiHandler :

 

public class GuiHandler implements IGuiHandler {

public static HashMap<EntityPlayer,Integer> indentifier = new HashMap();
public static HashMap<EntityPlayer,IComputerAccess> ssGui = new HashMap();



@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	// TODO Auto-generated method stub
	if(ID == 1){

		ItemStack stack = utils.getModularItemInInventory(player,"Power Fist");

		if(stack != null && ModuleManager.itemHasActiveModule(stack, BagModule.NAME)){

			int indentifier = 0;

			if(this.indentifier.containsKey(player)){
				indentifier = this.indentifier.get(player);
			}else{
				indentifier = utils.generateRandomInteger();
				this.indentifier.put(player, indentifier);
			}

			if(stack.stackTagCompound.hasKey("bag")){

			    stack.stackTagCompound.getCompoundTag("bag").setInteger("indentifier",indentifier);
			}else{

				stack.stackTagCompound.setCompoundTag("bag", new NBTTagCompound());
			    stack.stackTagCompound.getCompoundTag("bag").setInteger("indentifier",indentifier);
			}
			if(!stack.stackTagCompound.getCompoundTag("bag").hasKey("freq")){
				stack.stackTagCompound.getCompoundTag("bag").setInteger("freq",1);

			}
			if(!stack.stackTagCompound.getCompoundTag("bag").hasKey(String.valueOf(stack.stackTagCompound.getCompoundTag("bag").getInteger("freq")))){
				NBTTagCompound nbt1 = stack.stackTagCompound.getCompoundTag("bag");
        		NBTTagCompound nbt = new NBTTagCompound();
                NBTTagList itemList = new NBTTagList();
                
                nbt.setTag("Inventory", itemList);
                nbt1.setCompoundTag(String.valueOf(stack.stackTagCompound.getCompoundTag("bag").getInteger("freq")),nbt);
                stack.stackTagCompound.setCompoundTag("bag", nbt1);
			}
			return new ContainerBag(stack,player,indentifier);
		}

		//return new ContainerBag( null, null,null,player,1);


	}else if(ID == 2){
		IInventory[] invs = utils.getPeripheralInventories(player, world);
		MovingObjectPosition spot = RemoteItem.getPlayerLookingSpot(player, false);
		if(spot != null && spot.typeOfHit != null){
			switch(spot.typeOfHit){
			case ENTITY:
				break;
			case TILE :
				if(world.getBlockTileEntity(spot.blockX, spot.blockY, spot.blockZ) != null && world.getBlockTileEntity(spot.blockX, spot.blockY, spot.blockZ) instanceof ChairTile){
					return new ContainerPeripheral(invs[0],invs[1],(ChairTile) world.getBlockTileEntity(spot.blockX, spot.blockY, spot.blockZ));
				}
			}
		}
	}else if(ID == 3){
		return new SensorScreenGui(ssGui.get(player));
	}
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {

	if(ID == 1){
		ItemStack stack = utils.getModularItemInInventory(player, "Power Fist");

		if(stack != null && ModuleManager.itemHasActiveModule(stack, BagModule.NAME)){
			int indentifier = 0;

			if(this.indentifier.containsKey(player)){
				indentifier = this.indentifier.get(player);
			}else{
				indentifier = utils.generateRandomInteger();
				this.indentifier.put(player, indentifier);
			}

			if(stack.stackTagCompound.hasKey("bag")){

			    stack.stackTagCompound.getCompoundTag("bag").setInteger("indentifier",indentifier);
			}else{
			    
				stack.stackTagCompound.setCompoundTag("bag", new NBTTagCompound());
			    stack.stackTagCompound.getCompoundTag("bag").setInteger("indentifier",indentifier);
			}
			if(!stack.stackTagCompound.getCompoundTag("bag").hasKey("freq")){
				stack.stackTagCompound.getCompoundTag("bag").setInteger("freq",1);
			}
			if(!stack.stackTagCompound.getCompoundTag("bag").hasKey(String.valueOf(stack.stackTagCompound.getCompoundTag("bag").getInteger("freq")))){
				NBTTagCompound nbt1 = stack.stackTagCompound.getCompoundTag("bag");
        		NBTTagCompound nbt = new NBTTagCompound();
                NBTTagList itemList = new NBTTagList();
                
                nbt.setTag("Inventory", itemList);
                nbt1.setCompoundTag(String.valueOf(stack.stackTagCompound.getCompoundTag("bag").getInteger("freq")),nbt);
                stack.stackTagCompound.setCompoundTag("bag", nbt1);
			}
			return new GuiBag(new ContainerBag(stack,player,indentifier));
		}

		//return new GuiBag( null, null,null,player,1,new ContainerBag(null, null,null,player,1));

	}else if(ID == 2){
		IInventory[] invs = utils.getPeripheralInventories(player, world);
		MovingObjectPosition spot = RemoteItem.getPlayerLookingSpot(player, false);
		if(spot != null && spot.typeOfHit != null){
			switch(spot.typeOfHit){
			case ENTITY:
				break;
			case TILE :
				if(world.getBlockTileEntity(spot.blockX, spot.blockY, spot.blockZ) != null && world.getBlockTileEntity(spot.blockX, spot.blockY, spot.blockZ) instanceof ChairTile){
					return new GuiPeripheral(invs[0],invs[1],(ChairTile) world.getBlockTileEntity(spot.blockX, spot.blockY, spot.blockZ));
				}
			}
		}
	}else if(ID == 3){
		return new SensorScreenGui(ssGui.get(player));
	}
	return null;
}

 

 

    Gui Registration :

       

@EventHandler
    public void load(FMLInitializationEvent event)
    {
    	//Recipes
    	LoadStuff.loadRecipes();
    	//
    	
    	blockCheese = (ChairBlock) new ChairBlock(blockCheeseID,Material.wood).setCreativeTab(CreativeTabs.tabDecorations).setUnlocalizedName("Russoul's Peripheral");
        russy = (Russy_Ore) new Russy_Ore(russyID,Material.rock).setCreativeTab(CreativeTabs.tabBlock).setUnlocalizedName("Russy ore");
        itemBlasterRifle = new ItemBlasterRifle(this.itemBlasterRifleID).setUnlocalizedName("BlasterRifle").setCreativeTab(CreativeTabs.tabRedstone);
        itemBlasterBolt = new ItemBlasterBolt(this.itemBlasterBoltID).setUnlocalizedName("BlasterBolt").setCreativeTab(CreativeTabs.tabRedstone);
    	
        
    	TickRegistry.registerTickHandler(new MyTickHandler(EnumSet.of(TickType.PLAYER)), Side.SERVER);
    	proxy.registerRenderers();
        proxy.registerEvents();
    	
    	EntityRegistry.registerModEntity(EntityBlasterBolt.class, "BlasterBolt", EntityRegistry.findGlobalUniqueEntityId(), this, 64, 10, true);
    	
    	GameRegistry.registerBlock(blockCheese,ItemBlock.class,"R_Peripheral",modID);
        GameRegistry.registerBlock(russy,ItemBlock.class,"Russy Ore",modID);
    	
        LanguageRegistry.addName(itemBlasterRifle, "Blaster Rifle");
        LanguageRegistry.addName(itemBlasterBolt, "Blaster Bolt");
        
        LanguageRegistry.addName(blockCheese, "Russoul's Peripheral");
        LanguageRegistry.addName(russy, "Russy Ore");
        
        
        GameRegistry.registerTileEntity(ChairTile.class, "Russoul's_Peripheral");
        GameRegistry.registerWorldGenerator(new MyGenerator());
        
        NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());
        
        //LoadStuff.loadAspects();
        LoadStuff.loadModules();
    }

 

    openGui

     

public class MyTickHandler implements ITickHandler{
private final EnumSet<TickType> ticksToGet;
private static EntityPlayer tickedPlayer;

public static HashMap<String,ArrayList<String>> key = new HashMap();
private static HashMap<Integer,IComputerAccess> events = new HashMap() ;
private static HashMap<Integer,ChairTile> registeredIDs = new HashMap();
public static HashMap<String,String> mouse = new HashMap();


public MyTickHandler(EnumSet<TickType> ticksToGet)
{
         this.ticksToGet = ticksToGet;
}
/*
         * I suggest putting all your tick Logic in EITHER of these, but staying in one
         */
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
         playerTick((EntityPlayer)tickData[0]);
         this.tickedPlayer = (EntityPlayer) tickData[0];
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
	key.clear();
	mouse.clear();
}
@Override
public EnumSet<TickType> ticks()
{
         return ticksToGet;
}
@Override
public String getLabel()
{
         return "TutorialPlayerTick";
}

public static void playerTick(EntityPlayer player)
{



	if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getDisplayName().equals("Power Fist")){
		ItemStack stack = player.getCurrentEquippedItem();
		for(int i = 0;i < ModuleManager.getRightClickModules().size();i++){
			if(stack.stackTagCompound.hasKey("button")){
				if(stack.stackTagCompound.getCompoundTag("button").hasKey(ModuleManager.getRightClickModules().get(i).getDataName())){
					   String key = stack.stackTagCompound.getCompoundTag("button").getString(ModuleManager.getRightClickModules().get(i).getDataName());
					   
					   if(utils.isKeyPressed(player.username) && utils.whatKeyIsPressed(player.username).equals(key)){
						   if(ModuleManager.getRightClickModules().get(i).getDataName() == "Remote"){
							   MovingObjectPosition spot = RemoteItem.getPlayerLookingSpot(player, false);
							   new RemoteModule(LoadStuff.TOOLONLY).onRightClick(player, player.worldObj, stack);
						   }else if(ModuleManager.getRightClickModules().get(i).getDataName() == "Blink Drive"){
							   new BlinkDriveModule(LoadStuff.TOOLONLY).onRightClick(player, player.worldObj, stack);
						   }
					   }
				   }
			}
	    }
	}

	if(!registeredIDs.isEmpty()){
		for(int j = 0;j<300;j++){
	    	
	    	if(registeredIDs.containsKey(j)){		
	    		//for(int i = 0;i<keys.length;i++){
	    			if(registeredIDs.get(j) != null){
	        			String Username = registeredIDs.get(j).Username;
	                	if(Username != null){
	                		if(player != null && player.username.equalsIgnoreCase(Username)){
	                			ItemStack stack = utils.getModularItemInInventory(player, "Power Fist");
	                			if(stack != null){
	                				if(ModuleManager.itemHasModule(stack, RemoteModule.NAME)){
	                					if(utils.isKeyPressed(player.username)){
	            							
	            							IComputerAccess pc = getEvent(j);
	            							
	            							try{
	            								pc.queueEvent("My_Key_Event", new Object[]{utils.whatKeyIsPressedForMyKeyEventComputerCraftStuff(player.username)});
	            								unregister(j);
	            							}catch(Exception e){
	            								e.printStackTrace();
	            							}
	            						}
	                					
	                					
	                				}
	                			}
	                		}
	                	}
	        		}
	        	//}
	    		
	    	}
		}
	}
	if(utils.getModularItemInInventory(player, "Power Fist") != null){
		ItemStack stack = utils.getModularItemInInventory(player, "Power Fist");
		if(utils.isKeyPressed(player.username) && utils.whatKeyIsPressed(player.username).contains("Z")){
			if(stack != null && stack.getItem().equals(ModularPowersuits.powerTool)){
				if(stack.stackTagCompound != null){
					if(stack.stackTagCompound.hasKey("PeripheralPassword")){
						utils.chat(player, "has not key");
						String ind = stack.stackTagCompound.getString("PeripheralPassword");
						ChairTile p = utils.getChairTileWithEniqueIndentifier(player.worldObj, player.username, ind,player);
						if(p != null){
							utils.chat(player, "p ! null");
							if(p.pc != null){
								utils.chat(player, "p.pc ! null");
								GuiHandler.ssGui.put(player, p.pc);
								//player.openGui(Main.instance, 3, player.worldObj,(int) player.posX,(int) player.posX,(int) player.posX);
								FMLCommonHandler.instance().showGuiScreen(new SensorScreenGui(p.pc));
							}
						}
					}
				}
			}


		}
	}



    


         
}

public static void openPC(TileEntityComputer Computer,String Username){
	EntityPlayer player = tickedPlayer;
	if(Computer instanceof TileEntityComputer && player.username.equalsIgnoreCase(Username)){
		Computer.getBlockType().onBlockActivated(Computer.worldObj, Computer.xCoord, Computer.yCoord, Computer.zCoord, player, 0, 0, 0, 0);
    	player.openGui(OpenPeripheral.instance, OpenPeripheral.Gui.remote.ordinal(), Computer.worldObj, Computer.xCoord, Computer.yCoord, Computer.zCoord);
    }

}



public static IComputerAccess getEvent(int id){
	return events.get(id);

}

public static void register(int id,ChairTile tile, IComputerAccess pc){
	events.put(id, pc);
	registeredIDs.put(id,tile);
}
public static void unregister(int id){
	events.remove(id);
	registeredIDs.remove(id);
}

public static HashMap<Integer,ChairTile> getRegisteredIDs(){
	return registeredIDs;
}

public static void setKeyPressed(String player,String key1){
	if(!key.containsKey(player)){
		ArrayList<String> array = new ArrayList();
		array.add(key1);
	    key.put(player, array);
	}else{
		ArrayList<String> array = key.get(player);
		array.add(key1);
		key.put(player, array);
	}
}

public static void setMousePressed(String player,String mouse1){
	mouse.put(player, mouse1);
}

  • Author

I managed this  ;D ;D ;D ;D ;D Just used FMLCommonHandler.instance().showGuiScreen(new SensorScreenGui(p.pc));

But don't actually know will it work in multiple  ::)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.